diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/string.gleam | 15 | ||||
-rw-r--r-- | src/gleam_stdlib.mjs | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index ece64b4..5369b32 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -900,6 +900,21 @@ pub fn utf_codepoint(value: Int) -> Result(UtfCodepoint, Nil) { } } +pub fn to_ints(s: String) -> List(Int) { + to_utf_codepoints(s) + |> list.map(utf_codepoint_to_int) +} + +if erlang { + external fn utf_codepoint_to_int(cp: UtfCodepoint) -> Int = + "gleam_stdlib" "identity" +} + +if javascript { + external fn utf_codepoint_to_int(cp: UtfCodepoint) -> Int = + "../gleam_stdlib.mjs" "utf_codepoint_to_int" +} + /// Converts a `String` into `Option(String)` where an empty `String` becomes /// `None`. /// diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index 9d37ec3..69644dc 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -363,6 +363,10 @@ export function utf_codepoint_list_to_string(utf_codepoint_integer_list) { .join(""); } +export function utf_codepoint_to_int(utf_codepoint) { + return utf_codepoint.value; +} + export function regex_check(regex, string) { return regex.test(string); } |