Skip to content

Commit

Permalink
Merge pull request #15698 from Snuffleupagus/DIACRITICS_EXCEPTION_STR…
Browse files Browse the repository at this point in the history
…-lazy

Initialize the find-related `DIACRITICS_EXCEPTION_STR` constant lazily
  • Loading branch information
Snuffleupagus authored Nov 15, 2022
2 parents 859335a + 176e8f0 commit e089d07
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions web/pdf_find_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ const DIACRITICS_EXCEPTION = new Set([
// https://www.compart.com/fr/unicode/combining/132
0x0f74,
]);
const DIACRITICS_EXCEPTION_STR = [...DIACRITICS_EXCEPTION.values()]
.map(x => String.fromCharCode(x))
.join("");
let DIACRITICS_EXCEPTION_STR; // Lazily initialized, see below.

const DIACRITICS_REG_EXP = /\p{M}+/gu;
const SPECIAL_CHARS_REG_EXP =
Expand Down Expand Up @@ -675,6 +673,10 @@ class PDFFindController {
if (matchDiacritics) {
// aX must not match aXY.
if (hasDiacritics) {
DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(
...DIACRITICS_EXCEPTION
);

isUnicode = true;
query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
}
Expand Down

0 comments on commit e089d07

Please sign in to comment.