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

Function escapeBlocks

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

Source from the content-addressed store, hash-verified

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