Skip to content

Commit 2fd6675

Browse files
refactor: move from utf16le to utf16
1 parent 68ad6fa commit 2fd6675

File tree

9 files changed

+19
-16
lines changed

9 files changed

+19
-16
lines changed
File renamed without changes.

encoding/utf16le/decode_test.mbt renamed to encoding/utf16/decode_test.mbt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
///|
1616
test "decoding UTF16 encoded data to String" {
17-
let chars = @utf16le.decode(
17+
let chars = @utf16.decode(
1818
b"\x61\x00\x62\x00\x63\x00\x60\x4f\x7d\x59\x3d\xd8\x40\xdc",
1919
)
2020
inspect(chars, content="abc你好👀")
@@ -23,25 +23,25 @@ test "decoding UTF16 encoded data to String" {
2323
///|
2424
test "decoding UTF16 with bom" {
2525
let text = b"\xff\xfe\x61\x00\x62\x00\x63\x00\x60\x4f\x7d\x59\x3d\xd8\x40\xdc"
26-
inspect(try! @utf16le.decode(text), content="abc你好👀")
27-
inspect(try! @utf16le.decode(text, ignore_bom=true), content="abc你好👀")
26+
inspect(try! @utf16.decode(text), content="abc你好👀")
27+
inspect(try! @utf16.decode(text, ignore_bom=true), content="abc你好👀")
2828
}
2929

3030
///|
3131
test "decoding UTF16 invalid data with replacement" {
3232
let unpaired = b"\x61\x00\x00"
33-
inspect(@utf16le.decode_lossy(unpaired), content="a�")
33+
inspect(@utf16.decode_lossy(unpaired), content="a�")
3434
let high_surrogate = b"\x00\xd8"
35-
inspect(@utf16le.decode_lossy(high_surrogate), content="�")
35+
inspect(@utf16.decode_lossy(high_surrogate), content="�")
3636
let low_surrogate = b"\x00\xdc"
37-
inspect(@utf16le.decode_lossy(low_surrogate), content="�")
37+
inspect(@utf16.decode_lossy(low_surrogate), content="�")
3838
}
3939

4040
///|
4141
test "decoding UTF16 invalid data to String" {
4242
let unpaired = b"\x61\x00\x00"
4343
try {
44-
let _ = @utf16le.decode(unpaired)
44+
let _ = @utf16.decode(unpaired)
4545
panic()
4646
} catch {
4747
Malformed(e) =>
@@ -54,7 +54,7 @@ test "decoding UTF16 invalid data to String" {
5454
}
5555
let high_surrogate = b"\x00\xd8"
5656
try {
57-
let _ = @utf16le.decode(high_surrogate)
57+
let _ = @utf16.decode(high_surrogate)
5858
panic()
5959
} catch {
6060
Malformed(e) =>
@@ -67,7 +67,7 @@ test "decoding UTF16 invalid data to String" {
6767
}
6868
let low_surrogate = b"\x00\xdc"
6969
try {
70-
let _ = @utf16le.decode(low_surrogate)
70+
let _ = @utf16.decode(low_surrogate)
7171
panic()
7272
} catch {
7373
Malformed(e) =>
File renamed without changes.

encoding/utf16le/encode_test.mbt renamed to encoding/utf16/encode_test.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
///|
1616
test "encode" {
1717
let s = "abc你好👀"
18-
let encoded = @utf16le.encode(s)
18+
let encoded = @utf16.encode(s)
1919
inspect(
2020
encoded,
2121
content=(
2222
#|b"a\x00b\x00c\x00`O}Y=\xd8@\xdc"
2323
),
2424
)
25-
let encoded_with_bom = @utf16le.encode(s, bom=true)
25+
let encoded_with_bom = @utf16.encode(s, bom=true)
2626
inspect(
2727
encoded_with_bom,
2828
content=(
File renamed without changes.
File renamed without changes.

encoding/utf16/types.mbt

Whitespace-only changes.

string/README.mbt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ test "string conversion" {
7272
inspect(chars, content="['H', 'e', 'l', 'l', 'o', ' ', '你', '好']")
7373
7474
// Convert to bytes (UTF-8 encoding)
75-
let bytes = @utf8.encode(text) // Use UTF-8 encoding
75+
let bytes = @encoding/utf8.encode(text) // Use UTF-8 encoding
7676
inspect(bytes.length(), content="12")
7777
inspect(chars, content="['H', 'e', 'l', 'l', 'o', ' ', '你', '好']")
7878
7979
// Convert to bytes (UTF-16 LE encoding)
80-
let bytes = @encoding/utf16le.encode(text)
80+
let bytes = @encoding/utf16.encode(text)
8181
inspect(bytes.length(), content="16") // 5 chars * 2 bytes each
8282
}
8383
```

string/moon.pkg.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"moonbitlang/core/list",
55
"moonbitlang/core/json",
66
"moonbitlang/core/quickcheck",
7-
"moonbitlang/core/encoding/utf8",
87
{
9-
"path": "moonbitlang/core/encoding/utf16le",
10-
"alias": "encoding/utf16le"
8+
"path": "moonbitlang/core/encoding/utf8",
9+
"alias": "encoding/utf8"
10+
},
11+
{
12+
"path": "moonbitlang/core/encoding/utf16",
13+
"alias": "encoding/utf16"
1114
}
1215
],
1316
"targets": {

0 commit comments

Comments
 (0)