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

Function escapeBlocks

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

Source from the content-addressed store, hash-verified

1101}
1102
1103function escapeBlocks(
1104 input: string,
1105 charPairs: Map<string, string>,
1106 placeholder: string,
1107): StringWithEscapedBlocks {
1108 const resultParts: string[] = [];
1109 const escapedBlocks: string[] = [];
1110 let openCharCount = 0;
1111 let nonBlockStartIndex = 0;
1112 let blockStartIndex = -1;
1113 let openChar: string | undefined;
1114 let closeChar: string | undefined;
1115
1116 for (let i = 0; i < input.length; i++) {
1117 const char = input[i];
1118 if (char === '\\') {
1119 i++;
1120 } else if (char === closeChar) {
1121 openCharCount--;
1122 if (openCharCount === 0) {
1123 escapedBlocks.push(input.substring(blockStartIndex, i));
1124 resultParts.push(placeholder);
1125 nonBlockStartIndex = i;
1126 blockStartIndex = -1;
1127 openChar = closeChar = undefined;
1128 }
1129 } else if (char === openChar) {
1130 openCharCount++;
1131 } else if (openCharCount === 0 && charPairs.has(char)) {
1132 openChar = char;
1133 closeChar = charPairs.get(char);
1134 openCharCount = 1;
1135 blockStartIndex = i + 1;
1136 resultParts.push(input.substring(nonBlockStartIndex, blockStartIndex));
1137 }
1138 }
1139
1140 if (blockStartIndex !== -1) {
1141 escapedBlocks.push(input.substring(blockStartIndex));
1142 resultParts.push(placeholder);
1143 } else {
1144 resultParts.push(input.substring(nonBlockStartIndex));
1145 }
1146
1147 return new StringWithEscapedBlocks(resultParts.join(''), escapedBlocks);
1148}
1149
1150/**
1151 * 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