diff --git a/common/web/types/src/ldml-keyboard/unicodeset-parser-api.ts b/common/web/types/src/ldml-keyboard/unicodeset-parser-api.ts index 6e6cb9445c..0c890aa95a 100644 --- a/common/web/types/src/ldml-keyboard/unicodeset-parser-api.ts +++ b/common/web/types/src/ldml-keyboard/unicodeset-parser-api.ts @@ -6,9 +6,9 @@ export interface UnicodeSetParser { /** * Parse a UnicodeSet into ranges * @param pattern string to parse such as `[a-z]` - * @param bufferSize number of ranges to allow for + * @param rangeCount number of ranges to allow for */ - parseUnicodeSet(pattern: string, bufferSize: number) : UnicodeSet | null; + parseUnicodeSet(pattern: string, rangeCount: number) : UnicodeSet | null; /** * Calculate the number of ranges in a UnicodeSet * @param pattern string to parse such as `[a-z]` @@ -18,9 +18,16 @@ export interface UnicodeSetParser { } /** - * Represents a parsed UnicodeSet + * Parsed UnicodeSet, return value of of parseUnicodeSet() */ export class UnicodeSet { + /** + * A UnicodeSet in range form. + * For example, `[ħa-z]` will parse to + * ranges = `[[0x41, 0x7A], [0x0127, 0x0127]]` meaning `[a,z], [ħ,ħ]` + * @param pattern the pattern per UnicodeSet syntax such as `[a-z]` + * @param ranges array of 2-element arrays, 'start' and 'end'. + */ constructor(public pattern: string, public ranges: number[][]) { } /** diff --git a/developer/src/kmc-kmn/src/compiler/compiler.ts b/developer/src/kmc-kmn/src/compiler/compiler.ts index dc35a3a697..499c74abe9 100644 --- a/developer/src/kmc-kmn/src/compiler/compiler.ts +++ b/developer/src/kmc-kmn/src/compiler/compiler.ts @@ -228,22 +228,19 @@ export class KmnCompiler implements UnicodeSetParser { /** * * @param pattern UnicodeSet pattern such as `[a-z]` - * @param bufferSize guess as to the buffer size + * @param rangeCount number of ranges to allocate * @returns UnicodeSet accessor object, or null on failure */ - public parseUnicodeSet(pattern: string, bufferSize: number) : UnicodeSet | null { + public parseUnicodeSet(pattern: string, rangeCount: number) : UnicodeSet | null { if(!this.verifyInitialized()) { /* c8 ignore next 2 */ return null; } - if (!bufferSize) { - /* c8 ignore next 2 */ - bufferSize = 100; // TODO-LDML: Preflight mode? Reuse buffer? - } - const buf = this.Module.asm.malloc(bufferSize * 2 * this.Module.HEAPU32.BYTES_PER_ELEMENT); + const buf = this.Module.asm.malloc(rangeCount * 2 * this.Module.HEAPU32.BYTES_PER_ELEMENT); // TODO-LDML: Catch OOM - const rc = this.Module.kmcmp_parseUnicodeSet(pattern, buf, bufferSize); + /** return code, if positive: range count */ + const rc = this.Module.kmcmp_parseUnicodeSet(pattern, buf, rangeCount * 2); if (rc >= 0) { const ranges = []; const startu = (buf / this.Module.HEAPU32.BYTES_PER_ELEMENT);