aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Whatmore <tom@whatmore.me>2020-06-25 16:48:12 +0100
committerLouis Pilfold <louis@lpil.uk>2020-06-30 12:15:19 +0100
commit725e96b338621b8e1161679d9dc4215212df1e81 (patch)
tree3dca7ba0d81a7078ec69fdc668becd8988cc0fd1 /src
parentc3c2284841b8dda0236d3366932a3d555e1ead55 (diff)
downloadgleam_stdlib-725e96b338621b8e1161679d9dc4215212df1e81.tar.gz
gleam_stdlib-725e96b338621b8e1161679d9dc4215212df1e81.zip
Move UtfCodepoint functionality into string module
Diffstat (limited to 'src')
-rw-r--r--src/gleam/string.gleam21
-rw-r--r--src/gleam/utf_codepoint.gleam22
2 files changed, 21 insertions, 22 deletions
diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam
index 1714dad..2ae654e 100644
--- a/src/gleam/string.gleam
+++ b/src/gleam/string.gleam
@@ -10,6 +10,10 @@ import gleam/result
pub type String =
String
+/// A UtfCodepoint is the integer representation of a valid UTF codepoint
+pub type UtfCodepoint =
+ UtfCodepoint
+
/// Determine if a string is empty.
///
/// ## Examples
@@ -451,3 +455,20 @@ pub fn to_graphemes(string: String) -> List(String) {
_ -> []
}
}
+
+external fn int_to_utf_codepoint(Int) -> UtfCodepoint =
+ "gleam_stdlib" "identity"
+
+/// Convert an integer to a UtfCodepoint
+///
+/// Returns an error if the integer does not represent a valid UTF codepoint.
+///
+pub fn utf_codepoint(value: Int) -> Result(UtfCodepoint, Nil) {
+ case value {
+ 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_utf_codepoint(i))
+ }
+}
diff --git a/src/gleam/utf_codepoint.gleam b/src/gleam/utf_codepoint.gleam
deleted file mode 100644
index f1d0fbb..0000000
--- a/src/gleam/utf_codepoint.gleam
+++ /dev/null
@@ -1,22 +0,0 @@
-import gleam/result
-
-/// A UtfCodepoint is the integer representation of a valid UTF codepoint
-pub type UtfCodepoint =
- UtfCodepoint
-
-external fn int_to_utf8_codepoint(Int) -> UtfCodepoint =
- "gleam_stdlib" "identity"
-
-/// 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(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))
- }
-}