123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209 |
- ;(function(root) {
-
- var freeExports = typeof exports == 'object' && exports;
-
- var freeModule = typeof module == 'object' && module &&
- module.exports == freeExports && module;
-
-
- var freeGlobal = typeof global == 'object' && global;
- if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
- root = freeGlobal;
- }
-
- var ERRORS = {
- 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' +
- 'to the `start` value.',
- 'codePointRange': 'Invalid code point value. Code points range from ' +
- 'U+000000 to U+10FFFF.'
- };
-
- var HIGH_SURROGATE_MIN = 0xD800;
- var HIGH_SURROGATE_MAX = 0xDBFF;
- var LOW_SURROGATE_MIN = 0xDC00;
- var LOW_SURROGATE_MAX = 0xDFFF;
-
-
- var regexNull = /\\x00([^0123456789]|$)/g;
- var object = {};
- var hasOwnProperty = object.hasOwnProperty;
- var extend = function(destination, source) {
- var key;
- for (key in source) {
- if (hasOwnProperty.call(source, key)) {
- destination[key] = source[key];
- }
- }
- return destination;
- };
- var forEach = function(array, callback) {
- var index = -1;
- var length = array.length;
- while (++index < length) {
- callback(array[index], index);
- }
- };
- var toString = object.toString;
- var isArray = function(value) {
- return toString.call(value) == '[object Array]';
- };
- var isNumber = function(value) {
- return typeof value == 'number' ||
- toString.call(value) == '[object Number]';
- };
-
-
- var zeroes = '0000';
- var pad = function(number, totalCharacters) {
- var string = String(number);
- return string.length < totalCharacters
- ? (zeroes + string).slice(-totalCharacters)
- : string;
- };
- var hex = function(number) {
- return Number(number).toString(16).toUpperCase();
- };
- var slice = [].slice;
-
- var dataFromCodePoints = function(codePoints) {
- var index = -1;
- var length = codePoints.length;
- var max = length - 1;
- var result = [];
- var isStart = true;
- var tmp;
- var previous = 0;
- while (++index < length) {
- tmp = codePoints[index];
- if (isStart) {
- result.push(tmp);
- previous = tmp;
- isStart = false;
- } else {
- if (tmp == previous + 1) {
- if (index != max) {
- previous = tmp;
- continue;
- } else {
- isStart = true;
- result.push(tmp + 1);
- }
- } else {
-
- result.push(previous + 1, tmp);
- previous = tmp;
- }
- }
- }
- if (!isStart) {
- result.push(tmp + 1);
- }
- return result;
- };
- var dataRemove = function(data, codePoint) {
-
- var index = 0;
- var start;
- var end;
- var length = data.length;
- while (index < length) {
- start = data[index];
- end = data[index + 1];
- if (codePoint >= start && codePoint < end) {
-
- if (codePoint == start) {
- if (end == start + 1) {
-
- data.splice(index, 2);
- return data;
- } else {
-
- data[index] = codePoint + 1;
- return data;
- }
- } else if (codePoint == end - 1) {
-
- data[index + 1] = codePoint;
- return data;
- } else {
-
- data.splice(index, 2, start, codePoint, codePoint + 1, end);
- return data;
- }
- }
- index += 2;
- }
- return data;
- };
- var dataRemoveRange = function(data, rangeStart, rangeEnd) {
- if (rangeEnd < rangeStart) {
- throw Error(ERRORS.rangeOrder);
- }
-
- var index = 0;
- var start;
- var end;
- while (index < data.length) {
- start = data[index];
- end = data[index + 1] - 1;
-
- if (start > rangeEnd) {
- return data;
- }
-
-
-
-
- if (rangeStart <= start && rangeEnd >= end) {
-
- data.splice(index, 2);
- continue;
- }
-
-
-
- if (rangeStart >= start && rangeEnd < end) {
- if (rangeStart == start) {
-
- data[index] = rangeEnd + 1;
- data[index + 1] = end + 1;
- return data;
- }
-
- data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1);
- return data;
- }
-
-
- if (rangeStart >= start && rangeStart <= end) {
-
- data[index + 1] = rangeStart;
-
-
-
-
- }
-
-
- else if (rangeEnd >= start && rangeEnd <= end) {
-
- data[index] = rangeEnd + 1;
- return data;
- }
- index += 2;
- }
- return data;
- };
- var dataAdd = function(data, codePoint) {
-
- var index = 0;
- var start;
- var end;
- var lastIndex = null;
- var length = data.length;
- if (codePoint < 0x0 || codePoint > 0x10FFFF) {
- throw RangeError(ERRORS.codePointRange);
- }
- while (index < length) {
- start = data[index];
- end = data[index + 1];
-
- if (codePoint >= start && codePoint < end) {
- return data;
- }
- if (codePoint == start - 1) {
-
- data[index] = codePoint;
- return data;
- }
-
-
-
- if (start > codePoint) {
- data.splice(
- lastIndex != null ? lastIndex + 2 : 0,
- 0,
- codePoint,
- codePoint + 1
- );
- return data;
- }
- if (codePoint == end) {
-
-
- if (codePoint + 1 == data[index + 2]) {
- data.splice(index, 4, start, data[index + 3]);
- return data;
- }
-
- data[index + 1] = codePoint + 1;
- return data;
- }
- lastIndex = index;
- index += 2;
- }
-
- data.push(codePoint, codePoint + 1);
- return data;
- };
- var dataAddData = function(dataA, dataB) {
-
- var index = 0;
- var start;
- var end;
- var data = dataA.slice();
- var length = dataB.length;
- while (index < length) {
- start = dataB[index];
- end = dataB[index + 1] - 1;
- if (start == end) {
- data = dataAdd(data, start);
- } else {
- data = dataAddRange(data, start, end);
- }
- index += 2;
- }
- return data;
- };
- var dataRemoveData = function(dataA, dataB) {
-
- var index = 0;
- var start;
- var end;
- var data = dataA.slice();
- var length = dataB.length;
- while (index < length) {
- start = dataB[index];
- end = dataB[index + 1] - 1;
- if (start == end) {
- data = dataRemove(data, start);
- } else {
- data = dataRemoveRange(data, start, end);
- }
- index += 2;
- }
- return data;
- };
- var dataAddRange = function(data, rangeStart, rangeEnd) {
- if (rangeEnd < rangeStart) {
- throw Error(ERRORS.rangeOrder);
- }
- if (
- rangeStart < 0x0 || rangeStart > 0x10FFFF ||
- rangeEnd < 0x0 || rangeEnd > 0x10FFFF
- ) {
- throw RangeError(ERRORS.codePointRange);
- }
-
- var index = 0;
- var start;
- var end;
- var added = false;
- var length = data.length;
- while (index < length) {
- start = data[index];
- end = data[index + 1];
- if (added) {
-
-
-
- if (start == rangeEnd + 1) {
- data.splice(index - 1, 2);
- return data;
- }
-
- if (start > rangeEnd) {
- return data;
- }
-
-
-
- if (start >= rangeStart && start <= rangeEnd) {
-
- if (end > rangeStart && end - 1 <= rangeEnd) {
-
-
- data.splice(index, 2);
- index -= 2;
-
-
- } else {
-
-
-
-
- data.splice(index - 1, 2);
- index -= 2;
- }
-
- }
- }
- else if (start == rangeEnd + 1 || start == rangeEnd) {
- data[index] = rangeStart;
- return data;
- }
-
- else if (start > rangeEnd) {
- data.splice(index, 0, rangeStart, rangeEnd + 1);
- return data;
- }
- else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) {
-
-
- return data;
- }
- else if (
-
- (rangeStart >= start && rangeStart < end) ||
-
- end == rangeStart
- ) {
-
- data[index + 1] = rangeEnd + 1;
-
-
- added = true;
-
- }
- else if (rangeStart <= start && rangeEnd + 1 >= end) {
-
- data[index] = rangeStart;
- data[index + 1] = rangeEnd + 1;
- added = true;
- }
- index += 2;
- }
-
-
- if (!added) {
- data.push(rangeStart, rangeEnd + 1);
- }
- return data;
- };
- var dataContains = function(data, codePoint) {
- var index = 0;
- var length = data.length;
-
- var start = data[index];
- var end = data[length - 1];
- if (length >= 2) {
- if (codePoint < start || codePoint > end) {
- return false;
- }
- }
-
- while (index < length) {
- start = data[index];
- end = data[index + 1];
- if (codePoint >= start && codePoint < end) {
- return true;
- }
- index += 2;
- }
- return false;
- };
- var dataIntersection = function(data, codePoints) {
- var index = 0;
- var length = codePoints.length;
- var codePoint;
- var result = [];
- while (index < length) {
- codePoint = codePoints[index];
- if (dataContains(data, codePoint)) {
- result.push(codePoint);
- }
- ++index;
- }
- return dataFromCodePoints(result);
- };
- var dataIsEmpty = function(data) {
- return !data.length;
- };
- var dataIsSingleton = function(data) {
-
- return data.length == 2 && data[0] + 1 == data[1];
- };
- var dataToArray = function(data) {
-
- var index = 0;
- var start;
- var end;
- var result = [];
- var length = data.length;
- while (index < length) {
- start = data[index];
- end = data[index + 1];
- while (start < end) {
- result.push(start);
- ++start;
- }
- index += 2;
- }
- return result;
- };
-
-
- var floor = Math.floor;
- var highSurrogate = function(codePoint) {
- return parseInt(
- floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN,
- 10
- );
- };
- var lowSurrogate = function(codePoint) {
- return parseInt(
- (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN,
- 10
- );
- };
- var stringFromCharCode = String.fromCharCode;
- var codePointToString = function(codePoint) {
- var string;
-
-
-
-
- if (codePoint == 0x09) {
- string = '\\t';
- }
-
-
-
-
- else if (codePoint == 0x0A) {
- string = '\\n';
- }
- else if (codePoint == 0x0C) {
- string = '\\f';
- }
- else if (codePoint == 0x0D) {
- string = '\\r';
- }
- else if (codePoint == 0x2D) {
-
-
-
-
-
- string = '\\x2D';
- }
- else if (codePoint == 0x5C) {
- string = '\\\\';
- }
- else if (
- codePoint == 0x24 ||
- (codePoint >= 0x28 && codePoint <= 0x2B) ||
- codePoint == 0x2E || codePoint == 0x2F ||
- codePoint == 0x3F ||
- (codePoint >= 0x5B && codePoint <= 0x5E) ||
- (codePoint >= 0x7B && codePoint <= 0x7D)
- ) {
-
-
-
-
-
-
-
- string = '\\' + stringFromCharCode(codePoint);
- }
- else if (codePoint >= 0x20 && codePoint <= 0x7E) {
-
-
-
-
-
-
-
- string = stringFromCharCode(codePoint);
- }
- else if (codePoint <= 0xFF) {
- string = '\\x' + pad(hex(codePoint), 2);
- }
- else {
-
- string = '\\u' + pad(hex(codePoint), 4);
- }
-
-
-
-
-
-
- return string;
- };
- var codePointToStringUnicode = function(codePoint) {
- if (codePoint <= 0xFFFF) {
- return codePointToString(codePoint);
- }
- return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
- };
- var symbolToCodePoint = function(symbol) {
- var length = symbol.length;
- var first = symbol.charCodeAt(0);
- var second;
- if (
- first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX &&
- length > 1
- ) {
-
-
- second = symbol.charCodeAt(1);
-
- return (first - HIGH_SURROGATE_MIN) * 0x400 +
- second - LOW_SURROGATE_MIN + 0x10000;
- }
- return first;
- };
- var createBMPCharacterClasses = function(data) {
-
- var result = '';
- var index = 0;
- var start;
- var end;
- var length = data.length;
- if (dataIsSingleton(data)) {
- return codePointToString(data[0]);
- }
- while (index < length) {
- start = data[index];
- end = data[index + 1] - 1;
- if (start == end) {
- result += codePointToString(start);
- } else if (start + 1 == end) {
- result += codePointToString(start) + codePointToString(end);
- } else {
- result += codePointToString(start) + '-' + codePointToString(end);
- }
- index += 2;
- }
- return '[' + result + ']';
- };
- var createUnicodeCharacterClasses = function(data) {
-
- var result = '';
- var index = 0;
- var start;
- var end;
- var length = data.length;
- if (dataIsSingleton(data)) {
- return codePointToStringUnicode(data[0]);
- }
- while (index < length) {
- start = data[index];
- end = data[index + 1] - 1;
- if (start == end) {
- result += codePointToStringUnicode(start);
- } else if (start + 1 == end) {
- result += codePointToStringUnicode(start) + codePointToStringUnicode(end);
- } else {
- result += codePointToStringUnicode(start) + '-' + codePointToStringUnicode(end);
- }
- index += 2;
- }
- return '[' + result + ']';
- };
- var splitAtBMP = function(data) {
-
- var loneHighSurrogates = [];
- var loneLowSurrogates = [];
- var bmp = [];
- var astral = [];
- var index = 0;
- var start;
- var end;
- var length = data.length;
- while (index < length) {
- start = data[index];
- end = data[index + 1] - 1;
- if (start < HIGH_SURROGATE_MIN) {
-
-
- if (end < HIGH_SURROGATE_MIN) {
- bmp.push(start, end + 1);
- }
-
-
- if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
- bmp.push(start, HIGH_SURROGATE_MIN);
- loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1);
- }
-
-
- if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
- bmp.push(start, HIGH_SURROGATE_MIN);
- loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
- loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
- }
-
-
- if (end > LOW_SURROGATE_MAX) {
- bmp.push(start, HIGH_SURROGATE_MIN);
- loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1);
- loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
- if (end <= 0xFFFF) {
- bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
- } else {
- bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
- astral.push(0xFFFF + 1, end + 1);
- }
- }
- } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) {
-
-
- if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) {
- loneHighSurrogates.push(start, end + 1);
- }
-
-
- if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
- loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
- loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1);
- }
-
-
- if (end > LOW_SURROGATE_MAX) {
- loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1);
- loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1);
- if (end <= 0xFFFF) {
- bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
- } else {
- bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
- astral.push(0xFFFF + 1, end + 1);
- }
- }
- } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) {
-
-
- if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) {
- loneLowSurrogates.push(start, end + 1);
- }
-
-
- if (end > LOW_SURROGATE_MAX) {
- loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1);
- if (end <= 0xFFFF) {
- bmp.push(LOW_SURROGATE_MAX + 1, end + 1);
- } else {
- bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1);
- astral.push(0xFFFF + 1, end + 1);
- }
- }
- } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) {
-
-
- if (end <= 0xFFFF) {
- bmp.push(start, end + 1);
- } else {
- bmp.push(start, 0xFFFF + 1);
- astral.push(0xFFFF + 1, end + 1);
- }
- } else {
-
- astral.push(start, end + 1);
- }
- index += 2;
- }
- return {
- 'loneHighSurrogates': loneHighSurrogates,
- 'loneLowSurrogates': loneLowSurrogates,
- 'bmp': bmp,
- 'astral': astral
- };
- };
- var optimizeSurrogateMappings = function(surrogateMappings) {
- var result = [];
- var tmpLow = [];
- var addLow = false;
- var mapping;
- var nextMapping;
- var highSurrogates;
- var lowSurrogates;
- var nextHighSurrogates;
- var nextLowSurrogates;
- var index = -1;
- var length = surrogateMappings.length;
- while (++index < length) {
- mapping = surrogateMappings[index];
- nextMapping = surrogateMappings[index + 1];
- if (!nextMapping) {
- result.push(mapping);
- continue;
- }
- highSurrogates = mapping[0];
- lowSurrogates = mapping[1];
- nextHighSurrogates = nextMapping[0];
- nextLowSurrogates = nextMapping[1];
-
- tmpLow = lowSurrogates;
- while (
- nextHighSurrogates &&
- highSurrogates[0] == nextHighSurrogates[0] &&
- highSurrogates[1] == nextHighSurrogates[1]
- ) {
-
- if (dataIsSingleton(nextLowSurrogates)) {
- tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]);
- } else {
- tmpLow = dataAddRange(
- tmpLow,
- nextLowSurrogates[0],
- nextLowSurrogates[1] - 1
- );
- }
- ++index;
- mapping = surrogateMappings[index];
- highSurrogates = mapping[0];
- lowSurrogates = mapping[1];
- nextMapping = surrogateMappings[index + 1];
- nextHighSurrogates = nextMapping && nextMapping[0];
- nextLowSurrogates = nextMapping && nextMapping[1];
- addLow = true;
- }
- result.push([
- highSurrogates,
- addLow ? tmpLow : lowSurrogates
- ]);
- addLow = false;
- }
- return optimizeByLowSurrogates(result);
- };
- var optimizeByLowSurrogates = function(surrogateMappings) {
- if (surrogateMappings.length == 1) {
- return surrogateMappings;
- }
- var index = -1;
- var innerIndex = -1;
- while (++index < surrogateMappings.length) {
- var mapping = surrogateMappings[index];
- var lowSurrogates = mapping[1];
- var lowSurrogateStart = lowSurrogates[0];
- var lowSurrogateEnd = lowSurrogates[1];
- innerIndex = index;
- while (++innerIndex < surrogateMappings.length) {
- var otherMapping = surrogateMappings[innerIndex];
- var otherLowSurrogates = otherMapping[1];
- var otherLowSurrogateStart = otherLowSurrogates[0];
- var otherLowSurrogateEnd = otherLowSurrogates[1];
- if (
- lowSurrogateStart == otherLowSurrogateStart &&
- lowSurrogateEnd == otherLowSurrogateEnd &&
- otherLowSurrogates.length === 2
- ) {
-
- if (dataIsSingleton(otherMapping[0])) {
- mapping[0] = dataAdd(mapping[0], otherMapping[0][0]);
- } else {
- mapping[0] = dataAddRange(
- mapping[0],
- otherMapping[0][0],
- otherMapping[0][1] - 1
- );
- }
-
- surrogateMappings.splice(innerIndex, 1);
- --innerIndex;
- }
- }
- }
- return surrogateMappings;
- };
- var surrogateSet = function(data) {
-
- if (!data.length) {
- return [];
- }
-
- var index = 0;
- var start;
- var end;
- var startHigh;
- var startLow;
- var endHigh;
- var endLow;
- var surrogateMappings = [];
- var length = data.length;
- while (index < length) {
- start = data[index];
- end = data[index + 1] - 1;
- startHigh = highSurrogate(start);
- startLow = lowSurrogate(start);
- endHigh = highSurrogate(end);
- endLow = lowSurrogate(end);
- var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN;
- var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX;
- var complete = false;
-
-
- if (
- startHigh == endHigh ||
- startsWithLowestLowSurrogate && endsWithHighestLowSurrogate
- ) {
- surrogateMappings.push([
- [startHigh, endHigh + 1],
- [startLow, endLow + 1]
- ]);
- complete = true;
- } else {
- surrogateMappings.push([
- [startHigh, startHigh + 1],
- [startLow, LOW_SURROGATE_MAX + 1]
- ]);
- }
-
-
- if (!complete && startHigh + 1 < endHigh) {
- if (endsWithHighestLowSurrogate) {
-
- surrogateMappings.push([
- [startHigh + 1, endHigh + 1],
- [LOW_SURROGATE_MIN, endLow + 1]
- ]);
- complete = true;
- } else {
- surrogateMappings.push([
- [startHigh + 1, endHigh],
- [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1]
- ]);
- }
- }
-
- if (!complete) {
- surrogateMappings.push([
- [endHigh, endHigh + 1],
- [LOW_SURROGATE_MIN, endLow + 1]
- ]);
- }
- index += 2;
- }
-
-
-
-
-
-
-
-
-
-
- return optimizeSurrogateMappings(surrogateMappings);
- };
- var createSurrogateCharacterClasses = function(surrogateMappings) {
- var result = [];
- forEach(surrogateMappings, function(surrogateMapping) {
- var highSurrogates = surrogateMapping[0];
- var lowSurrogates = surrogateMapping[1];
- result.push(
- createBMPCharacterClasses(highSurrogates) +
- createBMPCharacterClasses(lowSurrogates)
- );
- });
- return result.join('|');
- };
- var createCharacterClassesFromData = function(data, bmpOnly, hasUnicodeFlag) {
- if (hasUnicodeFlag) {
- return createUnicodeCharacterClasses(data);
- }
- var result = [];
- var parts = splitAtBMP(data);
- var loneHighSurrogates = parts.loneHighSurrogates;
- var loneLowSurrogates = parts.loneLowSurrogates;
- var bmp = parts.bmp;
- var astral = parts.astral;
- var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates);
- var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates);
- var surrogateMappings = surrogateSet(astral);
- if (bmpOnly) {
- bmp = dataAddData(bmp, loneHighSurrogates);
- hasLoneHighSurrogates = false;
- bmp = dataAddData(bmp, loneLowSurrogates);
- hasLoneLowSurrogates = false;
- }
- if (!dataIsEmpty(bmp)) {
-
-
- result.push(createBMPCharacterClasses(bmp));
- }
- if (surrogateMappings.length) {
-
-
- result.push(createSurrogateCharacterClasses(surrogateMappings));
- }
-
- if (hasLoneHighSurrogates) {
- result.push(
- createBMPCharacterClasses(loneHighSurrogates) +
-
- '(?![\\uDC00-\\uDFFF])'
- );
- }
- if (hasLoneLowSurrogates) {
- result.push(
-
-
-
- '(?:[^\\uD800-\\uDBFF]|^)' +
- createBMPCharacterClasses(loneLowSurrogates)
- );
- }
- return result.join('|');
- };
-
-
-
-
- var regenerate = function(value) {
- if (arguments.length > 1) {
- value = slice.call(arguments);
- }
- if (this instanceof regenerate) {
- this.data = [];
- return value ? this.add(value) : this;
- }
- return (new regenerate).add(value);
- };
- regenerate.version = '1.4.2';
- var proto = regenerate.prototype;
- extend(proto, {
- 'add': function(value) {
- var $this = this;
- if (value == null) {
- return $this;
- }
- if (value instanceof regenerate) {
-
- $this.data = dataAddData($this.data, value.data);
- return $this;
- }
- if (arguments.length > 1) {
- value = slice.call(arguments);
- }
- if (isArray(value)) {
- forEach(value, function(item) {
- $this.add(item);
- });
- return $this;
- }
- $this.data = dataAdd(
- $this.data,
- isNumber(value) ? value : symbolToCodePoint(value)
- );
- return $this;
- },
- 'remove': function(value) {
- var $this = this;
- if (value == null) {
- return $this;
- }
- if (value instanceof regenerate) {
-
- $this.data = dataRemoveData($this.data, value.data);
- return $this;
- }
- if (arguments.length > 1) {
- value = slice.call(arguments);
- }
- if (isArray(value)) {
- forEach(value, function(item) {
- $this.remove(item);
- });
- return $this;
- }
- $this.data = dataRemove(
- $this.data,
- isNumber(value) ? value : symbolToCodePoint(value)
- );
- return $this;
- },
- 'addRange': function(start, end) {
- var $this = this;
- $this.data = dataAddRange($this.data,
- isNumber(start) ? start : symbolToCodePoint(start),
- isNumber(end) ? end : symbolToCodePoint(end)
- );
- return $this;
- },
- 'removeRange': function(start, end) {
- var $this = this;
- var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start);
- var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end);
- $this.data = dataRemoveRange(
- $this.data,
- startCodePoint,
- endCodePoint
- );
- return $this;
- },
- 'intersection': function(argument) {
- var $this = this;
-
-
- var array = argument instanceof regenerate ?
- dataToArray(argument.data) :
- argument;
- $this.data = dataIntersection($this.data, array);
- return $this;
- },
- 'contains': function(codePoint) {
- return dataContains(
- this.data,
- isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint)
- );
- },
- 'clone': function() {
- var set = new regenerate;
- set.data = this.data.slice(0);
- return set;
- },
- 'toString': function(options) {
- var result = createCharacterClassesFromData(
- this.data,
- options ? options.bmpOnly : false,
- options ? options.hasUnicodeFlag : false
- );
- if (!result) {
-
-
-
- return '[]';
- }
-
- return result.replace(regexNull, '\\0$1');
- },
- 'toRegExp': function(flags) {
- var pattern = this.toString(
- flags && flags.indexOf('u') != -1 ?
- { 'hasUnicodeFlag': true } :
- null
- );
- return RegExp(pattern, flags || '');
- },
- 'valueOf': function() {
- return dataToArray(this.data);
- }
- });
- proto.toArray = proto.valueOf;
-
-
- if (
- typeof define == 'function' &&
- typeof define.amd == 'object' &&
- define.amd
- ) {
- define(function() {
- return regenerate;
- });
- } else if (freeExports && !freeExports.nodeType) {
- if (freeModule) {
- freeModule.exports = regenerate;
- } else {
- freeExports.regenerate = regenerate;
- }
- } else {
- root.regenerate = regenerate;
- }
- }(this));
|