mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-04 14:58:37 +09:00
Avoid calling slice in self-hosted code. DiD
This time without unrelated/incomplete pluralforms junk.
This commit is contained in:
parent
7e93e7170f
commit
8ee79282f8
1 changed files with 21 additions and 3 deletions
|
|
@ -432,7 +432,7 @@ function CanonicalizeLanguageTag(locale) {
|
|||
subtags[i] = subtag;
|
||||
i++;
|
||||
}
|
||||
var normal = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, 0, i), "-");
|
||||
var normal = ArrayJoinRange(subtags, "-", 0, i);
|
||||
|
||||
// Extension sequences are sorted by their singleton characters.
|
||||
// "u-ca-chinese-t-zh-latn" -> "t-zh-latn-u-ca-chinese"
|
||||
|
|
@ -442,7 +442,7 @@ function CanonicalizeLanguageTag(locale) {
|
|||
i++;
|
||||
while (i < subtags.length && subtags[i].length > 1)
|
||||
i++;
|
||||
var extension = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, extensionStart, i), "-");
|
||||
var extension = ArrayJoinRange(subtags, "-", extensionStart, i);
|
||||
callFunction(std_Array_push, extensions, extension);
|
||||
}
|
||||
callFunction(std_Array_sort, extensions);
|
||||
|
|
@ -450,7 +450,7 @@ function CanonicalizeLanguageTag(locale) {
|
|||
// Private use sequences are left as is. "x-private"
|
||||
var privateUse = "";
|
||||
if (i < subtags.length)
|
||||
privateUse = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, i), "-");
|
||||
privateUse = ArrayJoinRange(subtags, "-", i);
|
||||
|
||||
// Put everything back together.
|
||||
var canonical = normal;
|
||||
|
|
@ -467,6 +467,24 @@ function CanonicalizeLanguageTag(locale) {
|
|||
return canonical;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the array elements in the given range with the supplied separator.
|
||||
*/
|
||||
function ArrayJoinRange(array, separator, from, to = array.length) {
|
||||
assert(typeof separator === "string", "|separator| is a string value");
|
||||
assert(typeof from === "number", "|from| is a number value");
|
||||
assert(typeof to === "number", "|to| is a number value");
|
||||
assert(0 <= from && from <= to && to <= array.length, "|from| and |to| form a valid range");
|
||||
|
||||
if (from === to)
|
||||
return "";
|
||||
|
||||
var result = array[from];
|
||||
for (var i = from + 1; i < to; i++) {
|
||||
result += separator + array[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function localeContainsNoUnicodeExtensions(locale) {
|
||||
// No "-u-", no possible Unicode extension.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue