ed2.js
  1  "use strict";
  2  /**
  3   * Character classes and associated utilities for the 2nd edition of XML 1.1.
  4   *
  5   * @author Louis-Dominique Dubeau
  6   * @license MIT
  7   * @copyright Louis-Dominique Dubeau
  8   */
  9  Object.defineProperty(exports, "__esModule", { value: true });
 10  //
 11  // Fragments.
 12  //
 13  exports.CHAR = "\u0001-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
 14  exports.RESTRICTED_CHAR = "\u0001-\u0008\u000B\u000C\u000E-\u001F\u007F-\u0084\u0086-\u009F";
 15  exports.S = " \t\r\n";
 16  // tslint:disable-next-line:max-line-length
 17  exports.NAME_START_CHAR = ":A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
 18  exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\u00B7\u0300-\u036F\u203F-\u2040";
 19  //
 20  // Regular expressions.
 21  //
 22  exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
 23  exports.RESTRICTED_CHAR_RE = new RegExp("^[" + exports.RESTRICTED_CHAR + "]$", "u");
 24  exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
 25  exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
 26  exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
 27  exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
 28  exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
 29  var TAB = 9;
 30  var NL = 0xA;
 31  var CR = 0xD;
 32  var SPACE = 0x20;
 33  //
 34  // Lists.
 35  //
 36  /** All characters in the ``S`` production. */
 37  exports.S_LIST = [SPACE, NL, CR, TAB];
 38  /**
 39   * Determines whether a codepoint matches the ``CHAR`` production.
 40   *
 41   * @param c The code point.
 42   *
 43   * @returns ``true`` if the codepoint matches ``CHAR``.
 44   */
 45  function isChar(c) {
 46      return (c >= 0x0001 && c <= 0xD7FF) ||
 47          (c >= 0xE000 && c <= 0xFFFD) ||
 48          (c >= 0x10000 && c <= 0x10FFFF);
 49  }
 50  exports.isChar = isChar;
 51  /**
 52   * Determines whether a codepoint matches the ``RESTRICTED_CHAR`` production.
 53   *
 54   * @param c The code point.
 55   *
 56   * @returns ``true`` if the codepoint matches ``RESTRICTED_CHAR``.
 57   */
 58  function isRestrictedChar(c) {
 59      return (c >= 0x1 && c <= 0x8) ||
 60          c === 0xB ||
 61          c === 0xC ||
 62          (c >= 0xE && c <= 0x1F) ||
 63          (c >= 0x7F && c <= 0x84) ||
 64          (c >= 0x86 && c <= 0x9F);
 65  }
 66  exports.isRestrictedChar = isRestrictedChar;
 67  /**
 68   * Determines whether a codepoint matches the ``CHAR`` production and does not
 69   * match the ``RESTRICTED_CHAR`` production. ``isCharAndNotRestricted(x)`` is
 70   * equivalent to ``isChar(x) && !isRestrictedChar(x)``. This function is faster
 71   * than running the two-call equivalent.
 72   *
 73   * @param c The code point.
 74   *
 75   * @returns ``true`` if the codepoint matches ``CHAR`` and does not match
 76   * ``RESTRICTED_CHAR``.
 77   */
 78  function isCharAndNotRestricted(c) {
 79      return (c === 0x9) ||
 80          (c === 0xA) ||
 81          (c === 0xD) ||
 82          (c > 0x1F && c < 0x7F) ||
 83          (c === 0x85) ||
 84          (c > 0x9F && c <= 0xD7FF) ||
 85          (c >= 0xE000 && c <= 0xFFFD) ||
 86          (c >= 0x10000 && c <= 0x10FFFF);
 87  }
 88  exports.isCharAndNotRestricted = isCharAndNotRestricted;
 89  /**
 90   * Determines whether a codepoint matches the ``S`` (space) production.
 91   *
 92   * @param c The code point.
 93   *
 94   * @returns ``true`` if the codepoint matches ``S``.
 95   */
 96  function isS(c) {
 97      return c === SPACE || c === NL || c === CR || c === TAB;
 98  }
 99  exports.isS = isS;
100  /**
101   * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
102   *
103   * @param c The code point.
104   *
105   * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
106   */
107  // tslint:disable-next-line:cyclomatic-complexity
108  function isNameStartChar(c) {
109      return ((c >= 0x41 && c <= 0x5A) ||
110          (c >= 0x61 && c <= 0x7A) ||
111          c === 0x3A ||
112          c === 0x5F ||
113          c === 0x200C ||
114          c === 0x200D ||
115          (c >= 0xC0 && c <= 0xD6) ||
116          (c >= 0xD8 && c <= 0xF6) ||
117          (c >= 0x00F8 && c <= 0x02FF) ||
118          (c >= 0x0370 && c <= 0x037D) ||
119          (c >= 0x037F && c <= 0x1FFF) ||
120          (c >= 0x2070 && c <= 0x218F) ||
121          (c >= 0x2C00 && c <= 0x2FEF) ||
122          (c >= 0x3001 && c <= 0xD7FF) ||
123          (c >= 0xF900 && c <= 0xFDCF) ||
124          (c >= 0xFDF0 && c <= 0xFFFD) ||
125          (c >= 0x10000 && c <= 0xEFFFF));
126  }
127  exports.isNameStartChar = isNameStartChar;
128  /**
129   * Determines whether a codepoint matches the ``NAME_CHAR`` production.
130   *
131   * @param c The code point.
132   *
133   * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
134   */
135  function isNameChar(c) {
136      return isNameStartChar(c) ||
137          (c >= 0x30 && c <= 0x39) ||
138          c === 0x2D ||
139          c === 0x2E ||
140          c === 0xB7 ||
141          (c >= 0x0300 && c <= 0x036F) ||
142          (c >= 0x203F && c <= 0x2040);
143  }
144  exports.isNameChar = isNameChar;
145  //# sourceMappingURL=ed2.js.map