From 4a9de3e18540889a742674439af5569388f23b86 Mon Sep 17 00:00:00 2001 From: zihang Date: Fri, 19 Dec 2025 15:12:38 +0800 Subject: [PATCH 1/2] fix: avoid breaking change --- encode.mbt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/encode.mbt b/encode.mbt index 689305f..b5d9fdf 100644 --- a/encode.mbt +++ b/encode.mbt @@ -12,13 +12,13 @@ pub fn encode(raw : String) -> String? { if h > 0 { encoded.push(delimiter) } - let input_lenght = raw.length().reinterpret_as_uint() + let input_lenght = raw.length().to_uint() // Main encoding loop while h < input_lenght { // let m = the minimum {non-basic} code point >= n in the input let mut m = @uint.max_value for j = 0U; j < input_lenght; j = j + 1U { - let code = raw[j.reinterpret_as_int()].reinterpret_as_uint() + let code = raw[j.reinterpret_as_int()].to_uint() if code >= n && code < m { m = code } @@ -29,7 +29,7 @@ pub fn encode(raw : String) -> String? { delta += (m - n) * (h + 1) n = m for j = 0U; j < input_lenght; j = j + 1U { - let code = raw[j.reinterpret_as_int()].reinterpret_as_uint() + let code = raw[j.reinterpret_as_int()].to_uint() if code < n { delta += 1 if delta == 0 { From 3cef447d57a71c5ab7bbb1de6ecc92c031b6ae90 Mon Sep 17 00:00:00 2001 From: zihang Date: Fri, 19 Dec 2025 15:12:59 +0800 Subject: [PATCH 2/2] chore: moon fmt & moon info --- common.mbt | 6 ++++-- decode.mbt | 3 ++- encode.mbt | 5 +++-- pkg.generated.mbti | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 pkg.generated.mbti diff --git a/common.mbt b/common.mbt index 45b8e84..ef475a1 100644 --- a/common.mbt +++ b/common.mbt @@ -21,10 +21,12 @@ let initial_bias : UInt = 72U ///| let initial_n : UInt = 0x80U // 128 -///| Delimiter between literal portion and encoded portion +///| +/// Delimiter between literal portion and encoded portion let delimiter : Char = '-' -///| Bias adaptation function +///| +/// Bias adaptation function fn adapt(delta : UInt, num_points : UInt, first_time : Bool) -> UInt { let mut delta = delta delta /= if first_time { damp } else { 2U } diff --git a/decode.mbt b/decode.mbt index 51ec2bb..747ef19 100644 --- a/decode.mbt +++ b/decode.mbt @@ -1,4 +1,5 @@ -///| Converts a Punycode string of ASCII-only symbols to a string of Unicode symbols. +///| +/// Converts a Punycode string of ASCII-only symbols to a string of Unicode symbols. pub fn decode(encoded : String) -> String? { let decoded = [] let encoded_length = encoded.length().reinterpret_as_uint() diff --git a/encode.mbt b/encode.mbt index b5d9fdf..1eef63f 100644 --- a/encode.mbt +++ b/encode.mbt @@ -1,4 +1,5 @@ -///| Convert a string of Unicode symbols to a Punycode string of ASCII-only symbols. +///| +/// Convert a string of Unicode symbols to a Punycode string of ASCII-only symbols. pub fn encode(raw : String) -> String? { // Basic code point segregation, extract ASCII characters that are // encoded as-is @@ -12,7 +13,7 @@ pub fn encode(raw : String) -> String? { if h > 0 { encoded.push(delimiter) } - let input_lenght = raw.length().to_uint() + let input_lenght = raw.length().reinterpret_as_uint() // Main encoding loop while h < input_lenght { // let m = the minimum {non-basic} code point >= n in the input diff --git a/pkg.generated.mbti b/pkg.generated.mbti new file mode 100644 index 0000000..df6758f --- /dev/null +++ b/pkg.generated.mbti @@ -0,0 +1,16 @@ +// Generated using `moon info`, DON'T EDIT IT +package "chawyehsu/punycode" + +// Values +pub fn decode(String) -> String? + +pub fn encode(String) -> String? + +// Errors + +// Types and methods + +// Type aliases + +// Traits +