1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

LibJS: Implement RegExp.prototype [ @@replace ] with UTF-16 code units

This also converts the GetSubstitution abstract operation take its input
strings as UTF-16 now that all callers are UTF-16 capable. This means
String.prototype.replace (and replaceAll) no longer needs UTF-8 and
UTF-16 copies of these strings.
This commit is contained in:
Timothy Flynn 2021-07-22 10:38:10 -04:00 committed by Linus Groh
parent ee7b04f7bb
commit 5a8f870594
6 changed files with 67 additions and 71 deletions

View file

@ -238,7 +238,11 @@ test("UTF-16", () => {
expect("😀".replace("\ud83d", "")).toBe("\ude00");
expect("😀".replace("\ude00", "")).toBe("\ud83d");
// FIXME: RegExp.prototype [ @@replace ] also needs to support UTF-16.
// expect("😀".replace(/\ud83d/, "")).toBe("\ude00");
// expect("😀".replace(/\ude00/, "")).toBe("\ud83d");
expect("😀".replace(/\ud83d/, "")).toBe("\ude00");
expect("😀".replace(/\ude00/, "")).toBe("\ud83d");
expect("😀".replace(/\ud83d\ude00/, "")).toBe("");
expect("😀".replace(/\ud83d/u, "")).toBe("😀");
expect("😀".replace(/\ude00/u, "")).toBe("😀");
expect("😀".replace(/\ud83d\ude00/u, "")).toBe("");
});

View file

@ -151,7 +151,18 @@ test("UTF-16", () => {
expect("😀😀😀".replaceAll("\ud83d", "")).toBe("\ude00\ude00\ude00");
expect("😀😀😀".replaceAll("\ude00", "")).toBe("\ud83d\ud83d\ud83d");
// FIXME: RegExp.prototype [ @@replace ] also needs to support UTF-16.
// expect("😀".replaceAll(/\ud83d/g, "")).toBe("\ude00");
// expect("😀".replaceAll(/\ude00/g, "")).toBe("\ud83d");
expect("😀".replaceAll(/\ud83d/g, "")).toBe("\ude00");
expect("😀".replaceAll(/\ude00/g, "")).toBe("\ud83d");
expect("😀".replaceAll(/\ud83d\ude00/g, "")).toBe("");
expect("😀😀😀".replaceAll(/\ud83d/g, "")).toBe("\ude00\ude00\ude00");
expect("😀😀😀".replaceAll(/\ude00/g, "")).toBe("\ud83d\ud83d\ud83d");
expect("😀😀😀".replaceAll(/\ud83d\ude00/g, "")).toBe("");
expect("😀".replaceAll(/\ud83d/gu, "")).toBe("😀");
expect("😀".replaceAll(/\ude00/gu, "")).toBe("😀");
expect("😀".replaceAll(/\ud83d\ude00/gu, "")).toBe("");
expect("😀😀😀".replaceAll(/\ud83d/gu, "")).toBe("😀😀😀");
expect("😀😀😀".replaceAll(/\ude00/gu, "")).toBe("😀😀😀");
expect("😀😀😀".replaceAll(/\ude00/gu, "")).toBe("😀😀😀");
expect("😀😀😀".replaceAll(/\ud83d\ude00/gu, "")).toBe("");
});