Skip to content

Commit

Permalink
feat: add support for the RestrictedChar production
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jun 24, 2019
1 parent ec43e86 commit 1ff2542
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/xml/1.1/ed2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
//
export const CHAR = "\u0001-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}";

export const RESTRICTED_CHAR =
"\u0001-\u0008\u000B\u000C\u000E-\u001F\u007F-\u0084\u0086-\u009F";

export const S = " \t\r\n";

// tslint:disable-next-line:max-line-length
Expand All @@ -25,6 +28,8 @@ export const NAME_CHAR =

export const CHAR_RE = new RegExp(`^[${CHAR}]$`, "u");

export const RESTRICTED_CHAR_RE = new RegExp(`^[${RESTRICTED_CHAR}]$`, "u");

export const S_RE = new RegExp(`^[${S}]+$`, "u");

export const NAME_START_CHAR_RE = new RegExp(`^[${NAME_START_CHAR}]$`, "u");
Expand Down Expand Up @@ -60,6 +65,22 @@ export function isChar(c: number): boolean {
(c >= 0x10000 && c <= 0x10FFFF);
}

/**
* Determines whether a codepoint matches the ``RESTRICTED_CHAR`` production.
*
* @param c The code point.
*
* @returns ``true`` if the codepoint matches ``RESTRICTED_CHAR``.
*/
export function isRestrictedChar(c: number): boolean {
return (c >= 0x1 && c <= 0x8) ||
c === 0xB ||
c === 0xC ||
(c >= 0xE && c <= 0x1F) ||
(c >= 0x7F && c <= 0x84) ||
(c >= 0x86 && c <= 0x9F);
}

/**
* Determines whether a codepoint matches the ``S`` (space) production.
*
Expand Down
9 changes: 9 additions & 0 deletions test/xmlchars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ describe("xml/1.1", () => {
matching: [one, x, poo, colon, space, tab, newline, cr, ideographic,
combining, digit, extender],
},
RESTRICTED_CHAR_RE: {
matching: [one],
},
S_RE: {
matching: [space, tab, newline, cr],
},
Expand Down Expand Up @@ -336,6 +339,12 @@ describe("xml/1.1", () => {
makeCodePointTestTests(xml_1_1_ed2.isChar, cases.CHAR_RE);
});

describe(".isRestrictedChar", () => {
// tslint:disable-next-line:mocha-no-side-effect-code
makeCodePointTestTests(xml_1_1_ed2.isRestrictedChar,
cases.RESTRICTED_CHAR_RE);
});

describe(".isS", () => {
// tslint:disable-next-line:mocha-no-side-effect-code
makeCodePointTestTests(xml_1_1_ed2.isS, cases.S_RE);
Expand Down

0 comments on commit 1ff2542

Please sign in to comment.