-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10028 from Snuffleupagus/entireWord
Add initial support for "Whole words" searching in the viewer
- Loading branch information
Showing
13 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Copyright 2018 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { CharacterType, getCharacterType } from '../../web/pdf_find_utils'; | ||
|
||
describe('pdf_find_utils', function() { | ||
describe('getCharacterType', function() { | ||
it('gets expected character types', function() { | ||
const characters = { | ||
'A': CharacterType.ALPHA_LETTER, | ||
'a': CharacterType.ALPHA_LETTER, | ||
'0': CharacterType.ALPHA_LETTER, | ||
'5': CharacterType.ALPHA_LETTER, | ||
'\xC4': CharacterType.ALPHA_LETTER, // 'Ä' | ||
'\xE4': CharacterType.ALPHA_LETTER, // 'ä' | ||
'_': CharacterType.ALPHA_LETTER, | ||
' ': CharacterType.SPACE, | ||
'\t': CharacterType.SPACE, | ||
'\r': CharacterType.SPACE, | ||
'\n': CharacterType.SPACE, | ||
'\xA0': CharacterType.SPACE, | ||
'-': CharacterType.PUNCT, | ||
',': CharacterType.PUNCT, | ||
'.': CharacterType.PUNCT, | ||
';': CharacterType.PUNCT, | ||
':': CharacterType.PUNCT, | ||
'\u2122': CharacterType.ALPHA_LETTER, // trademark | ||
'\u0E25': CharacterType.THAI_LETTER, | ||
'\u4000': CharacterType.HAN_LETTER, | ||
'\uF950': CharacterType.HAN_LETTER, | ||
'\u30C0': CharacterType.KATAKANA_LETTER, | ||
'\u3050': CharacterType.HIRAGANA_LETTER, | ||
'\uFF80': CharacterType.HALFWIDTH_KATAKANA_LETTER, | ||
}; | ||
|
||
for (const character in characters) { | ||
const charCode = character.charCodeAt(0); | ||
const type = characters[character]; | ||
|
||
expect(getCharacterType(charCode)).toEqual(type); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* Copyright 2018 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const CharacterType = { | ||
SPACE: 0, | ||
ALPHA_LETTER: 1, | ||
PUNCT: 2, | ||
HAN_LETTER: 3, | ||
KATAKANA_LETTER: 4, | ||
HIRAGANA_LETTER: 5, | ||
HALFWIDTH_KATAKANA_LETTER: 6, | ||
THAI_LETTER: 7, | ||
}; | ||
|
||
function isAlphabeticalScript(charCode) { | ||
return charCode < 0x2E80; | ||
} | ||
|
||
function isAscii(charCode) { | ||
return (charCode & 0xFF80) === 0; | ||
} | ||
|
||
function isAsciiAlpha(charCode) { | ||
return (charCode >= /* a = */ 0x61 && charCode <= /* z = */ 0x7A) || | ||
(charCode >= /* A = */ 0x41 && charCode <= /* Z = */ 0x5A); | ||
} | ||
|
||
function isAsciiDigit(charCode) { | ||
return (charCode >= /* 0 = */ 0x30 && charCode <= /* 9 = */ 0x39); | ||
} | ||
|
||
function isAsciiSpace(charCode) { | ||
return (charCode === /* SPACE = */ 0x20 || charCode === /* TAB = */ 0x09 || | ||
charCode === /* CR = */ 0x0D || charCode === /* LF = */ 0x0A); | ||
} | ||
|
||
function isHan(charCode) { | ||
return (charCode >= 0x3400 && charCode <= 0x9FFF) || | ||
(charCode >= 0xF900 && charCode <= 0xFAFF); | ||
} | ||
|
||
function isKatakana(charCode) { | ||
return (charCode >= 0x30A0 && charCode <= 0x30FF); | ||
} | ||
|
||
function isHiragana(charCode) { | ||
return (charCode >= 0x3040 && charCode <= 0x309F); | ||
} | ||
|
||
function isHalfwidthKatakana(charCode) { | ||
return (charCode >= 0xFF60 && charCode <= 0xFF9F); | ||
} | ||
|
||
function isThai(charCode) { | ||
return (charCode & 0xFF80) === 0x0E00; | ||
} | ||
|
||
/** | ||
* This function is based on the word-break detection implemented in: | ||
* https://hg.mozilla.org/mozilla-central/file/tip/intl/lwbrk/WordBreaker.cpp | ||
*/ | ||
function getCharacterType(charCode) { | ||
if (isAlphabeticalScript(charCode)) { | ||
if (isAscii(charCode)) { | ||
if (isAsciiSpace(charCode)) { | ||
return CharacterType.SPACE; | ||
} else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || | ||
charCode === /* UNDERSCORE = */ 0x5F) { | ||
return CharacterType.ALPHA_LETTER; | ||
} | ||
return CharacterType.PUNCT; | ||
} else if (isThai(charCode)) { | ||
return CharacterType.THAI_LETTER; | ||
} else if (charCode === /* NBSP = */ 0xA0) { | ||
return CharacterType.SPACE; | ||
} | ||
return CharacterType.ALPHA_LETTER; | ||
} | ||
|
||
if (isHan(charCode)) { | ||
return CharacterType.HAN_LETTER; | ||
} else if (isKatakana(charCode)) { | ||
return CharacterType.KATAKANA_LETTER; | ||
} else if (isHiragana(charCode)) { | ||
return CharacterType.HIRAGANA_LETTER; | ||
} else if (isHalfwidthKatakana(charCode)) { | ||
return CharacterType.HALFWIDTH_KATAKANA_LETTER; | ||
} | ||
return CharacterType.ALPHA_LETTER; | ||
} | ||
|
||
export { | ||
CharacterType, | ||
getCharacterType, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.