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

Function escapeBlocks

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

Source from the content-addressed store, hash-verified

1124}
1125
1126function escapeBlocks(
1127 input: string,
1128 charPairs: Map<string, string>,
1129 placeholder: string,
1130): StringWithEscapedBlocks {
1131 const resultParts: string[] = [];
1132 const escapedBlocks: string[] = [];
1133 let openCharCount = 0;
1134 let nonBlockStartIndex = 0;
1135 let blockStartIndex = -1;
1136 let openChar: string | undefined;
1137 let closeChar: string | undefined;
1138
1139 for (let i = 0; i < input.length; i++) {
1140 const char = input[i];
1141 if (char === '\\') {
1142 i++;
1143 } else if (char === closeChar) {
1144 openCharCount--;
1145 if (openCharCount === 0) {
1146 escapedBlocks.push(input.substring(blockStartIndex, i));
1147 resultParts.push(placeholder);
1148 nonBlockStartIndex = i;
1149 blockStartIndex = -1;
1150 openChar = closeChar = undefined;
1151 }
1152 } else if (char === openChar) {
1153 openCharCount++;
1154 } else if (openCharCount === 0 && charPairs.has(char)) {
1155 openChar = char;
1156 closeChar = charPairs.get(char);
1157 openCharCount = 1;
1158 blockStartIndex = i + 1;
1159 resultParts.push(input.substring(nonBlockStartIndex, blockStartIndex));
1160 }
1161 }
1162
1163 if (blockStartIndex !== -1) {
1164 escapedBlocks.push(input.substring(blockStartIndex));
1165 resultParts.push(placeholder);
1166 } else {
1167 resultParts.push(input.substring(nonBlockStartIndex));
1168 }
1169
1170 return new StringWithEscapedBlocks(resultParts.join(''), escapedBlocks);
1171}
1172
1173/**
1174 * 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