StringRange

Helpers to facilitate string range usage with a RangeGroup. A string range defines a range of strings, where each unicode codepoint can be changed individually. For example, the range ["ab", "cd"] encompasses the strings: ab ac ad bb bc bd cb cc cd. You can check out the concept of a string range as described in the unicode specification

String ranges are actually multidimensional, where each character index is another dimension. RangeGroup cannot work with multidimensional ranges directly. However, we can still use string ranges if we enumerate the range values in all but the last dimension. This unrolls the range into many one dimensional ones. The example above would then become: ["ab","ad"] ["bb","bd"] ["cb","cd"].

While for some cases this won't be acceptable, I believe it accomodates a majority of use cases for string ranges. For example, a common case that will still work is encoding a range of unicode grapheme clusters; e.g. emojis, like ["👦🏻", "👦🏿"].

The StringRange.toRanges1d method performs the transformation. You can use the StringRange.size to check the number of strings or 1d ranges a string range has.

For the 1d string ranges that are output, both UnicodeType and UnicodeNormType are available for use as the RangeGroup#type.

Methods

(static) size(range, stringsopt) → {number}

Calculate the number of strings encompassed by the string range, or the number of 1d ranges that would be generated by StringRange.toRanges1d

Parameters:
NameTypeAttributesDefaultDescription
rangeRange

a string range

stringsboolean<optional>
false

if true, outputs the number of strings in the range; if false, the number of 1d ranges that would be generated by StringRange.toRanges1d

Returns:
Type: 
number

(generator, static) toRanges1d(range) → {Range}

Converts string ranges into a set of Range objects that will work with RangeGroup. The Range#start and Range#end must have equal length (see UnicodeHelpers.length). Additionally, all the codepoints of Range#start must be less than or equal the codepoints of Range#end. Exclusive range bounds apply to the first and last generated strings, not individual characters.

Parameters:
NameTypeDescription
rangeRange

a string range

Yields:

enumerated 1d ranges

Type: 
Range