summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-10-23 17:08:48 +0000
committerMike Buland <eichlan@xagasoft.com>2011-10-23 17:08:48 +0000
commit27c2cbbbc0ed1e1b38274261c33b0427f976f22c (patch)
tree69343b66b4a98792701843c83995ea461d3382d6 /src
parentda1e0ef0772b078bd295301bd675afdee00d40e9 (diff)
downloadlibbu++-27c2cbbbc0ed1e1b38274261c33b0427f976f22c.tar.gz
libbu++-27c2cbbbc0ed1e1b38274261c33b0427f976f22c.tar.bz2
libbu++-27c2cbbbc0ed1e1b38274261c33b0427f976f22c.tar.xz
libbu++-27c2cbbbc0ed1e1b38274261c33b0427f976f22c.zip
The strfilter.h header has been added, it gives you one call filter access on
strings. encodeStr<Filter>( str ) and decodeStr<Filter>( str ). It's pretty cool, try it out :)
Diffstat (limited to 'src')
-rw-r--r--src/strfilter.h124
-rw-r--r--src/string.h2
2 files changed, 125 insertions, 1 deletions
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 @@
1#ifndef STR_FILTER_H
2#define STR_FILTER_H
3
4#include "bu/string.h"
5#include "bu/membuf.h"
6
7namespace Bu
8{
9 //
10 // Encoders
11 //
12 template<typename tFilter>
13 Bu::String encodeStr( const Bu::String &sIn )
14 {
15 Bu::MemBuf mb;
16 {
17 tFilter fEnc( mb );
18 fEnc.write( sIn.getStr(), sIn.getSize() );
19 }
20 return mb.getString();
21 }
22
23 template<typename tFilter, typename p1t>
24 Bu::String encodeStr( const Bu::String &sIn, p1t p1 )
25 {
26 Bu::MemBuf mb;
27 {
28 tFilter fEnc( mb, p1 );
29 fEnc.write( sIn.getStr(), sIn.getSize() );
30 }
31 return mb.getString();
32 }
33
34 template<typename tFilter, typename p1t, typename p2t>
35 Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2 )
36 {
37 Bu::MemBuf mb;
38 {
39 tFilter fEnc( mb, p1, p2 );
40 fEnc.write( sIn.getStr(), sIn.getSize() );
41 }
42 return mb.getString();
43 }
44
45 template<typename tFilter, typename p1t, typename p2t, typename p3t>
46 Bu::String encodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 )
47 {
48 Bu::MemBuf mb;
49 {
50 tFilter fEnc( mb, p1, p2 );
51 fEnc.write( sIn.getStr(), sIn.getSize() );
52 }
53 return mb.getString();
54 }
55
56 //
57 // Decoders
58 //
59 template<typename tFilter>
60 Bu::String decodeStr( const Bu::String &sIn )
61 {
62 Bu::MemBuf mb( sIn );
63 tFilter fDec( mb );
64 char buf[1024];
65 String sRet;
66 for(;;)
67 {
68 int iRead = fDec.read( buf, 1024 );
69 if( iRead == 0 )
70 return sRet;
71 sRet.append( buf, iRead );
72 }
73 }
74
75 template<typename tFilter, typename p1t>
76 Bu::String decodeStr( const Bu::String &sIn, p1t p1 )
77 {
78 Bu::MemBuf mb( sIn );
79 tFilter fDec( mb, p1 );
80 char buf[1024];
81 String sRet;
82 for(;;)
83 {
84 int iRead = fDec.read( buf, 1024 );
85 if( iRead == 0 )
86 return sRet;
87 sRet.append( buf, iRead );
88 }
89 }
90
91 template<typename tFilter, typename p1t, typename p2t>
92 Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2 )
93 {
94 Bu::MemBuf mb( sIn );
95 tFilter fDec( mb, p1, p2 );
96 char buf[1024];
97 String sRet;
98 for(;;)
99 {
100 int iRead = fDec.read( buf, 1024 );
101 if( iRead == 0 )
102 return sRet;
103 sRet.append( buf, iRead );
104 }
105 }
106
107 template<typename tFilter, typename p1t, typename p2t, typename p3t>
108 Bu::String decodeStr( const Bu::String &sIn, p1t p1, p2t p2, p3t p3 )
109 {
110 Bu::MemBuf mb( sIn );
111 tFilter fDec( mb, p1, p2, p3 );
112 char buf[1024];
113 String sRet;
114 for(;;)
115 {
116 int iRead = fDec.read( buf, 1024 );
117 if( iRead == 0 )
118 return sRet;
119 sRet.append( buf, iRead );
120 }
121 }
122};
123
124#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 @@
18#include "bu/list.h" 18#include "bu/list.h"
19#include "bu/fmt.h" 19#include "bu/fmt.h"
20#include "bu/variant.h" 20#include "bu/variant.h"
21
22#include <string.h> 21#include <string.h>
23 22
24namespace Bu 23namespace Bu
25{ 24{
26 class String; 25 class String;
26 class MemBuf;
27 27
28 /** @cond DEVEL */ 28 /** @cond DEVEL */
29 class StringCore 29 class StringCore