mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibJS: Use Unicode normalization within String.prototype.normalize
This commit is contained in:
parent
19b758ce8b
commit
7fc03e8967
2 changed files with 6 additions and 5 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibLocale/Locale.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
#include <LibUnicode/Normalize.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace JS {
|
||||
|
@ -850,8 +851,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::normalize)
|
|||
if (!form.is_one_of("NFC"sv, "NFD"sv, "NFKC"sv, "NFKD"sv))
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidNormalizationForm, form);
|
||||
|
||||
// FIXME: 6. Let ns be the String value that is the result of normalizing S into the normalization form named by f as specified in https://unicode.org/reports/tr15/.
|
||||
auto ns = string;
|
||||
// 6. Let ns be the String value that is the result of normalizing S into the normalization form named by f as specified in https://unicode.org/reports/tr15/.
|
||||
auto unicode_form = Unicode::normalization_form_from_string(form);
|
||||
auto ns = Unicode::normalize(string, unicode_form);
|
||||
|
||||
// 7. return ns.
|
||||
return js_string(vm, move(ns));
|
||||
|
|
|
@ -36,8 +36,7 @@ test("Invalid object throws", () => {
|
|||
);
|
||||
});
|
||||
|
||||
// Tests below here are skipped due to the function being a stub at the moment
|
||||
test.skip("Normalization works", () => {
|
||||
test("Normalization works", () => {
|
||||
var s = "\u1E9B\u0323";
|
||||
|
||||
expect(s.normalize("NFC")).toBe("\u1E9B\u0323");
|
||||
|
@ -46,7 +45,7 @@ test.skip("Normalization works", () => {
|
|||
expect(s.normalize("NFKD")).toBe("\u0073\u0323\u0307");
|
||||
});
|
||||
|
||||
test.skip("Default parameter is NFC", () => {
|
||||
test("Default parameter is NFC", () => {
|
||||
var s = "\u1E9B\u0323";
|
||||
|
||||
expect(s.normalize("NFC")).toBe(s.normalize());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue