summaryrefslogtreecommitdiff
path: root/src/fstring.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-11 14:55:17 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-11 14:55:17 +0000
commitcb219e9b51f3436b9fb6d63a2c7a05333e4c86ed (patch)
treed05fe35c8d00387c1fb82d162b3058f9017ed455 /src/fstring.cpp
parent4e86c50016ecfea40a72930cdd0460143f9edf4a (diff)
downloadlibbu++-cb219e9b51f3436b9fb6d63a2c7a05333e4c86ed.tar.gz
libbu++-cb219e9b51f3436b9fb6d63a2c7a05333e4c86ed.tar.bz2
libbu++-cb219e9b51f3436b9fb6d63a2c7a05333e4c86ed.tar.xz
libbu++-cb219e9b51f3436b9fb6d63a2c7a05333e4c86ed.zip
Added some more functions to Bu::FBasicString, including a setSize function.
Also added some awesome helpers to Bu::FString in the form of << operators to convert a string to many common types. Handy.
Diffstat (limited to 'src/fstring.cpp')
-rw-r--r--src/fstring.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/fstring.cpp b/src/fstring.cpp
index e4dc716..c9861e0 100644
--- a/src/fstring.cpp
+++ b/src/fstring.cpp
@@ -44,3 +44,93 @@ template<> void Bu::__tracer_format<Bu::FString>( const Bu::FString &v )
44 printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); 44 printf("(%ld)\"%s\"", v.getSize(), v.getStr() );
45} 45}
46 46
47bool &Bu::operator<<( bool &dst, const Bu::FString &sIn )
48{
49 if( sIn == "true" || sIn == "yes" || sIn == "t" )
50 dst = true;
51 else
52 dst = false;
53
54 return dst;
55}
56
57uint8_t &Bu::operator<<( uint8_t &dst, const Bu::FString &sIn )
58{
59 sscanf( sIn.getStr(), "%hhu", &dst );
60 return dst;
61}
62
63int8_t &operator<<( int8_t &dst, const Bu::FString &sIn )
64{
65 sscanf( sIn.getStr(), "%hhd", &dst );
66 return dst;
67}
68
69char &operator<<( char &dst, const Bu::FString &sIn )
70{
71 sscanf( sIn.getStr(), "%hhd", &dst );
72 return dst;
73}
74
75uint16_t &operator<<( uint16_t &dst, const Bu::FString &sIn )
76{
77 sscanf( sIn.getStr(), "%hu", &dst );
78 return dst;
79}
80
81int16_t &operator<<( int16_t &dst, const Bu::FString &sIn )
82{
83 sscanf( sIn.getStr(), "%hd", &dst );
84 return dst;
85}
86
87uint32_t &operator<<( uint32_t &dst, const Bu::FString &sIn )
88{
89 sscanf( sIn.getStr(), "%u", &dst );
90 return dst;
91}
92
93int32_t &operator<<( int32_t &dst, const Bu::FString &sIn )
94{
95 sscanf( sIn.getStr(), "%d", &dst );
96 return dst;
97}
98
99uint64_t &operator<<( uint64_t &dst, const Bu::FString &sIn )
100{
101 sscanf( sIn.getStr(), "%llu", &dst );
102 return dst;
103}
104
105int64_t &operator<<( int64_t &dst, const Bu::FString &sIn )
106{
107 sscanf( sIn.getStr(), "%lld", &dst );
108 return dst;
109}
110
111float &operator<<( float &dst, const Bu::FString &sIn )
112{
113 double tmp;
114 sscanf( sIn.getStr(), "%f", &tmp );
115 dst = tmp;
116 return dst;
117}
118
119double &operator<<( double &dst, const Bu::FString &sIn )
120{
121 sscanf( sIn.getStr(), "%f", &dst );
122 return dst;
123}
124
125long double &operator<<( long double &dst, const Bu::FString &sIn )
126{
127 sscanf( sIn.getStr(), "%Lf", &dst );
128 return dst;
129}
130
131Bu::FString &operator<<( Bu::FString &dst, const Bu::FString &sIn )
132{
133 dst = sIn;
134 return dst;
135}
136