- The gsm0338 encoding must be available in the Tcl installation. Download it from http://search.cpan.org/src/JHI/perl-5.7.2/ext/Encode/Encode/ and save it as e.g. $tcl_library/encoding/gsm0338.enc
- A Tcl-Version which supports encoding convertto and encoding convertfrom (Tcl 8.1 or above)
set gsmString [encoding convertto gsm0338 "me@domain.com"] # will return me?domain.com instead of me\x00domain.comWorkarounds
# The string is split at each "@", and the pieces are converted # separately. proc toGsm {aString} { set partsWithoutAt [split $aString "@"] set convertedPartsWithoutAt {} foreach part $partsWithoutAt { lappend convertedPartsWithoutAt [encoding convertto gsm0338 $part] } return [join $convertedPartsWithoutAt "\x00"] }An alternative workaround, which is shorter but relies on an implementation detail of encoding convertto:
proc toGsm {aString} { return [encoding convertto gsm0338 [string map {@ \x00} $aString] ] }
Lars H, 4 July 2005: I wouldn't label that as an implementation detail of encoding convertto; aren't you simply using the fact that gsm0338 maps NUL to itself? The string map maps \x40 to \x00.As for the encoding error, is this a shortcoming in the encoding mechanism (impossible to map non-NUL characters to NUL) or an error in the particular encoding definition file? I wouldn't be entirely surprised if other languages have trouble with NULs in strings, but Tcl handles it correctly AFAIK.schlenk, 5 July 2005: One could simply add the txt file from http://www.unicode.org/Public/MAPPINGS/ETSI/GSM0338.TXT to the encoding dir under tools in the tcl source distribution and rebuild the tcl encoding files from scratch including gsm0338 like Tcl does for all the other encoding tables. The above mentioned text file contains some extra hints on how to use the translation table.
willdye For what it's worth, the following (edited) conversation about GSM encoding took place in the Tcl chatroom on 2005-10-14:Cameron_: Why would a telephone handset, which seems to be using 7-bit ASCII for the most part, encode a '$' as decimal 2 (where blank is 32, '.' is 46, and so on--the normal ascii table)?schlenk: Maybe some SMS/GSM specification stuff? Something like this: http://wiki.tcl.tk/14441 . "$" is "02" in that specification.Cameron_: Wow! What a great answer. Thank you!
BAS - yeah, from what I remember, gsm03.38 looks like ASCII, except they took out a lot of the control characters, and replaced them with chars from LATIN-1 upper table.