aboutsummaryrefslogtreecommitdiffhomepage
path: root/expand.cpp
diff options
context:
space:
mode:
authorGravatar maxfl <gmaxfl@gmail.com>2012-07-07 10:57:28 +0800
committerGravatar maxfl <gmaxfl@gmail.com>2012-07-07 10:57:28 +0800
commit0a5e7be129644e9f53deb7051e812098c1f4e518 (patch)
treebfe36296f366f5d9546a601b5ab4005ccb34d6b9 /expand.cpp
parentb23d65b0144e61afee0b0fdd841c6c746b2e885d (diff)
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]
Diffstat (limited to 'expand.cpp')
-rw-r--r--expand.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/expand.cpp b/expand.cpp
index 0d4c84cb..05485951 100644
--- a/expand.cpp
+++ b/expand.cpp
@@ -759,8 +759,25 @@ static int parse_slice( const wchar_t *in, wchar_t **end_ptr, std::vector<long>
}
// 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 )