diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-09-30 16:06:37 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-11-09 07:18:26 +1000 |
commit | c35132ec0e0faa80908d3abe29173720403a4349 (patch) | |
tree | 699adffbc8b87601e411cadd7c9254249c121a26 | |
parent | 039c6c24ffbdb460165839ea8a933f764b813753 (diff) | |
download | jimtcl-c35132ec0e0faa80908d3abe29173720403a4349.zip jimtcl-c35132ec0e0faa80908d3abe29173720403a4349.tar.gz jimtcl-c35132ec0e0faa80908d3abe29173720403a4349.tar.bz2 |
List with # only needs braces for first element
Compatibility with Tcl
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 20 | ||||
-rw-r--r-- | tests/list.test | 2 |
2 files changed, 16 insertions, 6 deletions
@@ -5550,8 +5550,6 @@ static int ListElementQuotingType(const char *s, int len) /* Try with the SIMPLE case */ if (len == 0) return JIM_ELESTR_BRACE; - if (s[0] == '#') - return JIM_ELESTR_BRACE; if (s[0] == '"' || s[0] == '{') { trySimple = 0; goto testbrace; @@ -5712,8 +5710,13 @@ static void UpdateStringOfList(struct Jim_Obj *objPtr) quotingType[i] = ListElementQuotingType(strRep, len); switch (quotingType[i]) { case JIM_ELESTR_SIMPLE: - bufLen += len; - break; + if (i != 0 || strRep[0] != '#') { + bufLen += len; + break; + } + /* Special case '#' on first element needs braces */ + quotingType[i] = JIM_ELESTR_BRACE; + /* fall through */ case JIM_ELESTR_BRACE: bufLen += len + 2; break; @@ -6371,8 +6374,13 @@ void UpdateStringOfDict(struct Jim_Obj *objPtr) quotingType[i] = ListElementQuotingType(strRep, len); switch (quotingType[i]) { case JIM_ELESTR_SIMPLE: - bufLen += len; - break; + if (i != 0 || strRep[0] != '#') { + bufLen += len; + break; + } + /* Special case '#' on first element needs braces */ + quotingType[i] = JIM_ELESTR_BRACE; + /* fall through */ case JIM_ELESTR_BRACE: bufLen += len + 2; break; diff --git a/tests/list.test b/tests/list.test index 3889018..d4cecda 100644 --- a/tests/list.test +++ b/tests/list.test @@ -42,6 +42,8 @@ test list-1.22 {basic tests} {list "{ab}\\"} \\{ab\\}\\\\ test list-1.23 {basic tests} {list \{} "\\{" test list-1.24 {basic tests} {list} {} test list-1.25 {basic tests} {list #} {{#}} +test list-1.26 {basic tests} {list #abc} {{#abc}} +test list-1.27 {basic tests} {list def #abc} {def #abc} # For the next round of tests create a list and then pick it apart # with "index" to make sure that we get back exactly what went in. |