Skip to content
Tcl Source Code History Of Ticket ded7528bffe8bdf4
Login

History Of Ticket ded7528bffe8bdf4

Artifacts Associated With Ticket ded7528bffe8bdf4

  1. Ticket change [731ae5f5ce] (rid 136896) by ericp on 2014-02-16 01:38:06:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      I was trying to write a function that would urlencode a string, with \uxxxx sequences.  http://rosettacode.org/wiki/JSON#Tcl led me to trying this code:
      
          set escaped1 [subst  \
                            [regsub -all {[\[\]\$\u0000-\u001f\u0080-\uffff]} \
                         $value2 {[format "\\\\u%04x" [scan {&} %c]]}]]
      
      which I thought worked.  However, it seems to drop characters when
      braces are involved:
      
      % set value {w1 on the <blah abc {} def > form}
      w1 on the <blah abc {} def > form
      % set value1 [string map [list "@" "<@@>"] $value]
      w1 on the <blah abc {} def > form
      % set value2 [string map [list "\\" "<@>"] $value1]
      w1 on the <blah abc {} def > form
      % set escaped1 [subst [regsub -all {[\[\]\\\{\\\}\$\u0000-\u001f\u0080-\uffff]}
      $value2 {[format "\\\\u%04x" [scan {&} %c]]}]]
      w1 on the <blah abc \u007b def > form
      
      The close-brace should appear as \u007d, but it's missing completely.
      
      Bug, or is there better usage?
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "ericp"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "6d1053e9208f1074fd485c15cc0d7e49e190bac5"
    10. resolution initialized to: "None"
    11. severity initialized to: "Severe"
    12. status initialized to: "Open"
    13. submitter initialized to: "ericp"
    14. subsystem initialized to: "18. Commands M-Z"
    15. title initialized to: "subst/regsub/format/scan gets confused by braces"
    16. type initialized to: "Bug"
  2. Ticket change [9b78079142] (rid 136897) by dgp on 2014-02-16 03:55:36:

    1. icomment:
      There's no bug in Tcl demonstrated here.
      
      It's quite likely you are demonstrating buggy attempts
      to accomplish whatever it is you are trying to do.
      
      It helps not to obscure the intermediate results, or to
      include pointless preliminaries.  Examine this:
      
      % set a {w1 on the <blah abc {} def > form}
      w1 on the <blah abc {} def > form
      
      % set b [regsub -all {[\[\]\\\{\\\}\$\u0000-\u001f\u0080-\uffff]} $a {[format "\\\\u%04x" [scan {&} %c]]}]
      w1 on the <blah abc [format "\\u%04x" [scan {{} %c]][format "\\u%04x" [scan {}} %c]] def > form
      
      
      % set c [subst $b]
      w1 on the <blah abc \u007b def > form
      
      
      Take a good look at the value of $b and think through 
      how [subst] is going to parse the brace quoted words in
      the command substitutions found within it.  You likely
      were not expecting the command
      
      scan {{} %c]][format "\\u%04x" [scan {}} %c
      
      to be part of it, but that's what happened.  (That's
      the [scan] command with only 2 arguments)
      
      Just as a aside, whenever you see a Tcl programmer trying
      to perfect string manipulation techniques to omit or disguise
      braces, it's a very good bet they are mis-using lists somewhere.
      Frequently it involves mistaking the appearance of the list 
      itself with the appearance of the elements it comprises.
      What is the real problem to be solved when you get into trouble?
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  3. Ticket change [c5e33e0963] (rid 136898) by dgp on 2014-02-16 04:02:44:

    1. icomment:
      All that said, if you just want to replace the open brace
      with the string \u007b and the close brace with the string \u007d
      then the tool to use is [string map]
      
      % set s {foo {} bar}
      foo {} bar
      
      % set result [string map [list "{" {\u007b} "}" {\u007d}] $s]
      foo \u007b\u007d bar
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  4. Ticket change [2796553d17] (rid 137513) by dgp on 2014-04-04 18:14:42:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2456752.26021431"
    3. closer changed to: "dgp"
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"