From 9dc8bc4b3e9b58396ceae3e2bb466c1eb4679f86 Mon Sep 17 00:00:00 2001 From: inoas Date: Fri, 9 Dec 2022 09:10:36 +0100 Subject: replace string.to_ints with string.utf_codepoint_to_int --- src/gleam/string.gleam | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index e2377e2..04d58a8 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -900,39 +900,26 @@ pub fn utf_codepoint(value: Int) -> Result(UtfCodepoint, Nil) { } } -/// Converts a string to a list of UtfCodepoint integers. +/// Converts an UtfCodepoint to its ordinal code point value. /// /// ## Examples /// /// ```gleam -/// > "abc" -/// > |> string.to_ints -/// [97, 98, 99] +/// > utf_codepoint_to_int(128013) |> to_utf_codepoint_int +/// 128013 /// ``` /// -/// ```gleam -/// > "🐍" -/// > |> string.to_ints -/// [128013] -/// ``` -/// -/// ```gleam -/// > [utf_codepoint(128013)] |> from_utf_codepoints |> to_ints -/// "🐍" -/// ``` -/// -pub fn to_ints(s: String) -> List(Int) { - to_utf_codepoints(s) - |> list.map(utf_codepoint_to_int) +pub fn utf_codepoint_to_int(cp: UtfCodepoint) -> Int { + do_utf_codepoint_to_int(cp) } if erlang { - external fn utf_codepoint_to_int(cp: UtfCodepoint) -> Int = + external fn do_utf_codepoint_to_int(cp: UtfCodepoint) -> Int = "gleam_stdlib" "identity" } if javascript { - external fn utf_codepoint_to_int(cp: UtfCodepoint) -> Int = + external fn do_utf_codepoint_to_int(cp: UtfCodepoint) -> Int = "../gleam_stdlib.mjs" "utf_codepoint_to_int" } -- cgit v1.2.3