Skip to content

Commit 14cede5

Browse files
ssrliveCopilot
andcommitted
Implement String.prototype.normalize
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ba88121 commit 14cede5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/core/vm.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::fs::File;
2929
use std::io::{Read, Seek, SeekFrom, Write};
3030
use std::path::{Path, PathBuf};
3131
use std::sync::{LazyLock, Mutex};
32+
use unicode_normalization::UnicodeNormalization;
3233

3334
type VmStrong<'gc, T> = Gc<'gc, GcCell<T>>;
3435
type VmWeak<'gc, T> = GcWeak<'gc, GcCell<T>>;
@@ -30179,8 +30180,15 @@ impl<'gc> VM<'gc> {
3017930180
};
3018030181
match form.as_str() {
3018130182
"NFC" | "NFD" | "NFKC" | "NFKD" => {
30182-
// Return the string as-is (basic implementation without ICU)
30183-
return Value::String(s.to_vec());
30183+
let source = crate::unicode::utf16_to_utf8(s);
30184+
let normalized = match form.as_str() {
30185+
"NFC" => source.nfc().collect::<String>(),
30186+
"NFD" => source.nfd().collect::<String>(),
30187+
"NFKC" => source.nfkc().collect::<String>(),
30188+
"NFKD" => source.nfkd().collect::<String>(),
30189+
_ => unreachable!(),
30190+
};
30191+
return Value::String(crate::unicode::utf8_to_utf16(&normalized));
3018430192
}
3018530193
_ => {
3018630194
let err = self.make_range_error_object(

0 commit comments

Comments
 (0)