WvStreams
wvbackslash.h
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 
00022 class WvBackslashEncoder : public WvEncoder
00023 {
00024     WvString nasties;
00025 
00026 public:
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 
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:
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