aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Whatmore <tom@whatmore.me>2020-06-19 12:04:51 +0100
committerLouis Pilfold <louis@lpil.uk>2020-06-30 12:15:19 +0100
commit068a2168d19a57c462e67f0070aa9f42691ffe1b (patch)
treeb135215884801c1570497ff4e29415e7c87f4963
parent341eb947b4f3f33ea2bf700f629d328444b1df3f (diff)
downloadgleam_stdlib-068a2168d19a57c462e67f0070aa9f42691ffe1b.tar.gz
gleam_stdlib-068a2168d19a57c462e67f0070aa9f42691ffe1b.zip
Add documentation comments to utf_codepoint
-rw-r--r--src/gleam/utf_codepoint.gleam19
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))
}
}