aboutsummaryrefslogtreecommitdiff
path: root/src/strfilter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/strfilter.h')
-rw-r--r--src/strfilter.h124
1 files changed, 124 insertions, 0 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