@@ -144,15 +144,26 @@ impl DimElement {
144
144
145
145
/// Get array of indexes from string
146
146
pub fn parse_indexes ( text : & str ) -> Option < Vec < String > > {
147
- if text. contains ( '-' ) {
148
- let mut parts = text. splitn ( 2 , '-' ) ;
149
- let start = parts. next ( ) ?. parse :: < u32 > ( ) . ok ( ) ?;
150
- let end = parts. next ( ) ?. parse :: < u32 > ( ) . ok ( ) ?;
151
-
152
- Some ( ( start..=end) . map ( |i| i. to_string ( ) ) . collect ( ) )
147
+ ( if text. contains ( '-' ) {
148
+ let ( start, end) = text. split_once ( '-' ) ?;
149
+ if let ( Ok ( start) , Ok ( end) ) = ( start. parse :: < u32 > ( ) , end. parse :: < u32 > ( ) ) {
150
+ Some ( ( start..=end) . map ( |i| i. to_string ( ) ) . collect :: < Vec < _ > > ( ) )
151
+ } else {
152
+ let mut start = start. bytes ( ) ;
153
+ let mut end = end. bytes ( ) ;
154
+ match ( start. next ( ) , start. next ( ) , end. next ( ) , end. next ( ) ) {
155
+ ( Some ( start) , None , Some ( end) , None )
156
+ if start. is_ascii_alphabetic ( ) && end. is_ascii_alphabetic ( ) =>
157
+ {
158
+ Some ( ( start..=end) . map ( |c| char:: from ( c) . to_string ( ) ) . collect ( ) )
159
+ }
160
+ _ => None ,
161
+ }
162
+ }
153
163
} else {
154
164
Some ( text. split ( ',' ) . map ( |s| s. to_string ( ) ) . collect ( ) )
155
- }
165
+ } )
166
+ . filter ( |v| !v. is_empty ( ) )
156
167
}
157
168
/// Try to represent [`DimElement`] as range of integer indexes
158
169
pub fn indexes_as_range ( & self ) -> Option < RangeInclusive < u32 > > {
0 commit comments