|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
978 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | // \n = 10
|
|---|
| 9 | // ; = 59
|
|---|
| 10 | // { = 123
|
|---|
| 11 | // } = 125
|
|---|
| 12 | // <space> = 32
|
|---|
| 13 | // \r = 13
|
|---|
| 14 | // \t = 9
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * @param {string} str string
|
|---|
| 18 | * @returns {string[] | null} array of string separated by potential tokens
|
|---|
| 19 | */
|
|---|
| 20 | const splitIntoPotentialTokens = (str) => {
|
|---|
| 21 | const len = str.length;
|
|---|
| 22 | if (len === 0) return null;
|
|---|
| 23 | const results = [];
|
|---|
| 24 | let i = 0;
|
|---|
| 25 | while (i < len) {
|
|---|
| 26 | const start = i;
|
|---|
| 27 | block: {
|
|---|
| 28 | let cc = str.charCodeAt(i);
|
|---|
| 29 | while (cc !== 10 && cc !== 59 && cc !== 123 && cc !== 125) {
|
|---|
| 30 | if (++i >= len) break block;
|
|---|
| 31 | cc = str.charCodeAt(i);
|
|---|
| 32 | }
|
|---|
| 33 | while (
|
|---|
| 34 | cc === 59 ||
|
|---|
| 35 | cc === 32 ||
|
|---|
| 36 | cc === 123 ||
|
|---|
| 37 | cc === 125 ||
|
|---|
| 38 | cc === 13 ||
|
|---|
| 39 | cc === 9
|
|---|
| 40 | ) {
|
|---|
| 41 | if (++i >= len) break block;
|
|---|
| 42 | cc = str.charCodeAt(i);
|
|---|
| 43 | }
|
|---|
| 44 | if (cc === 10) {
|
|---|
| 45 | i++;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | results.push(str.slice(start, i));
|
|---|
| 49 | }
|
|---|
| 50 | return results;
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | module.exports = splitIntoPotentialTokens;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.