From 068a2168d19a57c462e67f0070aa9f42691ffe1b Mon Sep 17 00:00:00 2001 From: Tom Whatmore Date: Fri, 19 Jun 2020 12:04:51 +0100 Subject: Add documentation comments to utf_codepoint --- src/gleam/utf_codepoint.gleam | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') 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)) } } -- cgit v1.2.3