File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments