Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public static IEnumerable<object[]> ToUpper_TestData()
// we also don't preform.
// es-zed does not case to SS when uppercased.
yield return new object[] { cultureName, "\u00DF", "\u00DF" };
yield return new object[] { cultureName, "stra\u00DFe", "STRA\u00DFE" };

// Ligatures do not expand when cased.
yield return new object[] { cultureName, "\uFB00", "\uFB00" };
Expand Down
66 changes: 55 additions & 11 deletions src/mono/wasm/runtime/hybrid-globalization/change-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,37 @@ export function mono_wasm_change_case_invariant(src: number, srcLength: number,
const exceptionRoot = mono_wasm_new_external_root<MonoObject>(ex_address);
try{
const input = get_utf16_string(src, srcLength);
let result = toUpper ? input.toUpperCase() : input.toLowerCase();
const result = toUpper ? input.toUpperCase() : input.toLowerCase();

// Unicode defines some codepoints which expand into multiple codepoints,
// originally we do not support this expansion
if (result.length > dstLength)
result = input;
if (result.length <= dstLength)
{
for (let i = 0; i < result.length; i++)
setU16(dst + i*2, result.charCodeAt(i));
wrap_no_error_root(is_exception, exceptionRoot);
return;
}

for (let i = 0; i < result.length; i++)
setU16(dst + i*2, result.charCodeAt(i));
wrap_no_error_root(is_exception, exceptionRoot);
// workaround to maintain the ICU-like behavior
if (toUpper)
{
for (let i=0; i < input.length; i++)
{
const upperChar = input[i].toUpperCase();
const appendedChar = upperChar.length > 1 ? input[i] : upperChar;
setU16(dst + i*2, appendedChar.charCodeAt(0));
}
}
else
{
for (let i=0; i < input.length; i++)
{
const lowerChar = input[i].toLowerCase();
const appendedChar = lowerChar.length > 1 ? input[i] : lowerChar;
setU16(dst + i*2, appendedChar.charCodeAt(0));
}
}
}
catch (ex: any) {
wrap_error_root(is_exception, ex, exceptionRoot);
Expand All @@ -39,12 +61,34 @@ export function mono_wasm_change_case(culture: MonoStringRef, src: number, srcLe
if (!cultureName)
throw new Error("Cannot change case, the culture name is null.");
const input = get_utf16_string(src, srcLength);
let result = toUpper ? input.toLocaleUpperCase(cultureName) : input.toLocaleLowerCase(cultureName);
if (result.length > destLength)
result = input;
const result = toUpper ? input.toLocaleUpperCase(cultureName) : input.toLocaleLowerCase(cultureName);

for (let i = 0; i < destLength; i++)
setU16(dst + i*2, result.charCodeAt(i));
if (result.length <= destLength)
{
for (let i = 0; i < result.length; i++)
setU16(dst + i*2, result.charCodeAt(i));
wrap_no_error_root(is_exception, exceptionRoot);
return;
}
// workaround to maintain the ICU-like behavior
if (toUpper)
{
for (let i=0; i < input.length; i++)
{
const upperChar = input[i].toLocaleUpperCase(cultureName);
const appendedChar = upperChar.length > 1 ? input[i] : upperChar;
setU16(dst + i*2, appendedChar.charCodeAt(0));
}
}
else
{
for (let i=0; i < input.length; i++)
{
const lowerChar = input[i].toLocaleLowerCase(cultureName);
const appendedChar = lowerChar.length > 1 ? input[i] : lowerChar;
setU16(dst + i*2, appendedChar.charCodeAt(0));
}
}
wrap_no_error_root(is_exception, exceptionRoot);
}
catch (ex: any) {
Expand Down