Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvbackslash.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 2002 Net Integration Technologies, Inc. 00004 * 00005 * C-style backslash escaping and unescaping of strings. 00006 */ 00007 #ifndef __WVBACKSLASH_H 00008 #define __WVBACKSLASH_H 00009 00010 #include "wvencoder.h" 00011 00012 /** 00013 * An encoder that performs C-style backslash escaping of strings. 00014 * 00015 * Use this to escape control characters, unprintable characters, 00016 * and optionally quotes or any other special printable characters 00017 * into sequences of the form \\n, \\xFF, \\", etc... 00018 * 00019 * Supports reset(). 00020 * 00021 */ 00022 class WvBackslashEncoder : public WvEncoder 00023 { 00024 WvString nasties; 00025 00026 public: 00027 /** 00028 * Creates a C-style backslash encoder. 00029 * nasties - the set of printable characters to escape 00030 * in addition to the non-printable ones 00031 * (should always contain at least backslash) 00032 */ 00033 WvBackslashEncoder(WvStringParm _nasties = "\\\""); 00034 virtual ~WvBackslashEncoder() { } 00035 00036 protected: 00037 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush); 00038 virtual bool _reset(); 00039 }; 00040 00041 00042 /** 00043 * An encoder that performs C-style backslash unescaping of strings. 00044 * 00045 * Recognizes the following sequences preceeded by backslash: 00046 * 00047 * - a: substitutes alarm bell (ascii 7) 00048 * - b: substitutes backspace (ascii 8) 00049 * - f: substitutes formfeed (ascii 12) 00050 * - n: substitutes newline (ascii 10) 00051 * - r: substitutes carriage return (ascii 13) 00052 * - t: substitutes tab (ascii 9) 00053 * - v: substitutes vertical tab (ascii 11) 00054 * - 0: substitutes null (ascii 0) 00055 * - 0xyz: substitutes character with octal encoding xyz 00056 * - xxy: substitutes character with hex encoding xy 00057 * - newline: substitutes space (line continuation sequence) 00058 * - \\: substitutes backslash 00059 * - otherwise substitutes the next character (strips the backslash) 00060 * 00061 * 00062 * Supports reset(). 00063 * 00064 */ 00065 class WvBackslashDecoder : public WvEncoder 00066 { 00067 enum State 00068 { Initial, Escape, Hex1, Hex2, Octal1, Octal2, Octal3 }; 00069 State state; 00070 WvInPlaceBuf tmpbuf; 00071 int value; 00072 00073 public: 00074 /** Creates a C-style backslash decoder. */ 00075 WvBackslashDecoder(); 00076 virtual ~WvBackslashDecoder() { } 00077 00078 protected: 00079 virtual bool _encode(WvBuf &inbuf, WvBuf &outbuf, bool flush); 00080 virtual bool _reset(); 00081 00082 private: 00083 bool flushtmpbuf(WvBuf &outbuf); 00084 }; 00085 00086 #endif // __WVBACKSLASH_H

Generated on Tue Oct 5 01:09:19 2004 for WvStreams by doxygen 1.3.7