Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Backslash substitution bug

Closed / Invalid1065519fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 22 years ago
Descriptionplain2004-11-12 23:54:24
Tcl Version - Both 8.3 and 8.4
OS Platform and Version - Win XP, Solaris
Problem
Using backslash substitutions for hex characters
doesn't stop at 2 characters

Using a string2Hex Routine found on the TCLers wiki page

set xxx "ABC\x1C1.00"
0000000: 4142 43C1 2e30 30         ABC..00

I would expect
0000000: 4142 431c 312e 3030      ABC.1.00

My email is [email protected]
dgp Closed ticket [1065519fff]. [History diff]2004-11-13 07:26:22
dgpplain2004-11-13 07:26:23
Logged In: YES 
user_id=80530

that's the documented rule
for backslash substitution.
\x will keep reading bytes
as long as it sees hexadecimal
digits.  When done scanning,
the final two hexadigits become
the value to substitute.

You will probably be happier
making use of \u substitution
instead of \x subtitution for the
sake of more predictable behavior.
nobodyplain2004-11-13 08:06:50
Logged In: NO 

Thanks for the quick response!!!

I am very curious as to the background behind this.  Both C
and perl work as I would expect.  What possible reasons
would you want to discard data during a substition.

For various reasons, unicode substition is not an option
here, but I do have a work around.

[email protected]
maxvelocityplain2004-11-13 08:09:20
Logged In: YES 
user_id=1158291

I'm curious as why this rule is in place.  ANSI C and Perl
interpret the backslash substitution for hex with only 2
characters.

\u is fine but requires the "1" following the "\x1C" to be
converted to hex for a 16-bit value.
dgpplain2004-11-14 02:50:54
Logged In: YES 
user_id=80530

The people currently maintaining
Tcl are mostly not those who originally
implemented it, so we have a difficult
time answering the "why" questions.

All we can say is it's been that way
a long time; it's documented to be
that way; and there exist scripts
that depend on it, so we don't dare
change it while claiming compatible
operations, that is, while distributing
the Tcl 8.* series of releases.

It's conceivable this could be changed
when work toward Tcl 9 takes place.
If you are interested in pushing for
that, you might file a Feature Request
report.

BTW, I think you may have misunderstood
the \u recommendataion.  Wherever you
currently have \xHH you can replace it
with \u00HH and get the result you expect.
Log in (anonymous is fine) to add a comment.