2 * ----------------------------------------------------------------------
6 (**********************************************************************)
7 (* Several encodings important for the net *)
8 (**********************************************************************)
11 (**********************************************************************)
12 (* Base 64 encoding *)
13 (**********************************************************************)
15 (* See RFC 2045 for a description of Base 64 encoding. *)
18 * All Base64 functions are reentrant and thus thread-safe.
23 val encode : ?pos:int -> ?len:int -> ?linelength:int -> ?crlf:bool ->
25 (* Compute the "base 64" encoding of the given string argument.
26 * Note that the result is a string that only contains the characters
27 * a-z, A-Z, 0-9, +, /, =, and optionally spaces, CR and LF characters.
29 * If pos and/or len are passed, only the substring starting at
30 * pos (default: 0) with length len (default: rest of the string)
33 * The result is divided up into lines not longer than 'linelength'
34 * (without counting the line separator); default: do not divide lines.
35 * If 'linelength' is smaller than 4, no line division is performed.
36 * If 'linelength' is not divisible by 4, the produced lines are a
37 * bit shorter than 'linelength'.
39 * If 'crlf' (default: false) the lines are ended by CRLF; otherwise
40 * they are only ended by LF.
41 * (You need the crlf option to produce correct MIME messages.)
45 val url_encode : ?pos:int -> ?len:int -> ?linelength:int -> ?crlf:bool ->
47 (* Same as 'encode' but use slightly different characters that can be
48 * part of URLs without additional encodings.
49 * The encoded string consists only of the characters a-z, A-Z, 0-9,
51 * 'url_encode' does NOT implement the Base 64 encoding as described
55 val encode_substring : string -> pos:int -> len:int -> linelength:int ->
57 (* *** DEPRECATED FUNCTION *** Use 'encode' instead! ***
59 * encode_substring s pos len linelen crlf:
60 * Encodes the substring at position 'pos' in 's' with length 'len'.
61 * The result is divided up into lines not longer than 'linelen' (without
62 * counting the line separator).
63 * If 'linelen' is smaller than 4, no line division is performed.
64 * If 'linelen' is not divisible by 4, the produced lines are a
65 * bit shorter than 'linelen'.
66 * If 'crlf' the lines are ended by CRLF; otherwise they are only
68 * (You need the crlf option to produce correct MIME messages.)
71 val decode : ?pos:int -> ?len:int -> ?url_variant:bool ->
72 ?accept_spaces:bool -> string -> string
73 (* Decodes the given string argument.
75 * If pos and/or len are passed, only the substring starting at
76 * pos (default: 0) with length len (default: rest of the string)
79 * If url_variant (default: true) is set, the functions also
80 * accepts the characters '-' and '.' as produced by 'url_encode'.
82 * If accept_spaces (default: false) is set, the function ignores
83 * white space contained in the string to decode (otherwise the
84 * function fails if it finds white space).
87 val decode_ignore_spaces : string -> string
88 (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
90 * Decodes the string, too, but it is allowed that the string contains
91 * whitespace characters.
92 * This function is slower than 'decode'.
95 val decode_substring : string -> pos:int -> len:int -> url_variant:bool ->
96 accept_spaces:bool -> string
97 (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
99 * decode_substring s pos len url spaces:
100 * Decodes the substring of 's' beginning at 'pos' with length 'len'.
101 * If 'url', strings created by 'url_encode' are accepted, too.
102 * If 'spaces', whitespace characters are allowed in the string.
106 (**********************************************************************)
107 (* Quoted printable encoding *)
108 (**********************************************************************)
111 * This implementation assumes that the encoded string has a text MIME
112 * type. Because of this, the characters CR and LF are never protected
113 * by hex tokens; they are copied literally to the output string.
117 * All QuotedPrintable functions are reentrant and thus thread-safe.
120 module QuotedPrintable :
122 val encode : ?pos:int -> ?len:int -> string -> string
123 (* Encodes the string and returns it.
125 * No additional soft line breaks are added. The characters CR
126 * and LF are not represented as =0D resp. =0A. (But other control
127 * characters ARE encoded.)
128 * Note unsafe characters:
129 * As recommended by RFC 2045, the characters !\"#$@[]^`{|}~
130 * are additionally represented as hex tokens. -- "
132 * If pos and/or len are passed, only the substring starting at
133 * pos (default: 0) with length len (default: rest of the string)
137 val encode_substring : string -> pos:int -> len:int -> string
138 (* *** DEPRECATED FUNCTION *** Use 'encode' instead! ***
139 * encode_substring s pos len:
140 * Encodes the substring of 's' beginning at 'pos' with length 'len'.
143 val decode : ?pos:int -> ?len:int -> string -> string
144 (* Decodes the string and returns it.
145 * Most format errors cause an Invalid_argument exception.
146 * Note that soft line breaks can be properly decoded although
147 * 'encode' will never produce them.
149 * If pos and/or len are passed, only the substring starting at
150 * pos (default: 0) with length len (default: rest of the string)
154 val decode_substring : string -> pos:int -> len:int -> string
155 (* *** DEPRECATED FUNCTION *** Use 'decode' instead! ***
156 * decode_substring s pos len:
157 * Decodes the substring of 's' beginning at 'pos' with length 'len'.
162 (**********************************************************************)
164 (**********************************************************************)
167 * The functions behave similar to those of QuotedPrintable.
171 * All Q functions are reentrant and thus thread-safe.
176 val encode : ?pos:int -> ?len:int -> string -> string
178 * All characters except alphanumeric characters are protected by
180 * In particular, spaces are represented as "=20", not as "_".
183 val decode : ?pos:int -> ?len:int -> string -> string
185 val encode_substring : string -> pos:int -> len:int -> string
186 (* *** DEPRECATED FUNCTION *** Use 'encode' instead! *** *)
188 val decode_substring : string -> pos:int -> len:int -> string
189 (* *** DEPRECATED FUNCTION *** Use 'decode' instead! *** *)
192 (**********************************************************************)
194 (**********************************************************************)
196 (* The B encoding of RFC 2047 is the same as Base64. *)
199 (**********************************************************************)
201 (**********************************************************************)
203 (* Encoding/Decoding within URLs:
205 * The following two functions perform the '%'-substitution for
206 * characters that may otherwise be interpreted as metacharacters.
208 * According to: RFC 1738, RFC 1630
212 * The Url functions are thread-safe.
217 val decode : string -> string
218 val encode : string -> string
222 (**********************************************************************)
224 (**********************************************************************)
226 (* Encodes characters that need protection by converting them to
227 * entity references. E.g. "<" is converted to "<".
228 * As the entities may be named, there is a dependency on the character
229 * set. Currently, there are only functions for the Latin 1 alphabet.
233 * The Html functions are thread-safe.
238 val encode_from_latin1 : string -> string
239 (* Encodes the characters 0-8, 11-12, 14-31, '<', '>', '"', '&',
240 * 127-255. If the characters have a name, a named entity is
241 * preferred over a numeric entity.
243 val decode_to_latin1 : string -> string
244 (* Decodes the string. Unknown named entities are left as they
245 * are (i.e. decode_to_latin1 "&nonsense;" = "&nonsense;").
246 * The same applies to numeric entities greater than 255.
251 (* ======================================================================
255 * Revision 1.1 2000/11/17 09:57:27 lpadovan
258 * Revision 1.4 2000/06/25 22:34:43 gerd
259 * Added labels to arguments.
261 * Revision 1.3 2000/06/25 21:15:48 gerd
262 * Checked thread-safety.
264 * Revision 1.2 2000/03/03 01:08:29 gerd
265 * Added Netencoding.Html functions.
267 * Revision 1.1 2000/03/02 01:14:48 gerd