Skip to content

Commit 2c58966

Browse files
committed
up
1 parent acc1d3a commit 2c58966

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

assets/processing_file.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@
3939
if ( rule[0] == '"' ) {
4040
const match_arr = rule.trim().replaceAll('"', "").split("=")
4141
if ( match_arr.length == 2 ) {
42-
fix_text = fix_text.replaceAll(match_arr[0].toString(), match_arr[1].toString())
42+
const regex = new RegExp(this.get_escaped(match_arr[0]), 'giu');
43+
fix_text = fix_text.replace(regex, match_arr[1]);
4344
}
4445
} else {
45-
const match_arr = rule.trim().split("=")
46-
const regex = new RegExp('(^|\\s|\\p{P})' + match_arr[0].toString() + '(?=\\p{P}|\\s|$)', 'giu');
47-
fix_text = fix_text.replace(regex, '$1'+match_arr[1].toString())
46+
const match_arr = rule.trim().split("=");
47+
const escaped = this.get_escaped(match_arr[0]);
48+
if (this.is_punctuation(match_arr[0]) == true) {
49+
const regex = new RegExp(escaped, 'giu');
50+
fix_text = fix_text.replace(regex, match_arr[1]);
51+
} else {
52+
const regex = new RegExp('(^|\\s|\\p{P})' + escaped + '(?=\\p{P}|\\s|$)', 'giu');
53+
fix_text = fix_text.replace(regex, '$1' + match_arr[1]);
54+
}
4855
}
4956
}
5057
}
@@ -66,12 +73,19 @@
6673
}
6774
}
6875
}
69-
7076

7177
const pointsList = fix_text.split('\n').filter(Boolean);
7278
return pointsList;
7379
}
7480

81+
is_punctuation(str) {
82+
return str.length === 1 && /\p{P}/u.test(str);
83+
}
84+
85+
get_escaped(str) {
86+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
87+
}
88+
7589
containsPronounceableChars(str) {
7690
return /[\p{L}\p{N}]/u.test(str);
7791
}

0 commit comments

Comments
 (0)