From 0a5e7be129644e9f53deb7051e812098c1f4e518 Mon Sep 17 00:00:00 2001 From: maxfl Date: Sat, 7 Jul 2012 10:57:28 +0800 Subject: [PATCH] Add index ranges Builtin 'set' now can set variable index ranges: set test[1..3] a b c #works set test[-1..-3] a b c #works if variable have enough elements set test[2..-2] a b c #works set test[1..3 -1..-2] a b c b b #works Expand now can parse index ranges. But not handle for now. TODO: * Add variable substitution index ranges: echo $PATH[-1..1] * Add command substitution index range: echo (seq 10)[-1..-4] * Add process substitution indexes and ranges: echo %vim[-1] --- builtin_set.cpp | 30 ++++++++++++++++++++++++++---- expand.cpp | 19 ++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/builtin_set.cpp b/builtin_set.cpp index c1bb65ccc..11fe2ab98 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -236,11 +236,33 @@ static int parse_index( std::vector &indexes, l_ind = var_count+l_ind+1; } - indexes.push_back( l_ind ); src = end; - count++; - while (iswspace(*src)) src++; - } + if ( *src==L'.' && *(src+1)==L'.' ){ + src+=2; + long l_ind2 = wcstol( src, &end, 10 ); + if( end==src || errno ) + { + return 1; + } + src = end; + + if( l_ind2 < 0 ) + { + l_ind2 = var_count+l_ind2+1; + } + int direction = l_ind2 } // debug( 0, L"Push idx %d", tmp ); - idx.push_back(tmp); pos = end-in; + if ( in[pos]==L'.' && in[pos+1]==L'.' ){ + pos+=2; + long tmp1 = wcstol( &in[pos], &end, 10 ); + if( ( errno ) || ( end == &in[pos] ) ) + { + return 1; + } + pos = end-in; + + debug( 0, L"Push range idx %d %d", tmp, tmp1 ); + idx.push_back(tmp); + // idx.push_back(tmp2); + continue; + } + + debug( 0, L"Push idx %d", tmp ); + idx.push_back(tmp); + // idx.push_back(tmp2); } if( end_ptr )