instance method SpahQL.Token.Set#evalStringRange
SpahQL.Token.Set#evalStringRange(start, end) → Array of QueryResults
-
start
(String
) – The character at the start of the range (”a” is the start value for {’a’..’c’}) -
end
(String
) – The character at the end of the range (”c” is the end value for {’a’..’c’})
Evaluates a string range literal, generating an array of QueryResults containing all values in the range. String range literals are evaluated as numeric ranges using a radix of 35, and transposing the generated numeric values back into strings before returning them.
Evaluates with a ruby-style behaviour, for instance: “a”..”c” -> a, b, c “ab”..”ad” -> ab, ac, ad “a1”..”b2” -> a1, a2…… a8, a9, b1, b2 “1b”..”2b” -> 1b, 1c, 1d…… 1x, 1y, 1z, 2a, 2b
So: Each digit is cycled based on a its type, and at the culmination of each digit’s cycle the next highest-order digit is iterated. The types of digit are number, lowercase char and uppercase char.
If the digits cannot be cycled to a match, as in the example “1a”..”b1” where the digits are of differing types, the initial value is iterated to its peak and will terminate at that point. The generated range is equivalent in this case to “1a”..”9z”.
If the values appear to be reversed (e.g. “z”..”a”, “9a”..”3a”, “D1”..”A1”) then in ruby style the range will evaluate as empty.
We do this by defining three character code ranges for certain character types - integers(48-57), lower case characters (97-122) and uppercase characters (65-90). If any two characters belong to the same range then they are mutually iterable.
There is a special case for single-character ranges where if the initial value sits outside of these ranges, it is iterated towards the destination value until it reaches the destination value or until it reaches the end of one of the predefined ranges above. For instance, ”}”..”~” will iterate successfully, but “x”..”}” despite being an increasing range in raw character code terms will only evaluate to “x”,”y”,”z”. In the case of a range like ”)”..”a” (character code 41 to 97) the iterator will enter the numeric character range (48-57) and in doing so will terminate at char code 57, character “9”.
In ranges with multiple digits, characters outside the three defined ranges are locked and do not iterate.