diff options
-rw-r--r-- | src/gleam/utf_codepoint.gleam | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/gleam/utf_codepoint.gleam b/src/gleam/utf_codepoint.gleam index 2c3cb04..f894ad3 100644 --- a/src/gleam/utf_codepoint.gleam +++ b/src/gleam/utf_codepoint.gleam @@ -1,20 +1,21 @@ import gleam/result +/// A UtfCodepoint is the integer representation of a valid UTF codepoint pub type UtfCodepoint = UtfCodepoint -pub type Error { - Invalid -} - external fn int_to_utf8_codepoint(Int) -> UtfCodepoint = "gleam_stdlib" "identity" -pub fn from_int(value: Int) -> Result(UtfCodepoint, Error) { +/// Convert an integer to a UtfCodepoint +/// +/// Returns an error if the integer does not represent a valid UTF codepoint. +/// +pub fn from_int(value: Int) -> Result(UtfCodepoint, Nil) { case value { - i if i > 1114111 -> Error(Invalid) - i if i == 65534 -> Error(Invalid) - i if i == 65535 -> Error(Invalid) - i if i >= 55296 && i <= 57343 -> Error(Invalid) + i if i > 1114111 -> Error(Nil) + i if i == 65534 -> Error(Nil) + i if i == 65535 -> Error(Nil) + i if i >= 55296 && i <= 57343 -> Error(Nil) i -> Ok(int_to_utf8_codepoint(i)) } } |