Skip to content

Commit

Permalink
feat: Add "smart" quote matching [PT-188319600]
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmartin committed Oct 1, 2024
1 parent d426a53 commit 79018df
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/stores/target_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,27 @@ export class TargetStore {
// note: the multiple slash escaping is due to all the layers between this code and the CODAP formula evaluator
const escapedText = text
.replace(/[.*+?^${}()|[\]\\]/g, '\\\\\\\\$&') // escape regex modifiers
.replace(/\s+/g, '\\\\\\\\s+'); // allow multiple spaces between words
.replace(/\s+/g, '\\\\\\\\s+') // allow multiple spaces between words
.replace(/['"“”‘’]/g, (match) => { // allow both regular and smart quotes to match each other
switch (match) {
case '"':
case '“':
case '”':
return `["“”]`;
case "'":
case '‘':
case '’':
return `['‘’]`;
default:
return match;
}
});
// don't add word boundaries when the user input starts/ends with non-word characters, like ! or , as that would fail matching
const wordBoundary = `\\\\\\\\b`;
const maybeStartingWordBoundary = /^\w/.test(text) ? wordBoundary : '';
const maybeEndingWordBoundary = /\w$/.test(text) ? wordBoundary : '';
const tParamString = `${tTargetAttr},"${tBegins}${maybeStartingWordBoundary}${escapedText}${maybeEndingWordBoundary}${tEnds}"`;
console.log("tParamString", tParamString);
let tResult = '';
switch (option) {//['contain', 'not contain', 'start with', 'end with']
case featureDescriptors.containsOptions[0]: // contain
Expand Down

0 comments on commit 79018df

Please sign in to comment.