File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,21 @@ export class StringSet {
349349 }
350350 return new StringSet ( items , this . _caseFolding ) ;
351351 }
352+
353+ /**
354+ * Returns the minimum and maximum length of words in this set.
355+ *
356+ * If this set is empty, `undefined` will be returned returned.
357+ */
358+ getLengthRange ( ) : { min : number ; max : number } | undefined {
359+ if ( this . isEmpty ) {
360+ return undefined ;
361+ }
362+
363+ const min = this . words [ 0 ] . length ;
364+ const max = this . words [ this . words . length - 1 ] . length ;
365+ return { min, max } ;
366+ }
352367}
353368
354369function normalize ( items : ReadonlyWord [ ] ) : void {
Original file line number Diff line number Diff line change @@ -191,6 +191,27 @@ export class UnicodeSet {
191191 return this . chars . isDisjointWith ( other ) ;
192192 }
193193 }
194+
195+ /**
196+ * Returns the minimum and maximum length of words in this set.
197+ *
198+ * If this set is empty, `undefined` will be returned returned.
199+ */
200+ getLengthRange ( ) : { min : number ; max : number } | undefined {
201+ if ( this . chars . isEmpty ) {
202+ return this . accept . getLengthRange ( ) ;
203+ } else {
204+ const wordRange = this . accept . getLengthRange ( ) ;
205+ if ( wordRange === undefined ) {
206+ return { min : 1 , max : 1 } ;
207+ } else {
208+ return {
209+ min : Math . min ( 1 , wordRange . min ) ,
210+ max : Math . max ( 1 , wordRange . max ) ,
211+ } ;
212+ }
213+ }
214+ }
194215}
195216
196217function toWordSets ( set : UnicodeSet ) : readonly ReadonlyWordSet [ ] {
You can’t perform that action at this time.
0 commit comments