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
6 changes: 4 additions & 2 deletions common.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion decode.mbt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
7 changes: 4 additions & 3 deletions encode.mbt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +19,7 @@ pub fn encode(raw : String) -> String? {
// 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()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peter-jerry-ye Hi, I haven't been following moonbit's evolution closely, but I've been paying attention to the release notes from time to time. The last time I received a similar change, to_uint was a method that was replaced by reinterpret_as_uint and marked as obsolete1. However, the change you proposed is the complete opposite, which I don't understand. Could please you elaborate on this?

Footnotes

  1. https://github.com/chawyehsu/punycode.mbt/pull/1

if code >= n && code < m {
m = code
}
Expand All @@ -29,7 +30,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 {
Expand Down
16 changes: 16 additions & 0 deletions pkg.generated.mbti
Original file line number Diff line number Diff line change
@@ -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