Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #8. Combining marks and ZWJ's don't really exist. #9

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ export function LB09(state) {
// where X is any line break class except BK, CR, LF, NL, SP, or ZW.
if (![BK, CR, LF, NL, SP, ZW].includes(state.cur.cls)
&& ((state.next.cls === CM) || (state.next.cls === ZWJ))) {
state.next.cls = state.cur.cls;
state.next.char = state.cur.char;
state.next.cp = state.cur.cp;
state.next.ignored = true;
return NO_BREAK;
}
return PASS;
Expand Down
16 changes: 13 additions & 3 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export class BreakerChar {
*/
len = 0;

/**
* If true, this is an LB9 CM or ZWJ that is treated as coalesced into
* the previous code point.
*/
ignored = false;

/**
* @param {number} cls
* @param {number} cp
Expand All @@ -93,7 +99,7 @@ export class BreakerChar {
* @returns
*/
[Symbol.for('nodejs.util.inspect.custom')](_depth, _inspectOptions, _inspect) {
return `${classText(this.cls)}(${this.cp.toString(16).padStart(4, '0')}:${JSON.stringify(this.char)})`;
return `${classText(this.cls)}(${this.cp.toString(16).padStart(4, '0')}:${JSON.stringify(this.char)})${this.ignored ? 'Ig' : ''}`;
}
}

Expand Down Expand Up @@ -145,8 +151,12 @@ export class BreakerState {
* @param {BreakerChar} step
*/
push(step) {
this.prev = this.cur;
this.cur = this.next;
if (this.next.ignored) {
this.cur.len = this.next.len;
} else {
this.prev = this.cur;
this.cur = this.next;
}
this.next = step;
}

Expand Down
5 changes: 0 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ describe('unicode line break tests', function() {
if (!line || /^#/.test(line)) { return; }

const [cols, comment] = line.split('#');

// In 15.1, row 10287 really doesn't seem right to me.
if (cols === '× 1B18 ÷ 1B27 × 1B44 × 200C × 1B2B × 1B38 ÷ 1B31 × 1B44 × 1B1D × 1B36 ÷\t') {
return;
}
const codePoints = cols.split(/\s*[×÷]\s*/).slice(1, -1).map(c => parseInt(c, 16));
const str = String.fromCodePoint(...codePoints);

Expand Down
8 changes: 7 additions & 1 deletion test/state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe('manage parsing state', () => {
const str = '123';
const state = new BreakerState(str);
assert.deepEqual([...state.codePoints(1)].map(s => s.len), [2, 3]);
// Initialized with sot, sot, sot
const first = state.afterNext();
assert.deepEqual(first.char, '1');
state.push(first);
assert.deepEqual(state.afterNext().char, '2');
});

it('resolves Mn and Mc', () => {
Expand All @@ -36,6 +41,7 @@ describe('manage parsing state', () => {
state.RI = 1;
state.ex7pos = 5;
state.setProp('foo', 'bar');
assert.equal(util.inspect(state), 'sot(-Infinity:"") => XX(-Infinity:"") => eot(-Infinity:"") LB8 spaces RI: 1 ex7: 5 {"foo":"bar"}');
state.next.ignored = true;
assert.equal(util.inspect(state), 'sot(-Infinity:"") => XX(-Infinity:"") => eot(-Infinity:"")Ig LB8 spaces RI: 1 ex7: 5 {"foo":"bar"}');
});
});