Merge pull request #676 from hellerve/veit/starts-with-check

core: add check in starts-with?/ends-with? for string length
This commit is contained in:
Erik Svedäng 2020-02-14 10:31:50 +01:00 committed by GitHub
commit 381494bb4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,11 +76,14 @@
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
(defn starts-with? [s sub]
(= sub &(prefix s (length sub))))
(let [ls (length sub)]
(and (>= (length s) ls) (= sub &(prefix s ls)))))
(doc ends-with? "Check if the string `s` ends with the string `sub`.")
(defn ends-with? [s sub]
(= sub &(suffix s (- (length s) (length sub)))))
(let [ls (length s)
lsub (length sub)]
(and (>= ls lsub) (= sub &(suffix s (- ls lsub))))))
(doc zero "The empty string.")
(defn zero [] @"")