mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 13:51:50 +03:00
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:
commit
381494bb4a
@ -76,11 +76,14 @@
|
|||||||
|
|
||||||
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
|
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
|
||||||
(defn starts-with? [s 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`.")
|
(doc ends-with? "Check if the string `s` ends with the string `sub`.")
|
||||||
(defn ends-with? [s 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.")
|
(doc zero "The empty string.")
|
||||||
(defn zero [] @"")
|
(defn zero [] @"")
|
||||||
|
Loading…
Reference in New Issue
Block a user