Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions uint16/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ let min_value : UInt16
// Errors

// Types and methods
fn UInt16::is_leading_surrogate(UInt16) -> Bool
fn UInt16::is_surrogate(UInt16) -> Bool
fn UInt16::is_trailing_surrogate(UInt16) -> Bool
fn UInt16::to_char(UInt16) -> Char?
fn UInt16::to_uint(UInt16) -> UInt
fn UInt16::to_uint64(UInt16) -> UInt64
fn UInt16::unsafe_to_char(UInt16) -> Char
impl Add for UInt16
impl BitAnd for UInt16
impl BitOr for UInt16
Expand Down
59 changes: 59 additions & 0 deletions uint16/uint16.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,62 @@ pub fn UInt16::to_uint(self : UInt16) -> UInt {
pub fn UInt16::to_uint64(self : UInt16) -> UInt64 {
self.to_int().to_uint64()
}

///|
/// Checks if the integer value represents a UTF-16 leading surrogate.
/// Leading surrogates are in the range 0xD800 to 0xDBFF.
///
/// Example:
/// ```moonbit
/// inspect((0xD800 : UInt16).is_leading_surrogate(), content="true")
/// inspect((0xDBFF : UInt16).is_leading_surrogate(), content="true")
/// inspect((0xDC00 : UInt16).is_leading_surrogate(), content="false")
/// inspect((0x41 : UInt16).is_leading_surrogate(), content="false") // 'A'
/// ```
pub fn UInt16::is_leading_surrogate(self : Self) -> Bool {
self >= 0xD800 && self <= 0xDBFF
}

///|
/// Checks if the integer value represents a UTF-16 trailing surrogate.
/// Trailing surrogates are in the range 0xDC00 to 0xDFFF.
///
/// Example:
/// ```moonbit
/// inspect((0xDC00 : UInt16).is_trailing_surrogate(), content="true")
/// inspect((0xDFFF : UInt16).is_trailing_surrogate(), content="true")
/// inspect((0xD800 : UInt16).is_trailing_surrogate(), content="false")
/// inspect((0x41 : UInt16).is_trailing_surrogate(), content="false") // 'A'
/// ```
pub fn UInt16::is_trailing_surrogate(self : Self) -> Bool {
self >= 0xDC00 && self <= 0xDFFF
}

///|
/// Checks if the integer value represents any UTF-16 surrogate (leading or trailing).
/// Surrogates are in the range 0xD800 to 0xDFFF.
///
/// Example:
/// ```moonbit
/// inspect((0xD800 : UInt16).is_surrogate(), content="true") // leading surrogate
/// inspect((0xDC00 : UInt16).is_surrogate(), content="true") // trailing surrogate
/// inspect((0xDFFF : UInt16).is_surrogate(), content="true") // trailing surrogate
/// inspect((0x41 : UInt16).is_surrogate(), content="false") // 'A'
/// ```
pub fn UInt16::is_surrogate(self : Self) -> Bool {
self >= 0xD800 && self <= 0xDFFF
}

///|
pub fn UInt16::unsafe_to_char(self : UInt16) -> Char {
self.to_int().unsafe_to_char()
}

///|
pub fn UInt16::to_char(self : UInt16) -> Char? {
if self is (0..=0xD7FF) || self is (0xE000..<_) {
Some(self.unsafe_to_char())
} else {
None
}
}
Loading