diff options
author | inoas <mail@inoas.com> | 2022-12-04 19:39:37 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-12-22 20:44:33 +0000 |
commit | 663729b8a619d1076fda8953abdb06070a786269 (patch) | |
tree | 6bbfd6a6d7bae928acf89821a19757b7fbbc5360 /src | |
parent | 86532391dac84e5136031940db962d45a7814a02 (diff) | |
download | gleam_stdlib-663729b8a619d1076fda8953abdb06070a786269.tar.gz gleam_stdlib-663729b8a619d1076fda8953abdb06070a786269.zip |
add string.to_ints
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); } |