mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-02 13:47:42 +00:00
refactor(common/lmlayer): extract function: spansAreBackToBack
This commit is contained in:
parent
73591cb977
commit
acf7aab588
1 changed files with 11 additions and 2 deletions
|
|
@ -46,12 +46,13 @@ namespace wordBreakers {
|
|||
let current: Span | undefined = results[index];
|
||||
|
||||
let window = [];
|
||||
if (previous && previous.end === current.start) {
|
||||
if (previous && spansAreBackToBack(previous, current)) {
|
||||
window.push(index - 1);
|
||||
}
|
||||
|
||||
window.push(index);
|
||||
|
||||
if (next && current.end === next.start) {
|
||||
if (next && spansAreBackToBack(current, next)) {
|
||||
window.push(index + 1);
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +93,14 @@ namespace wordBreakers {
|
|||
return contiguousRanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the spans are contiguous.
|
||||
* Order matters when calling this function!
|
||||
*/
|
||||
function spansAreBackToBack(former: Span, latter: Span): boolean {
|
||||
return former.end === latter.start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of ranges of indices, and the corresponding spans,
|
||||
* concatenates spans according to the ranges of indices.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue