diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-06-27 22:11:31 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-07-08 05:41:58 +1000 |
commit | bd5bdcbe8a88570d1ac23511443563bc4454504d (patch) | |
tree | 1a05543fd69275f1371f3f4c3649ee284bc1071a | |
parent | 4a5e4965e2c208375a77d40b831a07897f80ee50 (diff) | |
download | jimtcl-bd5bdcbe8a88570d1ac23511443563bc4454504d.zip jimtcl-bd5bdcbe8a88570d1ac23511443563bc4454504d.tar.gz jimtcl-bd5bdcbe8a88570d1ac23511443563bc4454504d.tar.bz2 |
Make list to string conversion more Tcl compatible
If a list elements contains unmatch ] brackets, use
backslash quoting instead of braces. This is what Tcl does.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 17 | ||||
-rw-r--r-- | tests/scan.test | 4 |
2 files changed, 16 insertions, 5 deletions
@@ -5618,7 +5618,7 @@ void DupListInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr) #define JIM_ELESTR_QUOTE 2 static int ListElementQuotingType(const char *s, int len) { - int i, level, trySimple = 1; + int i, level, blevel, trySimple = 1; /* Try with the SIMPLE case */ if (len == 0) @@ -5653,9 +5653,10 @@ static int ListElementQuotingType(const char *s, int len) testbrace: /* Test if it's possible to do with braces */ - if (s[len - 1] == '\\' || s[len - 1] == ']') + if (s[len - 1] == '\\') return JIM_ELESTR_QUOTE; level = 0; + blevel = 0; for (i = 0; i < len; i++) { switch (s[i]) { case '{': @@ -5666,6 +5667,12 @@ static int ListElementQuotingType(const char *s, int len) if (level < 0) return JIM_ELESTR_QUOTE; break; + case '[': + blevel++; + break; + case ']': + blevel--; + break; case '\\': if (s[i + 1] == '\n') return JIM_ELESTR_QUOTE; @@ -5674,6 +5681,10 @@ static int ListElementQuotingType(const char *s, int len) break; } } + if (blevel < 0) { + return JIM_ELESTR_QUOTE; + } + if (level == 0) { if (!trySimple) return JIM_ELESTR_BRACE; @@ -5756,7 +5767,7 @@ static char *BackslashQuoteString(const char *s, int len, int *qlenPtr) return q; } -void UpdateStringOfList(struct Jim_Obj *objPtr) +static void UpdateStringOfList(struct Jim_Obj *objPtr) { int i, bufLen, realLength; const char *strRep; diff --git a/tests/scan.test b/tests/scan.test index f936ee3..8bfcbe8 100644 --- a/tests/scan.test +++ b/tests/scan.test @@ -20,9 +20,9 @@ needs cmd scan test scan-1.1 {BuildCharSet, CharInSet} { list [scan foo {%[^o]} x] $x } {1 f} -test scan-1.2 {BuildCharSet, CharInSet} jim { +test scan-1.2 {BuildCharSet, CharInSet} { list [scan \]foo {%[]f]} x] $x -} {1 {]f}} +} {1 \]f} test scan-1.3 {BuildCharSet, CharInSet} { list [scan abc-def {%[a-c]} x] $x } {1 abc} |