MCPcopy
hub / github.com/angular/angular / escapeInStrings

Function escapeInStrings

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

1146 * @returns the css text with specific characters in strings replaced by placeholders.
1147 **/
1148function 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

Callers 1

processRulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…