MCPcopy
hub / github.com/angular/angular / escapeBlocks

Function escapeBlocks

packages/compiler/src/shadow_css.ts:1070–1115  ·  view source on GitHub ↗
(
  input: string,
  charPairs: Map<string, string>,
  placeholder: string,
)

Source from the content-addressed store, hash-verified

1068}
1069
1070function escapeBlocks(
1071 input: string,
1072 charPairs: Map<string, string>,
1073 placeholder: string,
1074): StringWithEscapedBlocks {
1075 const resultParts: string[] = [];
1076 const escapedBlocks: string[] = [];
1077 let openCharCount = 0;
1078 let nonBlockStartIndex = 0;
1079 let blockStartIndex = -1;
1080 let openChar: string | undefined;
1081 let closeChar: string | undefined;
1082
1083 for (let i = 0; i < input.length; i++) {
1084 const char = input[i];
1085 if (char === '\\') {
1086 i++;
1087 } else if (char === closeChar) {
1088 openCharCount--;
1089 if (openCharCount === 0) {
1090 escapedBlocks.push(input.substring(blockStartIndex, i));
1091 resultParts.push(placeholder);
1092 nonBlockStartIndex = i;
1093 blockStartIndex = -1;
1094 openChar = closeChar = undefined;
1095 }
1096 } else if (char === openChar) {
1097 openCharCount++;
1098 } else if (openCharCount === 0 && charPairs.has(char)) {
1099 openChar = char;
1100 closeChar = charPairs.get(char);
1101 openCharCount = 1;
1102 blockStartIndex = i + 1;
1103 resultParts.push(input.substring(nonBlockStartIndex, blockStartIndex));
1104 }
1105 }
1106
1107 if (blockStartIndex !== -1) {
1108 escapedBlocks.push(input.substring(blockStartIndex));
1109 resultParts.push(placeholder);
1110 } else {
1111 resultParts.push(input.substring(nonBlockStartIndex));
1112 }
1113
1114 return new StringWithEscapedBlocks(resultParts.join(''), escapedBlocks);
1115}
1116
1117/**
1118 * Object containing as keys characters that should be substituted by placeholders

Callers 1

processRulesFunction · 0.85

Calls 4

hasMethod · 0.65
getMethod · 0.65
joinMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…