Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 188d6b6d88fc5cdb9bbdf56582cbbbea03d7495f
Ticket: 3063568fffffffffffffffffffffffffffffffff
regsub example doesn't perform as advertized
User & Date: jaspertheperson on 2010-09-10 11:57:18
Changes

  1. assignee changed to: "pvgoran"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    It's this one:
    ===========================================
    Convert all non-ASCII and Tcl-significant characters into \u escape sequences by using regsub and subst in combination:
    
    # This RE is just a character class for everything "bad"
    set RE {[][{};#\\\$\s\u0080-\uffff]}
    
    # We will substitute with a fragment of Tcl script in brackets
    set substitution {[format \\\\u%04x [scan "\\&" %c]]}
    
    # Now we apply the substitution to get a subst-string that
    # will perform the computational parts of the conversion.
    set quoted [subst [regsub -all $RE $string $substitution]]
    
    ===========================================
    The RE for "bad" characters includes \s which matches all whitespace characters including newline. However, inserting \ before newline before calling subst on a string containing it does not preserve the newline, it causes it to be replaced by a space, so the whole procedure replaces newlines with \u0020
    
    Not sure how to get this to work properly! Little help?
    
  4. foundin changed to: "obsolete: 8.6b1"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "jaspertheperson"
  10. subsystem changed to: "43. Regexp"
  11. title changed to: "regsub example doesn't perform as advertized"
  12. type changed to: "Bug"