Skip to content

Commit 952bc42

Browse files
committed
feat(string): add string:ascii?
1 parent 54e92ed commit 952bc42

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎String.ark‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
# @author https://github.com/SuperFola
107107
(let setAt (fun (_str _index _x) (builtin__string:setAt _str _index _x)))
108108

109+
# @brief Check if a string is only ASCII
110+
# @param _str String where the lookup occurs
111+
# @author https://github.com/SuperFola
112+
(let ascii? (fun (_str) (= (len _str) (builtin__string:utf8len _str))))
113+
109114
# @brief Check if a string contains a word
110115
# @param _str String where the lookup occurs
111116
# @param _word Word to look up for

‎tests/string-tests.ark‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
(test:eq (builtin__string:removeAt "abcd" -1) "abc")
1313
(test:eq (builtin__string:setAt "abcd" 1 "z") (string:setAt "abcd" 1 "z")) })
1414

15+
(test:case "ascii?" {
16+
(test:expect (string:ascii? ""))
17+
(test:expect (string:ascii? string:asciiLetters))
18+
(test:expect (string:ascii? string:whitespace))
19+
(test:expect (not (string:ascii? "abcdé")))
20+
(test:expect (not (string:ascii? "🏳️‍⚧️"))) })
21+
1522
(test:case "contains?" {
1623
(test:expect (string:contains? "hello, world" "h"))
1724
(test:expect (string:contains? "hello, world" "hello"))

0 commit comments

Comments
 (0)