wvdbusserver: implement NameHasOwner request.
[wvstreams.git] / include / wvbackslash.h
blob916cfbd1e9ea527552ff1b14a1a35df4cc795ea9
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2002 Net Integration Technologies, Inc.
5 * C-style backslash escaping and unescaping of strings.
6 */
7 #ifndef __WVBACKSLASH_H
8 #define __WVBACKSLASH_H
10 #include "wvencoder.h"
12 /**
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...
19 * Supports reset().
22 class WvBackslashEncoder : public WvEncoder
24 WvString nasties;
26 public:
27 /**
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() { }
36 protected:
37 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush);
38 virtual bool _reset();
42 /**
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)
62 * Supports reset().
65 class WvBackslashDecoder : public WvEncoder
67 enum State
68 { Initial, Escape, Hex1, Hex2, Octal1, Octal2, Octal3 };
69 State state;
70 WvInPlaceBuf tmpbuf;
71 int value;
73 public:
74 /** Creates a C-style backslash decoder. */
75 WvBackslashDecoder();
76 virtual ~WvBackslashDecoder() { }
78 protected:
79 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush);
80 virtual bool _reset();
82 private:
83 bool flushtmpbuf(WvBuf &outbuf);
86 #endif // __WVBACKSLASH_H