mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-21 15:17:40 +00:00
fix(developer): ldml drop \u1234 🙀
- for now, convert \u{1234} to \u1234 before going into
UnicodeSet.
- for feat(core): ldml drop \u1234 format 🙀 #9515
This commit is contained in:
parent
28012d1f7d
commit
213dd7d2ad
2 changed files with 22 additions and 0 deletions
|
|
@ -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]`
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue