From 27c2cbbbc0ed1e1b38274261c33b0427f976f22c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 23 Oct 2011 17:08:48 +0000 Subject: The strfilter.h header has been added, it gives you one call filter access on strings. encodeStr( str ) and decodeStr( str ). It's pretty cool, try it out :) --- src/strfilter.h | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/string.h | 2 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/strfilter.h (limited to 'src') diff --git a/src/strfilter.h b/src/strfilter.h new file mode 100644 index 0000000..8da0a3f --- /dev/null +++ b/src/strfilter.h @@ -0,0 +1,124 @@ +#ifndef STR_FILTER_H +#define STR_FILTER_H + +#include "bu/string.h" +#include "bu/membuf.h" + +namespace Bu +{ + // + // Encoders + // + template + Bu::String encodeStr( const Bu::String &sIn ) + { + Bu::MemBuf mb; + { + tFilter fEnc( mb ); + fEnc.write( sIn.getStr(), sIn.getSize() ); + } + return mb.getString(); + } + + template + Bu::String encodeStr( const Bu::String &sIn, p1t p1 ) + { + Bu::MemBuf mb; + { + tFilter fEnc( mb, p1 ); + fEnc.write( sIn.getStr(), sIn.getSize() ); + } + return mb.getString(); + } + + template + Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2 ) + { + Bu::MemBuf mb; + { + tFilter fEnc( mb, p1, p2 ); + fEnc.write( sIn.getStr(), sIn.getSize() ); + } + return mb.getString(); + } + + template + Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 ) + { + Bu::MemBuf mb; + { + tFilter fEnc( mb, p1, p2 ); + fEnc.write( sIn.getStr(), sIn.getSize() ); + } + return mb.getString(); + } + + // + // Decoders + // + template + Bu::String decodeStr( const Bu::String &sIn ) + { + Bu::MemBuf mb( sIn ); + tFilter fDec( mb ); + char buf[1024]; + String sRet; + for(;;) + { + int iRead = fDec.read( buf, 1024 ); + if( iRead == 0 ) + return sRet; + sRet.append( buf, iRead ); + } + } + + template + Bu::String decodeStr( const Bu::String &sIn, p1t p1 ) + { + Bu::MemBuf mb( sIn ); + tFilter fDec( mb, p1 ); + char buf[1024]; + String sRet; + for(;;) + { + int iRead = fDec.read( buf, 1024 ); + if( iRead == 0 ) + return sRet; + sRet.append( buf, iRead ); + } + } + + template + Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2 ) + { + Bu::MemBuf mb( sIn ); + tFilter fDec( mb, p1, p2 ); + char buf[1024]; + String sRet; + for(;;) + { + int iRead = fDec.read( buf, 1024 ); + if( iRead == 0 ) + return sRet; + sRet.append( buf, iRead ); + } + } + + template + Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 ) + { + Bu::MemBuf mb( sIn ); + tFilter fDec( mb, p1, p2, p3 ); + char buf[1024]; + String sRet; + for(;;) + { + int iRead = fDec.read( buf, 1024 ); + if( iRead == 0 ) + return sRet; + sRet.append( buf, iRead ); + } + } +}; + +#endif diff --git a/src/string.h b/src/string.h index 2874e37..a9006d1 100644 --- a/src/string.h +++ b/src/string.h @@ -18,12 +18,12 @@ #include "bu/list.h" #include "bu/fmt.h" #include "bu/variant.h" - #include namespace Bu { class String; + class MemBuf; /** @cond DEVEL */ class StringCore -- cgit v1.2.3