Issue with handling the degree character
Bill Frantz <[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <r314ps-1065i-211506355ED542EB90910F1C38596FA5@Bill-Frantzs-MacBook-Pro.local> |
I have a problem with the degree symbol.
For the record, the environment is: MacOS X 10.6.4 (Intel
processor). The source file is edited in BBEdit 9.6.1 (2860) of
Thu, 11 Nov 2010.
The symbol is used in a file the first two lines of which are
(look for "Temp, °C"):
"Plot Title: 997111 - Cave "
"#","Time, GMT-07:00","Temp, °C","Intensity, Lux","Batt,
V","Coupler Attached","Stopped","End Of File"
When I print the start of the file with od -ctxC, I get
0000000 " P l o t T i t l e :
9 9 7
22 50 6c 6f 74 20 54 69 74 6c 65 3a 20
39 39 37
0000020 1 1 1 - C a v e " \r
\n " #
31 31 31 20 2d 20 43 61 76 65 20 22 0d
0a 22 23
0000040 " , " T i m e , G M T -
0 7 :
22 2c 22 54 69 6d 65 2c 20 47 4d 54 2d
30 37 3a
0000060 0 0 " , " T e m p , 241 C
" , "
30 30 22 2c 22 54 65 6d 70 2c 20 a1 43
22 2c 22
0000100
The degree symbol is represented as the single character 0xa1 in
the file.
I read the file with:
for line in file {
if (line =~ `@_,@d1,@d2,@t1,@t2,@l1,@l2,@_`) {
I code a test for it in my program:
if (t1 != "\"Temp" || t2 != " °C\"") {
Which results in the following disk version of the source code:
0004220 " T e m p " | | t 2
! =
22 54 65 6d 70 22 20 7c 7c 20 74 32 20
21 3d 20
0004240 " ° ** C \ " " ) { \r \t \t
22 20 c2 b0 43 5c 22 22 29 20 7b 0d 09
09 20 20
Where the degree symbol is represented by the sequence 0xc2b0.
After the test fails, I added some code to print the constant
and the parsed value:
def px {
to printhex(value) {
var str := ` value.size ${value.size()} `
def albet := "0123456789ABCDEF"
for ch in value {
def hich := ch.asInteger() >> 8
def loch := ch.asInteger() & 255
str += albet[hich//16]
str += albet[hich%16]
str += albet[loch//16]
str += albet[loch%16]
}
println(str)
}
}
#...
def con := " °C\""
println(`Constant $con`)
px.printhex(con)
println(`t2 $t2`)
px.printhex(t2)
Which prints:
Constant °C"
value.size 5 002000AC221E00430022
t2 ?C"
value.size 4 002000B000430022
When I changed the text encoding in BBEdit from "Unicode
(UTF-8)" to "Western (MacOS Roman)", the test succeeded and printed:
Constant ¡C"
value.size 4 002000B000430022
t2 ¡C"
value.size 4 002000B000430022
The source file changed to:
0004760 ! = " \ " T e m p " |
| t
21 3d 20 22 5c 22 54 65 6d 70 22 20 7c
7c 20 74
0005000 2 ! = " 241 C \ " "
) { \r
32 20 21 3d 20 22 20 a1 43 5c 22 22 29
20 7b 0d
The degree symbol is represented as the single character 0xa1 in
this source.
It seems to me that something in either reading the file or the
quasi-parser is converting the degree symbol to a 0x00b0. Also
something is happening to the Unicode value between the source
file and the representation of the constant at run time
expanding it to 5 characters.
I can live with this issue, but is this what is supposed to happen?
Cheers - Bill
-----------------------------------------------------------------------
Bill Frantz | The nice thing about | Periwinkle
(408)356-8506 | standards is there are so | 16345
Englewood Ave
www.pwpconsult.com | many to choose from. - anon | Los Gatos,
CA 95032
_______________________________________________
e-lang mailing list
[email protected]
http://www.eros-os.org/mailman/listinfo/e-lang