Version 1 of quoted-printable

Updated 2004-05-12 05:31:23

Richard Suchenwirth 2004-05-12 - "Quoted-printable" is a way of encoding 8-bit characters by using only 7-bit ASCII characters, by replacing them with =XX, XX being two hex digits. This is used for instance in MIME mail attachments. Decoding this type of data goes in a one-liner with subst:

 proc quoted-printable s {subst -nocom -novar [string map {== = = \\u00} $s]}

The other way it seems to need explicit iteration:

 proc to-quoted-printable s {
    set res ""
    foreach char [split $s ""] {
        scan $char %c i
        if {$i>255} {error "character $i does not fit in 8 bits"}
        append res [expr {$i<128? $char: [format =%02X $i]}]
    }
    set res
 }

# Test and demo:

 % to-quoted-printable "Schöne Grüße"
 Sch=F6ne Gr=FC=DFe

Arts and crafts of Tcl-Tk programming