function isString (str, index) { if (str[index] === '"' || str[index] === "'") { var indexMatchingQuote = str.indexOf(str[index], index + 1); var matchingQuote = str[index]; if (indexMatchingQuote === -1) { return []; } tempTokens = []; var it = index + 1; tempTokens.push({ tokenName: str[index], tokenColor: stringColor }); while (str[it] !== matchingQuote && it < str.length) { var escapeAdded = false; for (var charIdx = 0; charIdx < escapeCharacters.length; charIdx++) { if (str.substr(it, escapeCharacters[charIdx].length) === escapeCharacters[charIdx]) { escapeAdded = true; tempTokens.push({ tokenName: escapeCharacters[charIdx], tokenColor: escapeCharacterColor }); it += escapeCharacters[charIdx].length; break; } } if (!escapeAdded) { tempTokens.push({ tokenName: str[it], tokenColor: stringColor }); it += 1; } } tempTokens.push({ tokenName: str[index], tokenColor: stringColor }); return tempTokens; // if (indexMatchingQuote !== -1) { // return str.substring(index, indexMatchingQuote + 1); // } } return []; }