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
Prev Previous commit
Next Next commit
Merge branch 'main' into hg-normalization
  • Loading branch information
ilonatommy committed May 19, 2023
commit daf236052ec95129efcbcdaee08e9457284d0f35
2 changes: 2 additions & 0 deletions src/mono/wasm/runtime/corebindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern void mono_wasm_change_case(MonoString **exceptionMessage, MonoString **cu
extern int mono_wasm_compare_string(MonoString **exceptionMessage, MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options);
extern mono_bool mono_wasm_starts_with(MonoString **exceptionMessage, MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options);
extern mono_bool mono_wasm_ends_with(MonoString **exceptionMessage, MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options);
extern int mono_wasm_index_of(MonoString **exceptionMessage, MonoString **culture, const uint16_t* str1, int32_t str1Length, const uint16_t* str2, int32_t str2Length, int32_t options, mono_bool fromBeginning);
extern mono_bool mono_wasm_is_normalized(MonoString **exceptionMessage, int32_t normalizationForm, MonoString **src);
extern int mono_wasm_normalize_string(MonoString **exceptionMessage, int32_t normalizationForm, MonoString **src, uint16_t* dst, int32_t dstLength);

Expand Down Expand Up @@ -83,6 +84,7 @@ void bindings_initialize_internals (void)
mono_add_internal_call ("Interop/JsGlobalization::CompareString", mono_wasm_compare_string);
mono_add_internal_call ("Interop/JsGlobalization::StartsWith", mono_wasm_starts_with);
mono_add_internal_call ("Interop/JsGlobalization::EndsWith", mono_wasm_ends_with);
mono_add_internal_call ("Interop/JsGlobalization::IndexOf", mono_wasm_index_of);
mono_add_internal_call ("Interop/JsGlobalization::IsNormalized", mono_wasm_is_normalized);
mono_add_internal_call ("Interop/JsGlobalization::NormalizeString", mono_wasm_normalize_string);
}
1 change: 1 addition & 0 deletions src/mono/wasm/runtime/es6/dotnet.es6.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ let linked_functions = [
"mono_wasm_compare_string",
"mono_wasm_starts_with",
"mono_wasm_ends_with",
"mono_wasm_index_of",
"mono_wasm_is_normalized",
"mono_wasm_normalize_string",
"mono_wasm_to_Unicode",
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/exports-linker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
mono_wasm_get_by_index_ref, mono_wasm_set_by_index_ref, mono_wasm_get_global_object_ref
} from "./net6-legacy/method-calls";
import { mono_wasm_change_case, mono_wasm_change_case_invariant } from "./hybrid-globalization/change-case";
import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with } from "./hybrid-globalization/collations";
import { mono_wasm_compare_string, mono_wasm_ends_with, mono_wasm_starts_with, mono_wasm_index_of } from "./hybrid-globalization/collations";
import { mono_wasm_is_normalized, mono_wasm_normalize_string } from "./hybrid-globalization/normalization";

// the methods would be visible to EMCC linker
Expand Down Expand Up @@ -104,6 +104,7 @@ export function export_linker(): any {
mono_wasm_compare_string,
mono_wasm_starts_with,
mono_wasm_ends_with,
mono_wasm_index_of,
mono_wasm_is_normalized,
mono_wasm_normalize_string,

Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/runtime/hybrid-globalization/change-case.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { Module } from "../imports";
import { Module } from "../globals";
import { setU16 } from "../memory";
import { mono_wasm_new_external_root } from "../roots";
import { conv_string_root } from "../strings";
import { MonoString, MonoStringRef } from "../types";
import { MonoString, MonoStringRef } from "../types/internal";
import { Int32Ptr } from "../types/emscripten";
import { pass_exception_details } from "./common";

Expand Down
57 changes: 29 additions & 28 deletions src/mono/wasm/runtime/hybrid-globalization/collations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

import { mono_wasm_new_external_root } from "../roots";
import { conv_string_root, string_decoder } from "../strings";
import { MonoString, MonoStringRef } from "../types";
import { MonoString, MonoStringRef } from "../types/internal";
import { Int32Ptr } from "../types/emscripten";
import { pass_exception_details } from "./common";

export function mono_wasm_compare_string(exceptionMessage: Int32Ptr, culture: MonoStringRef, str1: number, str1Length: number, str2: number, str2Length: number, options: number) : number{
const cultureRoot = mono_wasm_new_external_root<MonoString>(culture);
try {
try{
const cultureName = conv_string_root(cultureRoot);
const string1 = string_decoder.decode(<any>str1, <any>(str1 + 2 * str1Length));
const string2 = string_decoder.decode(<any>str2, <any>(str2 + 2 * str2Length));
const string1 = string_decoder.decode(<any>str1, <any>(str1 + 2*str1Length));
const string2 = string_decoder.decode(<any>str2, <any>(str2 + 2*str2Length));
const casePicker = (options & 0x1f);
const locale = cultureName ? cultureName : undefined;
return compare_strings(string1, string2, locale, casePicker);
Expand All @@ -28,14 +28,14 @@ export function mono_wasm_compare_string(exceptionMessage: Int32Ptr, culture: Mo

export function mono_wasm_starts_with(exceptionMessage: Int32Ptr, culture: MonoStringRef, str1: number, str1Length: number, str2: number, str2Length: number, options: number): number{
const cultureRoot = mono_wasm_new_external_root<MonoString>(culture);
try {
try{
const cultureName = conv_string_root(cultureRoot);
const prefix = decode_to_clean_string(prefixPtr, prefixLength);
const prefix = decode_to_clean_string(str2, str2Length);
// no need to look for an empty string
if (prefix.length == 0)
return 1; // true

const source = decode_to_clean_string(srcPtr, srcLength);
const source = decode_to_clean_string(str1, str1Length);
if (source.length < prefix.length)
return 0; //false
const sourceOfPrefixLength = source.slice(0, prefix.length);
Expand All @@ -54,15 +54,15 @@ export function mono_wasm_starts_with(exceptionMessage: Int32Ptr, culture: MonoS
}
}

export function mono_wasm_ends_with(exceptionMessage: Int32Ptr, culture: MonoStringRef, srcPtr: number, srcLength: number, suffixPtr: number, suffixLength: number, options: number): number{
export function mono_wasm_ends_with(exceptionMessage: Int32Ptr, culture: MonoStringRef, str1: number, str1Length: number, str2: number, str2Length: number, options: number): number{
const cultureRoot = mono_wasm_new_external_root<MonoString>(culture);
try {
try{
const cultureName = conv_string_root(cultureRoot);
const suffix = decode_to_clean_string(suffixPtr, suffixLength);
const suffix = decode_to_clean_string(str2, str2Length);
if (suffix.length == 0)
return 1; // true

const source = decode_to_clean_string(srcPtr, srcLength);
const source = decode_to_clean_string(str1, str1Length);
const diff = source.length - suffix.length;
if (diff < 0)
return 0; //false
Expand All @@ -82,18 +82,6 @@ export function mono_wasm_ends_with(exceptionMessage: Int32Ptr, culture: MonoStr
}
}

function decode_to_clean_string(strPtr: number, strLen: number)
{
const str = string_decoder.decode(<any>strPtr, <any>(strPtr + 2*strLen));
return clean_string(str);
}

function clean_string(str: string)
{
const nStr = str.normalize();
return nStr.replace(/[\u200B-\u200D\uFEFF\0]/g, "");
}

export function mono_wasm_index_of(exceptionMessage: Int32Ptr, culture: MonoStringRef, needlePtr: number, needleLength: number, srcPtr: number, srcLength: number, options: number, fromBeginning: number): number{
const cultureRoot = mono_wasm_new_external_root<MonoString>(culture);
try {
Expand Down Expand Up @@ -180,18 +168,19 @@ export function mono_wasm_index_of(exceptionMessage: Int32Ptr, culture: MonoStri
}
}

export function compare_strings(string1: string, string2: string, locale: string | undefined, casePicker: number): number {
switch (casePicker) {
export function compare_strings(string1: string, string2: string, locale: string | undefined, casePicker: number) : number{
switch (casePicker)
{
case 0:
// 0: None - default algorithm for the platform OR
// StringSort - since .Net 5 StringSort gives the same result as None, even for hyphen etc.
// StringSort - for ICU it gives the same result as None, see: https://github.com/dotnet/dotnet-api-docs/issues
// does not work for "ja"
if (locale && locale.startsWith("ja"))
if (locale && locale.split("-")[0] === "ja")
return -2;
return string1.localeCompare(string2, locale); // a ≠ b, a ≠ á, a ≠ A
case 8:
// 8: IgnoreKanaType works only for "ja"
if (locale && !locale.startsWith("ja"))
if (locale && locale.split("-")[0] !== "ja")
return -2;
return string1.localeCompare(string2, locale); // a ≠ b, a ≠ á, a ≠ A
case 1:
Expand Down Expand Up @@ -271,3 +260,15 @@ export function compare_strings(string1: string, string2: string, locale: string
throw new Error(`Invalid comparison option. Option=${casePicker}`);
}
}

function decode_to_clean_string(strPtr: number, strLen: number)
{
const str = string_decoder.decode(<any>strPtr, <any>(strPtr + 2*strLen));
return clean_string(str);
}

function clean_string(str: string)
{
const nStr = str.normalize();
return nStr.replace(/[\u200B-\u200D\uFEFF\0]/g, "");
}
2 changes: 1 addition & 1 deletion src/mono/wasm/runtime/hybrid-globalization/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

import { mono_wasm_new_external_root } from "../roots";
import {MonoString } from "../types";
import { MonoString } from "../types/internal";
import { Int32Ptr } from "../types/emscripten";
import { js_string_to_mono_string_root } from "../strings";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { setU16 } from "../memory";
import { mono_wasm_new_external_root } from "../roots";
import { conv_string_root } from "../strings";
import { MonoString, MonoStringRef } from "../types";
import { MonoString, MonoStringRef } from "../types/internal";
import { Int32Ptr } from "../types/emscripten";
import { pass_exception_details } from "./common";

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.