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

Function escapeInStrings

packages/compiler/src/shadow_css.ts:1180–1205  ·  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

1178 * @returns the css text with specific characters in strings replaced by placeholders.
1179 **/
1180function escapeInStrings(input: string): string {
1181 let result = input;
1182 let currentQuoteChar: string | null = null;
1183 for (let i = 0; i < result.length; i++) {
1184 const char = result[i];
1185 if (char === '\\') {
1186 i++;
1187 } else {
1188 if (currentQuoteChar !== null) {
1189 // index i is inside a quoted sub-string
1190 if (char === currentQuoteChar) {
1191 currentQuoteChar = null;
1192 } else {
1193 const placeholder: string | undefined = ESCAPE_IN_STRING_MAP[char];
1194 if (placeholder) {
1195 result = `${result.substr(0, i)}${placeholder}${result.substr(i + 1)}`;
1196 i += placeholder.length - 1;
1197 }
1198 }
1199 } else if (char === "'" || char === '"') {
1200 currentQuoteChar = char;
1201 }
1202 }
1203 }
1204 return result;
1205}
1206
1207/**
1208 * 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