27 lines
900 B
Plaintext
27 lines
900 B
Plaintext
CFStringRef local fn ExpandRanges( string as CFStringRef )
|
|
CFArrayRef ranges = fn StringComponentsSeparatedByString( string, @"," )
|
|
CFStringRef expanded = @""
|
|
for CFStringRef s in ranges
|
|
ScannerRef scanner = fn ScannerWithString( s )
|
|
long first, last
|
|
if ( fn ScannerScanInteger( scanner, @first ) )
|
|
if ( len(expanded) ) then expanded = concat(expanded,@", ")
|
|
expanded = concat(expanded,@(first))
|
|
end if
|
|
if ( !fn ScannerIsAtEnd( scanner ) )
|
|
if ( fn ScannerScanString( scanner, @"-", NULL ) )
|
|
if ( fn ScannerScanInteger( scanner, @last ) )
|
|
for long i = first + 1 to last
|
|
if ( len(expanded) ) then expanded = concat(expanded,@", ")
|
|
expanded = concat(expanded,@(i))
|
|
next
|
|
end if
|
|
end if
|
|
end if
|
|
next
|
|
end fn = expanded
|
|
|
|
print fn ExpandRanges( @"-6,-3--1,3-5,7-11,14,15,17-20" )
|
|
|
|
HandleEvents
|