2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
5 * C-style backslash escaping and unescaping of strings.
7 #ifndef __WVBACKSLASH_H
8 #define __WVBACKSLASH_H
10 #include "wvencoder.h"
13 * An encoder that performs C-style backslash escaping of strings.
15 * Use this to escape control characters, unprintable characters,
16 * and optionally quotes or any other special printable characters
17 * into sequences of the form \\n, \\xFF, \\", etc...
22 class WvBackslashEncoder
: public WvEncoder
28 * Creates a C-style backslash encoder.
29 * nasties - the set of printable characters to escape
30 * in addition to the non-printable ones
31 * (should always contain at least backslash)
33 WvBackslashEncoder(WvStringParm _nasties
= "\\\"");
34 virtual ~WvBackslashEncoder() { }
37 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
, bool flush
);
38 virtual bool _reset();
43 * An encoder that performs C-style backslash unescaping of strings.
45 * Recognizes the following sequences preceeded by backslash:
47 * - a: substitutes alarm bell (ascii 7)
48 * - b: substitutes backspace (ascii 8)
49 * - f: substitutes formfeed (ascii 12)
50 * - n: substitutes newline (ascii 10)
51 * - r: substitutes carriage return (ascii 13)
52 * - t: substitutes tab (ascii 9)
53 * - v: substitutes vertical tab (ascii 11)
54 * - 0: substitutes null (ascii 0)
55 * - 0xyz: substitutes character with octal encoding xyz
56 * - xxy: substitutes character with hex encoding xy
57 * - newline: substitutes space (line continuation sequence)
58 * - \\: substitutes backslash
59 * - otherwise substitutes the next character (strips the backslash)
65 class WvBackslashDecoder
: public WvEncoder
68 { Initial
, Escape
, Hex1
, Hex2
, Octal1
, Octal2
, Octal3
};
74 /** Creates a C-style backslash decoder. */
76 virtual ~WvBackslashDecoder() { }
79 virtual bool _encode(WvBuf
&inbuf
, WvBuf
&outbuf
, bool flush
);
80 virtual bool _reset();
83 bool flushtmpbuf(WvBuf
&outbuf
);
86 #endif // __WVBACKSLASH_H