* Parse the provided css text and inside strings (meaning, inside pairs of unescaped single or * double quotes) replace specific characters with their respective placeholders as indicated * by the `ESCAPE_IN_STRING_MAP` map. * * For example convert the text * `animation: "my-anim:at\"ion" 1s;`
(input: string)
| 1146 | * @returns the css text with specific characters in strings replaced by placeholders. |
| 1147 | **/ |
| 1148 | function escapeInStrings(input: string): string { |
| 1149 | let result = input; |
| 1150 | let currentQuoteChar: string | null = null; |
| 1151 | for (let i = 0; i < result.length; i++) { |
| 1152 | const char = result[i]; |
| 1153 | if (char === '\\') { |
| 1154 | i++; |
| 1155 | } else { |
| 1156 | if (currentQuoteChar !== null) { |
| 1157 | // index i is inside a quoted sub-string |
| 1158 | if (char === currentQuoteChar) { |
| 1159 | currentQuoteChar = null; |
| 1160 | } else { |
| 1161 | const placeholder: string | undefined = ESCAPE_IN_STRING_MAP[char]; |
| 1162 | if (placeholder) { |
| 1163 | result = `${result.substr(0, i)}${placeholder}${result.substr(i + 1)}`; |
| 1164 | i += placeholder.length - 1; |
| 1165 | } |
| 1166 | } |
| 1167 | } else if (char === "'" || char === '"') { |
| 1168 | currentQuoteChar = char; |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | return result; |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Replace in a string all occurrences of keys in the `ESCAPE_IN_STRING_MAP` map with their |
no outgoing calls
no test coverage detected
searching dependent graphs…