aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/utfstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unstable/utfstring.cpp')
-rw-r--r--src/unstable/utfstring.cpp55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/unstable/utfstring.cpp b/src/unstable/utfstring.cpp
index 21b3f82..6217f80 100644
--- a/src/unstable/utfstring.cpp
+++ b/src/unstable/utfstring.cpp
@@ -8,6 +8,7 @@
8#include "bu/utfstring.h" 8#include "bu/utfstring.h"
9 9
10#include "bu/string.h" 10#include "bu/string.h"
11#include "bu/blob.h"
11#include "bu/stream.h" 12#include "bu/stream.h"
12#include "bu/config.h" 13#include "bu/config.h"
13#include "bu/sio.h" 14#include "bu/sio.h"
@@ -36,11 +37,16 @@ Bu::UtfString::UtfString( const Bu::String &sInput, Encoding eEnc )
36 set( sInput, eEnc ); 37 set( sInput, eEnc );
37} 38}
38 39
39Bu::UtfString::UtfString( const char *sInput, Encoding eEnc ) 40Bu::UtfString::UtfString( const Bu::Blob &sInput, Encoding eEnc )
40{ 41{
41 set( sInput, eEnc ); 42 set( sInput, eEnc );
42} 43}
43 44
45Bu::UtfString::UtfString( const char *sInput, Encoding eEnc )
46{
47 set( Bu::Blob(sInput), eEnc );
48}
49
44Bu::UtfString::~UtfString() 50Bu::UtfString::~UtfString()
45{ 51{
46} 52}
@@ -57,6 +63,11 @@ Bu::UtfString::const_iterator Bu::UtfString::begin() const
57 63
58void Bu::UtfString::set( const Bu::String &sInput, Encoding eEnc ) 64void Bu::UtfString::set( const Bu::String &sInput, Encoding eEnc )
59{ 65{
66 set( sInput, eEnc );
67}
68
69void Bu::UtfString::set( const Bu::Blob &sInput, Encoding eEnc )
70{
60 switch( eEnc ) 71 switch( eEnc )
61 { 72 {
62 case Utf8: 73 case Utf8:
@@ -122,9 +133,9 @@ void Bu::UtfString::append( const UtfString &rSrc )
122 iCharLen += rSrc.iCharLen; 133 iCharLen += rSrc.iCharLen;
123} 134}
124 135
125void Bu::UtfString::setUtf8( const Bu::String &sInput ) 136void Bu::UtfString::setUtf8( const Bu::Blob &sInput )
126{ 137{
127 for( Bu::String::const_iterator i = sInput.begin(); i; i++ ) 138 for( Bu::Blob::const_iterator i = sInput.begin(); i; i++ )
128 { 139 {
129 if( ((int)(uint8_t)*i)&0x80 ) 140 if( ((int)(uint8_t)*i)&0x80 )
130 { 141 {
@@ -145,9 +156,9 @@ void Bu::UtfString::setUtf8( const Bu::String &sInput )
145 } 156 }
146} 157}
147 158
148void Bu::UtfString::setUtf16( const Bu::String &sInput ) 159void Bu::UtfString::setUtf16( const Bu::Blob &sInput )
149{ 160{
150// Bu::String::const_iterator i = sInput.begin(); 161// Bu::Blob::const_iterator i = sInput.begin();
151 if( (uint8_t)*sInput.begin() == 0xFF && 162 if( (uint8_t)*sInput.begin() == 0xFF &&
152 (uint8_t)*(sInput.begin()+1) == 0xFE ) 163 (uint8_t)*(sInput.begin()+1) == 0xFE )
153 { 164 {
@@ -157,9 +168,9 @@ void Bu::UtfString::setUtf16( const Bu::String &sInput )
157 setUtf16be( sInput ); 168 setUtf16be( sInput );
158} 169}
159 170
160void Bu::UtfString::setUtf16be( const Bu::String &sInput ) 171void Bu::UtfString::setUtf16be( const Bu::Blob &sInput )
161{ 172{
162 Bu::String::const_iterator i = sInput.begin(); 173 Bu::Blob::const_iterator i = sInput.begin();
163 if( (uint8_t)*sInput.begin() == 0xFE && 174 if( (uint8_t)*sInput.begin() == 0xFE &&
164 (uint8_t)*(sInput.begin()+1) == 0xFF ) 175 (uint8_t)*(sInput.begin()+1) == 0xFF )
165 176
@@ -184,9 +195,9 @@ void Bu::UtfString::setUtf16be( const Bu::String &sInput )
184 } 195 }
185} 196}
186 197
187void Bu::UtfString::setUtf16le( const Bu::String &sInput ) 198void Bu::UtfString::setUtf16le( const Bu::Blob &sInput )
188{ 199{
189 Bu::String::const_iterator i = sInput.begin(); 200 Bu::Blob::const_iterator i = sInput.begin();
190 if( (uint8_t)*sInput.begin() == 0xFF && 201 if( (uint8_t)*sInput.begin() == 0xFF &&
191 (uint8_t)*(sInput.begin()+1) == 0xFE ) 202 (uint8_t)*(sInput.begin()+1) == 0xFE )
192 { 203 {
@@ -210,9 +221,9 @@ void Bu::UtfString::setUtf16le( const Bu::String &sInput )
210 } 221 }
211} 222}
212 223
213void Bu::UtfString::setUtf32( const Bu::String &sInput ) 224void Bu::UtfString::setUtf32( const Bu::Blob &sInput )
214{ 225{
215 Bu::String::const_iterator i = sInput.begin(); 226 Bu::Blob::const_iterator i = sInput.begin();
216 if( (uint8_t)*i == 0x00 && 227 if( (uint8_t)*i == 0x00 &&
217 (uint8_t)*(++i) == 0x00 && 228 (uint8_t)*(++i) == 0x00 &&
218 (uint8_t)*(++i) == 0xFF && 229 (uint8_t)*(++i) == 0xFF &&
@@ -224,9 +235,9 @@ void Bu::UtfString::setUtf32( const Bu::String &sInput )
224 setUtf32be( sInput ); 235 setUtf32be( sInput );
225} 236}
226 237
227void Bu::UtfString::setUtf32be( const Bu::String &sInput ) 238void Bu::UtfString::setUtf32be( const Bu::Blob &sInput )
228{ 239{
229 Bu::String::const_iterator i = sInput.begin(); 240 Bu::Blob::const_iterator i = sInput.begin();
230 if( (uint8_t)*i == 0x00 && 241 if( (uint8_t)*i == 0x00 &&
231 (uint8_t)*(++i) == 0x00 && 242 (uint8_t)*(++i) == 0x00 &&
232 (uint8_t)*(++i) == 0xFE && 243 (uint8_t)*(++i) == 0xFE &&
@@ -250,9 +261,9 @@ void Bu::UtfString::setUtf32be( const Bu::String &sInput )
250 } 261 }
251} 262}
252 263
253void Bu::UtfString::setUtf32le( const Bu::String &sInput ) 264void Bu::UtfString::setUtf32le( const Bu::Blob &sInput )
254{ 265{
255 Bu::String::const_iterator i = sInput.begin(); 266 Bu::Blob::const_iterator i = sInput.begin();
256 if( (uint8_t)*i == 0x00 && 267 if( (uint8_t)*i == 0x00 &&
257 (uint8_t)*(++i) == 0x00 && 268 (uint8_t)*(++i) == 0x00 &&
258 (uint8_t)*(++i) == 0xFF && 269 (uint8_t)*(++i) == 0xFF &&
@@ -443,12 +454,12 @@ int Bu::UtfString::writePoint( Bu::Stream &sOut, const Bu::UtfChar &c,
443 454
444int32_t Bu::UtfString::toInt32( int iRadix ) const 455int32_t Bu::UtfString::toInt32( int iRadix ) const
445{ 456{
446 return strtol( get().getStr(), NULL, iRadix ); 457 return strtol( get().getData(), NULL, iRadix );
447} 458}
448 459
449int64_t Bu::UtfString::toInt64( int iRadix ) const 460int64_t Bu::UtfString::toInt64( int iRadix ) const
450{ 461{
451 return strtoll( get().getStr(), NULL, iRadix ); 462 return strtoll( get().getData(), NULL, iRadix );
452} 463}
453 464
454void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) const 465void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) const
@@ -626,7 +637,7 @@ bool Bu::UtfString::operator==( const Bu::UtfString &rhs ) const
626 return aData == rhs.aData; 637 return aData == rhs.aData;
627} 638}
628 639
629bool Bu::UtfString::operator==( const Bu::String &rhs ) const 640bool Bu::UtfString::operator==( const Bu::Blob &rhs ) const
630{ 641{
631 // Nieve comparison 642 // Nieve comparison
632 if( aData.getSize() != rhs.getSize() ) 643 if( aData.getSize() != rhs.getSize() )
@@ -718,11 +729,11 @@ bool Bu::UtfString::operator>=( const Bu::UtfString &rhs ) const
718 return false; 729 return false;
719} 730}
720 731
721Bu::String Bu::UtfString::get( Encoding eEnc ) const 732Bu::Blob Bu::UtfString::get( Encoding eEnc ) const
722{ 733{
723 Bu::MemBuf mb; 734 Bu::MemBuf mb;
724 write( mb, eEnc ); 735 write( mb, eEnc );
725 return mb.getString(); 736 return Bu::Blob( mb.getString().getStr(), mb.getString().getSize() );
726} 737}
727 738
728void Bu::UtfString::debug() const 739void Bu::UtfString::debug() const
@@ -745,9 +756,9 @@ void Bu::UtfString::debug() const
745 sio << sio.nl; 756 sio << sio.nl;
746} 757}
747/* 758/*
748void Bu::UtfString::debugUtf8( const Bu::String &sUtf8 ) 759void Bu::UtfString::debugUtf8( const Bu::Blob &sUtf8 )
749{ 760{
750 for( Bu::String::const_iterator i = sUtf8.begin(); i; i++ ) 761 for( Bu::Blob::const_iterator i = sUtf8.begin(); i; i++ )
751 { 762 {
752 if( i != sUtf8.begin() ) 763 if( i != sUtf8.begin() )
753 sio << ", "; 764 sio << ", ";