Skip to content

Commit 13078f0

Browse files
committed
feat(string): add string:codepoints
1 parent 952bc42 commit 13078f0

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎String.ark‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,22 @@
6969
(let removeAt (fun (_str _index) (builtin__string:removeAt _str _index)))
7070

7171
# @brief Compute the length of an UTF8 string by counting the number of codepoints
72-
# @param char a String
72+
# @param _str a String
7373
# =begin
7474
# (string:utf8len "h") # 1
7575
# (string:utf8len "🏳️‍⚧️") # 5
7676
# =end
7777
# @author https://github.com/SuperFola
7878
(let utf8len (fun (_str) (builtin__string:utf8len _str)))
7979

80+
# @brief Compute the UTF8 codepoints that makes a string, and return them as a List
81+
# @param _str String
82+
# =begin
83+
# (print (string:codepoints "abc")) # ["a" "b" "c"]
84+
# =end
85+
# @author https://github.com/SuperFola
86+
(let codepoints (fun (_str) (builtin__string:codepoints _str)))
87+
8088
# @brief Get the ordinal of a given character
8189
# @param char a String with a single UTF8 character
8290
# =begin

‎tests/string-tests.ark‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
(test:eq (string:utf8len "hello\t") 6)
5353
(test:eq (string:utf8len "🏳️‍⚧️") 5) })
5454

55+
(test:case "codepoints" {
56+
(test:eq (builtin__string:codepoints "hello") (string:codepoints "hello"))
57+
(test:eq (string:codepoints "") [])
58+
(test:eq (string:codepoints "hello") ["h" "e" "l" "l" "o"])
59+
(test:eq (list:map (string:codepoints "🏳️‍⚧️") string:ord) [127987 65039 8205 9895 65039]) })
60+
5561
(test:case "ord, chr" {
5662
(test:eq (builtin__string:ord "a") (string:ord "a"))
5763
(test:eq (string:ord "ø") 248)

0 commit comments

Comments
 (0)