Subject: Re: Dangers of \x (WAS Re: Doing in tcl/tk text widget?) - DN [1]
Don Libes <libes@nist.gov> - 04 May 1999 - comp.lang.tcl
Jeffrey Hobbs <Jeffrey.Hobbs@icn.siemens.de> writes: > John Chambers wrote: > > Don Porter wrote: > > > Try inserting the character \xa0 instead of a space between the > > > two words you don't want broken apart onto separate lines. > > > > Here's a little test script to demo how \xa0 fails: > ... > > .t insert end "This line uses\xa0several a0\xa0chars to\xa0prevent wrapping.\n" > ... > > However, the "a0\xa0chars" screws up rather badly. First, it > > The problem is in the way \x... is interpreted in Tcl. After the \x, > all hexadecimal chars will be swallowed up until a non-hex is found, but > only the last two are used. This is kind of stupid, IMHO, since octal > backslash is limited to 3 (although one or two works as well, which can > be dangerously interp'd), and the unicode of Tcl8.1 is limited to 4. It may help to note that this design was just borrowed from C which defines hex escapes similarly. In C, not having a bound on escape sequence lengths makes a lot of sense because objects could be indefinitely large - and it was implementation dependent how large certain datatypes could be. Tcl followed C's definition for hex escapes because it wasn't clear at the time that it wasn't a good idea. Now of course, it's quite obvious. (In fact, lint probably reports that Tcl isn't checking for the potential overflow.) So this should be fixed - and it's trivial to do so. There can't possibly be any code that would break. By the way, the "only the last two are used" is not set in stone. That's also implementation dependent. > Anyway, I prefer to use 8.1, and the \xa0 does work in the text widget, > but it can be safely written: > set a "a\u00a0b" > to get "a b" (visually), without having to worry about what follows > the escape sequence. Otherwise, you can pop it into octal as \240 > (again, 3 max, so no misunderstandings). Don
Last modified
1999-09-27
1999-09-27
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
