-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
Add UTF-8 encoding/decoding support as part of the std::encoding module.
Parent issue: #48
Functions
| Function | Signature | Description |
|---|---|---|
encode |
(s: string) -> bytes |
Convert string to UTF-8 bytes |
decode |
(data: bytes) -> string throws DecodeError |
Convert UTF-8 bytes to string |
Usage
use std::encoding::utf8::*;
var raw: bytes = encode("Hello 世界");
var text: string = decode(raw);
// With error handling
var text: string = decode(invalid_bytes) catch e {
println(e.message);
return;
} ?? "";
Implementation Notes
- naml strings are already UTF-8 internally, so encode is essentially a view/copy
- decode validates UTF-8 sequences and throws on invalid bytes
- Use Rust's
std::str::from_utf8for validation
Exception
exception DecodeError {
position: int,
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels