File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
import gleam/result
2
2
3
+ /// A UtfCodepoint is the integer representation of a valid UTF codepoint
3
4
pub type UtfCodepoint = UtfCodepoint
4
5
5
- pub type Error {
6
- Invalid
7
- }
8
-
9
6
external fn int_to_utf8_codepoint ( Int ) -> UtfCodepoint =
10
7
"gleam_stdlib" "identity"
11
8
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 ) {
13
14
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 )
18
19
i -> Ok ( int_to_utf8_codepoint ( i ) )
19
20
}
20
21
}
You can’t perform that action at this time.
0 commit comments