[REBOL] quoted-printable encoder
From: oliva::david::seznam::cz at: 20-Jun-2002 15:16
Hello rebol-list,
I've just uploaded this quoted-printable encoder to the library so enjoy it if you
want and correct me if you will find some bugs:-)
-----------
rebol [
title: "quoted-printable encoder"
purpose: {Encodes the string data to quoted-printable format}
author: "Oldes"
email: [oliva--david--seznam--cz]
date: 20-Jun-2002/13:16:03+2:00
version: 1.0.0
usage: {
>> qp-encode "nejzajímavější"
== "nejzaj=EDmav=ECj=9A=ED"}
comment: {More info about this encoding:
http://www.faqs.org/rfcs/rfc2045.html}
]
qp-encode: func[
"Encodes the string data to quoted-printable format"
str [any-string!] "string to encode"
/local c h l r normal rest
][
l: 0 r: 0
normal: charset [#"!" - #"<" #">" - #"~" #" "]
rest: complement normal
parse/all copy str [
any [
h: [
( r: (index? h) - l )
normal (
;non encoded characters
if r = 76 [h: insert h "=^M^/" l: -1 + index? h]
)
| copy c rest (
remove h
if r >= 74 [h: insert h "=^M^/" l: -1 + index? h]
insert h join #"=" copy/part skip mold to binary! c 2 2
) 2 skip
] :h skip
]
]
head h
]