File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6868# @author https://github.com/SuperFola
6969(let removeAt (fun (_str _index) (builtin__string:removeAt _str _index)))
7070
71+ # @brief Compute the length of an UTF8 string by counting the number of codepoints
72+ # @param char a String
73+ # =begin
74+ # (string:utf8len "h") # 1
75+ # (string:utf8len "🏳️⚧️") # 5
76+ # =end
77+ # @author https://github.com/SuperFola
78+ (let utf8len (fun (_str) (builtin__string:utf8len _str)))
79+
7180# @brief Get the ordinal of a given character
7281# @param char a String with a single UTF8 character
7382# =begin
Original file line number Diff line number Diff line change 3838 (test:eq (string:emptyOrWhitespace? "a ") false)
3939 (test:eq (string:emptyOrWhitespace? " a ") false) })
4040
41+ (test:case "utf8len" {
42+ (test:eq (builtin__string:utf8len "hello") (string:utf8len "hello"))
43+ (test:eq (string:utf8len "h") 1)
44+ (test:eq (string:utf8len "hello") 5)
45+ (test:eq (string:utf8len "hello\t") 6)
46+ (test:eq (string:utf8len "🏳️⚧️") 5) })
47+
4148 (test:case "ord, chr" {
4249 (test:eq (builtin__string:ord "a") (string:ord "a"))
50+ (test:eq (string:ord "ø") 248)
4351 (test:eq (builtin__string:chr 65) (string:chr 65)) })
4452
4553 (test:case "count" {
You can’t perform that action at this time.
0 commit comments