Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/js/string-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ export class StringSet {
}
return new StringSet(items, this._caseFolding);
}

/**
* Returns the minimum and maximum length of words in this set.
*
* If this set is empty, `undefined` will be returned returned.
*/
getLengthRange(): { min: number; max: number } | undefined {
if (this.isEmpty) {
return undefined;
}

const min = this.words[0].length;
const max = this.words[this.words.length - 1].length;
return { min, max };
}
}

function normalize(items: ReadonlyWord[]): void {
Expand Down
21 changes: 21 additions & 0 deletions src/js/unicode-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ export class UnicodeSet {
return this.chars.isDisjointWith(other);
}
}

/**
* Returns the minimum and maximum length of words in this set.
*
* If this set is empty, `undefined` will be returned returned.
*/
getLengthRange(): { min: number; max: number } | undefined {
if (this.chars.isEmpty) {
return this.accept.getLengthRange();
} else {
const wordRange = this.accept.getLengthRange();
if (wordRange === undefined) {
return { min: 1, max: 1 };
} else {
return {
min: Math.min(1, wordRange.min),
max: Math.max(1, wordRange.max),
};
}
}
}
}

function toWordSets(set: UnicodeSet): readonly ReadonlyWordSet[] {
Expand Down