Skip to content

Commit

Permalink
fix(developer): ldml drop \u1234 🙀
Browse files Browse the repository at this point in the history
- for now, convert \u{1234} to \u1234 before going into
UnicodeSet.

- for feat(core): ldml drop \u1234 format 🙀  #9515
  • Loading branch information
srl295 committed Sep 15, 2023
1 parent 28012d1 commit 213dd7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions developer/src/kmc-kmn/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ export class KmnCompiler implements UnicodeSetParser {
return Module.kmcmp_testSentry();
}

/** convert `\u{1234}` to `\u1234` */
public static fixNewPattern(pattern: string) : string {
return pattern.replaceAll(/\\u\{([0-9a-fA-F]{4})\}/g, `\\u$1`);
// TODO-LDML: other lengths! #9515
}

/**
*
* @param pattern UnicodeSet pattern such as `[a-z]`
Expand All @@ -435,6 +441,8 @@ export class KmnCompiler implements UnicodeSetParser {

// TODO-LDML: Catch OOM
const buf = this.wasmExports.malloc(rangeCount * 2 * Module.HEAPU32.BYTES_PER_ELEMENT);
// fix \u1234 pattern format
pattern = KmnCompiler.fixNewPattern(pattern);
/** If <= 0: return code. If positive: range count */
const rc = Module.kmcmp_parseUnicodeSet(pattern, buf, rangeCount * 2);
if (rc >= 0) {
Expand All @@ -459,6 +467,8 @@ export class KmnCompiler implements UnicodeSetParser {
/* c8 ignore next 2 */
return null;
}
// fix \u1234 pattern format
pattern = KmnCompiler.fixNewPattern(pattern);
// call with rangeCount = 0 to invoke in 'preflight' mode.
const rc = Module.kmcmp_parseUnicodeSet(pattern, 0, 0);
if (rc >= 0) {
Expand Down
12 changes: 12 additions & 0 deletions developer/src/kmc-kmn/test/test-wasm-uset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { CompilerMessages } from '../src/compiler/messages.js';
import { compilerErrorFormatCode } from '@keymanapp/common-types';

describe('Compiler UnicodeSet function', function() {
it('should fixup \\u1234 format escapes', function() {
assert.equal(KmnCompiler.fixNewPattern(`\\u{1234}`), `\\u1234`);
assert.equal(KmnCompiler.fixNewPattern(`\\u1234`), `\\u1234`);
assert.equal(KmnCompiler.fixNewPattern(`[\\u{1234}-\\u{5678}]`), `[\\u1234-\\u5678]`);
assert.equal(KmnCompiler.fixNewPattern(`something else`), `something else`);
});

it.skip('should fixup more creative \\u format escapes', function() {
assert.equal(KmnCompiler.fixNewPattern(`\\u{22}`), `\\u0022`); // "
assert.equal(KmnCompiler.fixNewPattern(`\\u{1F640}`), `\\uD83D\\uDE40`); // TODO-LDM #9515: or something, 🙀
});

it('should start', async function() {
const compiler = new KmnCompiler();
const callbacks = new TestCompilerCallbacks();
Expand Down

0 comments on commit 213dd7d

Please sign in to comment.