summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 02:14:08 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 02:14:08 +0000
commitf5aca1a1b402bd7ebc944dc6e6fe65828d863365 (patch)
tree4a0fdd8e166d5c4b03543279d332b9a858ef62df /src/string.cpp
parent10c557562e1d67c55314c212371ea9cb7f802863 (diff)
downloadlibbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.gz
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.bz2
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.tar.xz
libbu++-f5aca1a1b402bd7ebc944dc6e6fe65828d863365.zip
Bu::FString is now String, and there's a shell script to fix any other programs
that were using fstring, I hope.
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp
new file mode 100644
index 0000000..3f895dc
--- /dev/null
+++ b/src/string.cpp
@@ -0,0 +1,128 @@
1/*
2 * Copyright (C) 2007-2010 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#define BU_TRACE
9#include "bu/trace.h"
10
11#include "bu/string.h"
12#include "bu/hash.h"
13
14template class Bu::BasicString<char>;
15
16template<> uint32_t Bu::__calcHashCode<Bu::String>( const Bu::String &k )
17{
18 long j, sz = k.getSize();
19 const char *s = k.getStr();
20
21 long nPos = 0;
22 for( j = 0; j < sz; j++, s++ )
23 {
24 nPos = *s + (nPos << 6) + (nPos << 16) - nPos;
25 }
26
27 return nPos;
28}
29
30template<> bool Bu::__cmpHashKeys<Bu::String>(
31 const Bu::String &a, const Bu::String &b )
32{
33 return a == b;
34}
35
36template<> void Bu::__tracer_format<Bu::String>( const Bu::String &v )
37{
38 printf("(%ld)\"%s\"", v.getSize(), v.getStr() );
39}
40
41bool &Bu::operator<<( bool &dst, const Bu::String &sIn )
42{
43 if( sIn == "true" || sIn == "yes" || sIn == "t" )
44 dst = true;
45 else
46 dst = false;
47
48 return dst;
49}
50
51uint8_t &Bu::operator<<( uint8_t &dst, const Bu::String &sIn )
52{
53 sscanf( sIn.getStr(), "%hhu", &dst );
54 return dst;
55}
56
57int8_t &Bu::operator<<( int8_t &dst, const Bu::String &sIn )
58{
59 sscanf( sIn.getStr(), "%hhd", &dst );
60 return dst;
61}
62
63char &Bu::operator<<( char &dst, const Bu::String &sIn )
64{
65 sscanf( sIn.getStr(), "%hhd", &dst );
66 return dst;
67}
68
69uint16_t &Bu::operator<<( uint16_t &dst, const Bu::String &sIn )
70{
71 sscanf( sIn.getStr(), "%hu", &dst );
72 return dst;
73}
74
75int16_t &Bu::operator<<( int16_t &dst, const Bu::String &sIn )
76{
77 sscanf( sIn.getStr(), "%hd", &dst );
78 return dst;
79}
80
81uint32_t &Bu::operator<<( uint32_t &dst, const Bu::String &sIn )
82{
83 sscanf( sIn.getStr(), "%u", &dst );
84 return dst;
85}
86
87int32_t &Bu::operator<<( int32_t &dst, const Bu::String &sIn )
88{
89 sscanf( sIn.getStr(), "%d", &dst );
90 return dst;
91}
92
93uint64_t &Bu::operator<<( uint64_t &dst, const Bu::String &sIn )
94{
95 sscanf( sIn.getStr(), "%llu", &dst );
96 return dst;
97}
98
99int64_t &Bu::operator<<( int64_t &dst, const Bu::String &sIn )
100{
101 sscanf( sIn.getStr(), "%lld", &dst );
102 return dst;
103}
104
105float &Bu::operator<<( float &dst, const Bu::String &sIn )
106{
107 sscanf( sIn.getStr(), "%f", &dst );
108 return dst;
109}
110
111double &Bu::operator<<( double &dst, const Bu::String &sIn )
112{
113 sscanf( sIn.getStr(), "%lf", &dst );
114 return dst;
115}
116
117long double &Bu::operator<<( long double &dst, const Bu::String &sIn )
118{
119 sscanf( sIn.getStr(), "%Lf", &dst );
120 return dst;
121}
122
123Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn )
124{
125 dst = sIn;
126 return dst;
127}
128