MCPcopy Create free account
hub / github.com/angular/angular / escapeInStrings

Function escapeInStrings

packages/compiler/src/shadow_css.ts:1206–1231  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1204 * @returns the css text with specific characters in strings replaced by placeholders.
1205 **/
1206function escapeInStrings(input: string): string {
1207 let result = input;
1208 let currentQuoteChar: string | null = null;
1209 for (let i = 0; i < result.length; i++) {
1210 const char = result[i];
1211 if (char === '\\') {
1212 i++;
1213 } else {
1214 if (currentQuoteChar !== null) {
1215 // index i is inside a quoted sub-string
1216 if (char === currentQuoteChar) {
1217 currentQuoteChar = null;
1218 } else {
1219 const placeholder: string | undefined = ESCAPE_IN_STRING_MAP[char];
1220 if (placeholder) {
1221 result = `${result.substr(0, i)}${placeholder}${result.substr(i + 1)}`;
1222 i += placeholder.length - 1;
1223 }
1224 }
1225 } else if (char === "'" || char === '"') {
1226 currentQuoteChar = char;
1227 }
1228 }
1229 }
1230 return result;
1231}
1232
1233/**
1234 * Replace in a string all occurrences of keys in the `ESCAPE_IN_STRING_MAP` map with their

Callers 1

processRulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected