diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
commit | 74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch) | |
tree | 843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /c++-libbu++/src/string.cpp | |
parent | d9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff) | |
download | libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2 libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip |
Made the repo less libbu++-centric.
Diffstat (limited to 'c++-libbu++/src/string.cpp')
-rw-r--r-- | c++-libbu++/src/string.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/c++-libbu++/src/string.cpp b/c++-libbu++/src/string.cpp new file mode 100644 index 0000000..de66d5d --- /dev/null +++ b/c++-libbu++/src/string.cpp | |||
@@ -0,0 +1,70 @@ | |||
1 | #include "gats/string.h" | ||
2 | |||
3 | #include "gats/integer.h" | ||
4 | |||
5 | #include <bu/formatter.h> | ||
6 | |||
7 | Gats::String::String() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Gats::String::String( const char *s ) : | ||
12 | Bu::String( s ) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Gats::String::String( const char *s, long iLength ) : | ||
17 | Bu::String( s, iLength ) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | Gats::String::String( long iLength ) : | ||
22 | Bu::String( iLength ) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | Gats::String::String( const String &s ) : | ||
27 | Bu::String( s ) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | Gats::String::String( const Bu::String &s ) : | ||
32 | Bu::String( s ) | ||
33 | { | ||
34 | } | ||
35 | |||
36 | Gats::String::~String() | ||
37 | { | ||
38 | } | ||
39 | |||
40 | Gats::Object *Gats::String::clone() const | ||
41 | { | ||
42 | return new Gats::String( Bu::String::clone() ); | ||
43 | } | ||
44 | |||
45 | void Gats::String::write( Bu::Stream &rOut ) const | ||
46 | { | ||
47 | rOut.write("s", 1 ); | ||
48 | uint32_t iSize = getSize(); | ||
49 | Gats::Integer::writePackedInt( rOut, iSize ); | ||
50 | rOut.write( getStr(), iSize ); | ||
51 | } | ||
52 | |||
53 | void Gats::String::read( Bu::Stream &rIn, char cType ) | ||
54 | { | ||
55 | uint32_t iSize; | ||
56 | Gats::Integer::readPackedInt( rIn, iSize ); | ||
57 | setSize( iSize ); | ||
58 | rIn.read( getStr(), iSize ); | ||
59 | } | ||
60 | |||
61 | Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::String &s ) | ||
62 | { | ||
63 | for( Gats::String::const_iterator i = s.begin(); i; i++ ) | ||
64 | { | ||
65 | if( *i >= 127 || *i <= 31 ) | ||
66 | return f << "(binary str) " << s.getSize() << " bytes"; | ||
67 | } | ||
68 | return f << "(str) \"" << dynamic_cast<const Bu::String &>(s) << "\""; | ||
69 | } | ||
70 | |||