summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-01-20 18:09:04 +0000
committerMike Buland <eichlan@xagasoft.com>2011-01-20 18:09:04 +0000
commit393f1b414746a7f1977971dd7659dd2b47092b11 (patch)
tree81d0ca1ee70ab86a7d79c1991abe5c387b655fb2 /src/string.cpp
parentc259f95bd0e58b247940a339bb9b4b401b4e9438 (diff)
parent7e25a863325dc3e9762397e700030969e093b087 (diff)
downloadlibbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.gz
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.bz2
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.tar.xz
libbu++-393f1b414746a7f1977971dd7659dd2b47092b11.zip
Wow! Merged the branch, streams are updated, and there's no more FString, run
the fixstrings.sh script in the support directory to (hopefully) automatically update your projects.
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..538ac52
--- /dev/null
+++ b/src/string.cpp
@@ -0,0 +1,128 @@
1/*
2 * Copyright (C) 2007-2011 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