MCPcopy Create free account
hub / github.com/Wscats/vscode-explore / _deserializeRegexValue

Function _deserializeRegexValue

contextKeyExpr/src/contextkey.ts:204–238  ·  view source on GitHub ↗
(serializedValue: string, strict: boolean)

Source from the content-addressed store, hash-verified

202 }
203
204 private static _deserializeRegexValue(serializedValue: string, strict: boolean): RegExp | null {
205
206 if (isFalsyOrWhitespace(serializedValue)) {
207 if (strict) {
208 throw new Error('missing regexp-value for =~-expression');
209 } else {
210 console.warn('missing regexp-value for =~-expression');
211 }
212 return null;
213 }
214
215 let start = serializedValue.indexOf('/');
216 let end = serializedValue.lastIndexOf('/');
217 if (start === end || start < 0 /* || to < 0 */) {
218 if (strict) {
219 throw new Error(`bad regexp-value '${serializedValue}', missing /-enclosure`);
220 } else {
221 console.warn(`bad regexp-value '${serializedValue}', missing /-enclosure`);
222 }
223 return null;
224 }
225
226 let value = serializedValue.slice(start + 1, end);
227 let caseIgnoreFlag = serializedValue[end + 1] === 'i' ? 'i' : '';
228 try {
229 return new RegExp(value, caseIgnoreFlag);
230 } catch (e) {
231 if (strict) {
232 throw new Error(`bad regexp-value '${serializedValue}', parse error: ${e}`);
233 } else {
234 console.warn(`bad regexp-value '${serializedValue}', parse error: ${e}`);
235 }
236 return null;
237 }
238 }
239}
240
241function cmp(a: ContextKeyExpression, b: ContextKeyExpression): number {

Callers

nothing calls this directly

Calls 3

warnMethod · 0.80
sliceMethod · 0.80
isFalsyOrWhitespaceFunction · 0.70

Tested by

no test coverage detected