aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-12-12 08:13:34 +0000
committerMike Buland <eichlan@xagasoft.com>2008-12-12 08:13:34 +0000
commit7c8e31fc057859d08610f17f669fdfcaf2fc2956 (patch)
tree2d645e85abab60a40091f3e676fcae78fe477148 /src
parenta36df989b1a603474345d792a1f9bc7d375a59ef (diff)
downloadlibbu++-7c8e31fc057859d08610f17f669fdfcaf2fc2956.tar.gz
libbu++-7c8e31fc057859d08610f17f669fdfcaf2fc2956.tar.bz2
libbu++-7c8e31fc057859d08610f17f669fdfcaf2fc2956.tar.xz
libbu++-7c8e31fc057859d08610f17f669fdfcaf2fc2956.zip
All of those changes I thought I'd already committed. The taf writer handles
binary data much better, actually escaping it properly and not stopping on null. Bu::FString has an iterator, it's actually just a raw datatype, but it may have more function later, so careful assuming that it's a char and using it in any non-iterator like way. Also augmented the taf unit test, and added the Bu::CacheCalc base class, the rest of the simple develpment cycle will happen between here and project hhp.
Diffstat (limited to '')
-rw-r--r--src/cachecalc.cpp1
-rw-r--r--src/cachecalc.h22
-rw-r--r--src/fstring.h25
-rw-r--r--src/tafwriter.cpp8
-rw-r--r--src/unit/taf.cpp47
5 files changed, 102 insertions, 1 deletions
diff --git a/src/cachecalc.cpp b/src/cachecalc.cpp
new file mode 100644
index 0000000..0080735
--- /dev/null
+++ b/src/cachecalc.cpp
@@ -0,0 +1 @@
#include "bu/cachecalc.h"
diff --git a/src/cachecalc.h b/src/cachecalc.h
new file mode 100644
index 0000000..9e83b06
--- /dev/null
+++ b/src/cachecalc.h
@@ -0,0 +1,22 @@
1#ifndef BU_CACHE_CALC_H
2#define BU_CACHE_CALC_H
3
4namespace Bu
5{
6 template<class type>
7 class CacheCalc
8 {
9 public:
10 CacheCalc()
11 {
12 }
13
14 virtual ~CacheCalc()
15 {
16 }
17
18 private:
19 };
20};
21
22#endif
diff --git a/src/fstring.h b/src/fstring.h
index 167c055..91251bc 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -916,6 +916,31 @@ namespace Bu
916 } 916 }
917 } 917 }
918 918
919 typedef chr *iterator;
920 typedef const chr *const_iterator;
921
922 iterator begin()
923 {
924 flatten();
925 return pFirst->pData;
926 }
927
928 const_iterator begin() const
929 {
930 flatten();
931 return pFirst->pData;
932 }
933
934 iterator end()
935 {
936 return pFirst->pData+pFirst->nLength;
937 }
938
939 const_iterator end() const
940 {
941 return pFirst->pData+pFirst->nLength;
942 }
943
919 private: 944 private:
920 void flatten() const 945 void flatten() const
921 { 946 {
diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp
index c30bc67..8e5fcdc 100644
--- a/src/tafwriter.cpp
+++ b/src/tafwriter.cpp
@@ -93,12 +93,18 @@ void Bu::TafWriter::writeString( const Bu::FString &str )
93 if( str.getStr() == NULL ) 93 if( str.getStr() == NULL )
94 return; 94 return;
95 sOut.write("\"", 1 ); 95 sOut.write("\"", 1 );
96 for( const char *s = str.getStr(); *s; s++ ) 96 for( Bu::FString::const_iterator s = str.begin(); s != str.end(); s++ )
97 { 97 {
98 if( *s == '\"' ) 98 if( *s == '\"' )
99 sOut.write("\\\"", 2 ); 99 sOut.write("\\\"", 2 );
100 else if( *s == '\\' ) 100 else if( *s == '\\' )
101 sOut.write("\\\\", 2 ); 101 sOut.write("\\\\", 2 );
102 else if( *s < 32 || *s > 126 )
103 {
104 char buf[5];
105 sprintf( buf, "\\x%02X", (unsigned char)*s );
106 sOut.write(buf, 4 );
107 }
102 else 108 else
103 sOut.write( s, 1 ); 109 sOut.write( s, 1 );
104 } 110 }
diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp
index 71bd867..0813444 100644
--- a/src/unit/taf.cpp
+++ b/src/unit/taf.cpp
@@ -8,6 +8,8 @@
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/file.h" 9#include "bu/file.h"
10#include "bu/tafreader.h" 10#include "bu/tafreader.h"
11#include "bu/tafwriter.h"
12#include "bu/membuf.h"
11 13
12#include <string.h> 14#include <string.h>
13#include <unistd.h> 15#include <unistd.h>
@@ -19,6 +21,7 @@ public:
19 { 21 {
20 setName("taf"); 22 setName("taf");
21 addTest( Unit::read1 ); 23 addTest( Unit::read1 );
24 addTest( Unit::encode );
22 } 25 }
23 26
24 virtual ~Unit() 27 virtual ~Unit()
@@ -46,6 +49,50 @@ public:
46 unlink(sFnTmp.getStr()); 49 unlink(sFnTmp.getStr());
47#undef FN_TMP 50#undef FN_TMP
48 } 51 }
52
53 void encode()
54 {
55 Bu::MemBuf mb;
56 Bu::TafWriter tw( mb );
57
58 Bu::TafGroup g("Test data");
59 Bu::FString sData( 256 );
60 for( int j = 0; j < 256; j++ )
61 sData[j] = (unsigned char)j;
62 g.addChild( new Bu::TafProperty("Encoded", sData) );
63 tw.writeGroup( &g );
64
65 static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\""
66 "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07"
67 "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F"
68 "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17"
69 "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F"
70 " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD"
71 "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi"
72 "jklmnopqrstuvwxyz{|}~\\x7F"
73 "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87"
74 "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F"
75 "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97"
76 "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F"
77 "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7"
78 "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF"
79 "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7"
80 "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF"
81 "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7"
82 "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF"
83 "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7"
84 "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF"
85 "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7"
86 "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF"
87 "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7"
88 "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n";
89 unitTest( mb.getString() == cmpdata );
90 mb.setPos( 0 );
91 Bu::TafReader tr( mb );
92 Bu::TafGroup *rg = tr.readGroup();
93 unitTest( rg->getProperty("Encoded") == sData );
94 delete rg;
95 }
49}; 96};
50 97
51int main( int argc, char *argv[] ) 98int main( int argc, char *argv[] )