-6 loops overall by only incrementing loop count when regex/str.replace is being called
This commit is contained in:
parent
c58ebcc9f9
commit
2cfa923093
|
@ -11,13 +11,15 @@ import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
export const escapeCharacters = (str: string, esc: string): string => {
|
export const escapeCharacters = (str: string, esc: string): string => {
|
||||||
// Loop thru each esc char one at a time
|
// Loop thru each esc char one at a time
|
||||||
for (const e of esc) {
|
for (const e of esc) {
|
||||||
|
loggingEnabled && log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
|
||||||
|
if (str.includes(e)) {
|
||||||
loopCountCheck(`escape.ts - escaping character ${e}`);
|
loopCountCheck(`escape.ts - escaping character ${e}`);
|
||||||
|
|
||||||
loggingEnabled && log(LT.LOG, `Escaping character ${e} | ${str}, ${esc}`);
|
|
||||||
// Create a new regex to look for that char that needs replaced and escape it
|
// Create a new regex to look for that char that needs replaced and escape it
|
||||||
const tempRgx = new RegExp(`[${e}]`, 'g');
|
const tempRgx = new RegExp(`[${e}]`, 'g');
|
||||||
str = str.replace(tempRgx, `\\${e}`);
|
str = str.replace(tempRgx, `\\${e}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue