Skip to content

Commit

Permalink
Remove all negative slice indexing.
Browse files Browse the repository at this point in the history
In the event that this changes and breaks code, well, it wont here.
  • Loading branch information
bakpakin committed Jul 14, 2023
1 parent 213842c commit 6b38c2c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions spork/base64.janet
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
```
[s]
(if-not (empty? s)
(let [without-padding (peg/replace-all "=" "" s)
(let [without-padding (string/replace-all "=" "" s)
padded? (not (zero? (% (length without-padding) 4)))
quadruples (partition 4 without-padding)
bytes (map quadruples->bytes quadruples)
base64 (apply string bytes)]
(if padded? (slice base64 0 -2) base64))
(if padded? (slice base64 0 (dec (length base64))) base64))
""))
2 changes: 1 addition & 1 deletion spork/cjanet.janet
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
(defn emit-declare
"Emit a declaration of a variable or constant."
[binding & form]
(def storage-classes (slice form 0 -2))
(def storage-classes (slice form 0 (dec (length form))))
(def v (last form))
(when (next storage-classes)
(emit-storage-classes storage-classes))
Expand Down
2 changes: 1 addition & 1 deletion spork/httpf.janet
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
(put mime-read-default path read-mime)
(put mime-render-default path render-mime)
(if (string/has-suffix? "/" path)
(add-route server (string/slice path 0 -2) docstring schema handler read-mime render-mime)
(add-route server (string/slice path 0 (dec (length path))) docstring schema handler read-mime render-mime)
server))

(defn add-bindings-as-routes
Expand Down
8 changes: 4 additions & 4 deletions spork/misc.janet
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"\n" (string/replace indent "" x))]
# Remove trailing newline to mimic long string newline omission.
(if (= (chr "\n") (last y))
(slice y 0 -2)
(slice y 0 (dec (length y)))
y))
x))

Expand Down Expand Up @@ -200,14 +200,14 @@
"Trim the specified prefix of a string if it has one"
[prefix str]
(if (string/has-prefix? prefix str)
(slice str (length prefix) -1)
(slice str (length prefix))
str))

(defn trim-suffix
"Trim the specified suffix of a string if it has one"
[suffix str]
(if (string/has-suffix? suffix str)
(slice str 0 (* -1 (+ 1 (length suffix))))
(slice str 0 (- (length str) (length suffix)))
str))

(defmacro log
Expand Down Expand Up @@ -278,7 +278,7 @@
'if cnd
(tuple 'set res
(tuple (first ope) res
;(tuple/slice ope 1 -1)))))
;(tuple/slice ope 1)))))
(partition 2 clauses))
,res)))

Expand Down
6 changes: 3 additions & 3 deletions spork/path.janet
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(if-let [m (peg/match ext-peg path (length path))]
(let [i (m 0)]
(if (= (path i) 46)
(string/slice path (m 0) -1)))))
(string/slice path (m 0))))))

(defn- redef
"Redef a value, keeping all metadata."
Expand Down Expand Up @@ -63,7 +63,7 @@
path
(length path))]
(let [[p] m]
(string/slice path p -1))
(string/slice path p))
path)))

(defmacro- decl-parts
Expand Down Expand Up @@ -130,7 +130,7 @@
(def target-parts (,(symbol pre "/parts") (,(symbol pre "/abspath") target)))
(def same-parts (length (take-until identity (map not= source-parts target-parts))))
(def up-walk (array/new-filled (- (length source-parts) same-parts) ".."))
(def down-walk (tuple/slice target-parts same-parts -1))
(def down-walk (tuple/slice target-parts same-parts))
(,(symbol pre "/join") ;up-walk ;down-walk)))

#
Expand Down

0 comments on commit 6b38c2c

Please sign in to comment.