Skip to content

Commit 068a216

Browse files
tomwhatmorelpil
authored andcommitted
Add documentation comments to utf_codepoint
1 parent 341eb94 commit 068a216

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/gleam/utf_codepoint.gleam

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import gleam/result
22

3+
/// A UtfCodepoint is the integer representation of a valid UTF codepoint
34
pub type UtfCodepoint = UtfCodepoint
45

5-
pub type Error {
6-
Invalid
7-
}
8-
96
external fn int_to_utf8_codepoint(Int) -> UtfCodepoint =
107
"gleam_stdlib" "identity"
118

12-
pub fn from_int(value: Int) -> Result(UtfCodepoint, Error) {
9+
/// Convert an integer to a UtfCodepoint
10+
///
11+
/// Returns an error if the integer does not represent a valid UTF codepoint.
12+
///
13+
pub fn from_int(value: Int) -> Result(UtfCodepoint, Nil) {
1314
case value {
14-
i if i > 1114111 -> Error(Invalid)
15-
i if i == 65534 -> Error(Invalid)
16-
i if i == 65535 -> Error(Invalid)
17-
i if i >= 55296 && i <= 57343 -> Error(Invalid)
15+
i if i > 1114111 -> Error(Nil)
16+
i if i == 65534 -> Error(Nil)
17+
i if i == 65535 -> Error(Nil)
18+
i if i >= 55296 && i <= 57343 -> Error(Nil)
1819
i -> Ok(int_to_utf8_codepoint(i))
1920
}
2021
}

0 commit comments

Comments
 (0)