|
39 | 39 | if ( rule[0] == '"' ) { |
40 | 40 | const match_arr = rule.trim().replaceAll('"', "").split("=") |
41 | 41 | 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]); |
43 | 44 | } |
44 | 45 | } 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 | + } |
48 | 55 | } |
49 | 56 | } |
50 | 57 | } |
|
66 | 73 | } |
67 | 74 | } |
68 | 75 | } |
69 | | - |
70 | 76 |
|
71 | 77 | const pointsList = fix_text.split('\n').filter(Boolean); |
72 | 78 | return pointsList; |
73 | 79 | } |
74 | 80 |
|
| 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 | + |
75 | 89 | containsPronounceableChars(str) { |
76 | 90 | return /[\p{L}\p{N}]/u.test(str); |
77 | 91 | } |
|
0 commit comments