diff options
Diffstat (limited to 'src/unstable/utfstring.cpp')
-rw-r--r-- | src/unstable/utfstring.cpp | 78 |
1 files changed, 64 insertions, 14 deletions
diff --git a/src/unstable/utfstring.cpp b/src/unstable/utfstring.cpp index 1c6813c..9fe2d02 100644 --- a/src/unstable/utfstring.cpp +++ b/src/unstable/utfstring.cpp | |||
@@ -23,10 +23,25 @@ Bu::UtfString::UtfString( const Bu::String &sInput, Encoding eEnc ) | |||
23 | set( sInput, eEnc ); | 23 | set( sInput, eEnc ); |
24 | } | 24 | } |
25 | 25 | ||
26 | Bu::UtfString::UtfString( const char *sInput, Encoding eEnc ) | ||
27 | { | ||
28 | set( sInput, eEnc ); | ||
29 | } | ||
30 | |||
26 | Bu::UtfString::~UtfString() | 31 | Bu::UtfString::~UtfString() |
27 | { | 32 | { |
28 | } | 33 | } |
29 | 34 | ||
35 | Bu::UtfString::iterator Bu::UtfString::begin() | ||
36 | { | ||
37 | return Bu::UtfString::iterator( this, 0 ); | ||
38 | } | ||
39 | |||
40 | Bu::UtfString::const_iterator Bu::UtfString::begin() const | ||
41 | { | ||
42 | return Bu::UtfString::const_iterator( this, 0 ); | ||
43 | } | ||
44 | |||
30 | void Bu::UtfString::set( const Bu::String &sInput, Encoding eEnc ) | 45 | void Bu::UtfString::set( const Bu::String &sInput, Encoding eEnc ) |
31 | { | 46 | { |
32 | switch( eEnc ) | 47 | switch( eEnc ) |
@@ -258,7 +273,7 @@ void Bu::UtfString::setUtf32le( const Bu::String &sInput ) | |||
258 | } | 273 | } |
259 | } | 274 | } |
260 | 275 | ||
261 | void Bu::UtfString::write( Bu::Stream &sOut, Encoding eEnc ) | 276 | void Bu::UtfString::write( Bu::Stream &sOut, Encoding eEnc ) const |
262 | { | 277 | { |
263 | switch( eEnc ) | 278 | switch( eEnc ) |
264 | { | 279 | { |
@@ -306,7 +321,7 @@ void Bu::UtfString::write( Bu::Stream &sOut, Encoding eEnc ) | |||
306 | } | 321 | } |
307 | } | 322 | } |
308 | 323 | ||
309 | void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) | 324 | void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) const |
310 | { | 325 | { |
311 | int iPos = 0; | 326 | int iPos = 0; |
312 | while( iPos < aData.getSize() ) | 327 | while( iPos < aData.getSize() ) |
@@ -359,12 +374,12 @@ void Bu::UtfString::writeUtf16( Bu::Stream &sOut ) | |||
359 | { | 374 | { |
360 | } | 375 | } |
361 | */ | 376 | */ |
362 | void Bu::UtfString::writeUtf16be( Bu::Stream &sOut ) | 377 | void Bu::UtfString::writeUtf16be( Bu::Stream &sOut ) const |
363 | { | 378 | { |
364 | #if BYTE_ORDER == BIG_ENDIAN | 379 | #if BYTE_ORDER == BIG_ENDIAN |
365 | uint16_t iTmp = 0xFEFF; // Byte Order Marker | 380 | uint16_t iTmp = 0xFEFF; // Byte Order Marker |
366 | sOut.write( &iTmp, 2 ); | 381 | sOut.write( &iTmp, 2 ); |
367 | for( Array<uint16_t>::iterator i = aData.begin(); i; i++ ) | 382 | for( Array<uint16_t>::const_iterator i = aData.begin(); i; i++ ) |
368 | { | 383 | { |
369 | iTmp = *i; | 384 | iTmp = *i; |
370 | sOut.write( &iTmp, 2 ); | 385 | sOut.write( &iTmp, 2 ); |
@@ -373,7 +388,7 @@ void Bu::UtfString::writeUtf16be( Bu::Stream &sOut ) | |||
373 | uint16_t iTmp = 0xFEFF; // Byte Order Marker | 388 | uint16_t iTmp = 0xFEFF; // Byte Order Marker |
374 | iTmp = (iTmp>>8) | (iTmp<<8); | 389 | iTmp = (iTmp>>8) | (iTmp<<8); |
375 | sOut.write( &iTmp, 2 ); | 390 | sOut.write( &iTmp, 2 ); |
376 | for( Array<uint16_t>::iterator i = aData.begin(); i; i++ ) | 391 | for( Array<uint16_t>::const_iterator i = aData.begin(); i; i++ ) |
377 | { | 392 | { |
378 | iTmp = *i; | 393 | iTmp = *i; |
379 | iTmp = (iTmp>>8) | (iTmp<<8); | 394 | iTmp = (iTmp>>8) | (iTmp<<8); |
@@ -382,12 +397,12 @@ void Bu::UtfString::writeUtf16be( Bu::Stream &sOut ) | |||
382 | #endif | 397 | #endif |
383 | } | 398 | } |
384 | 399 | ||
385 | void Bu::UtfString::writeUtf16le( Bu::Stream &sOut ) | 400 | void Bu::UtfString::writeUtf16le( Bu::Stream &sOut ) const |
386 | { | 401 | { |
387 | #if BYTE_ORDER == LITTLE_ENDIAN | 402 | #if BYTE_ORDER == LITTLE_ENDIAN |
388 | uint16_t iTmp = 0xFEFF; // Byte Order Marker | 403 | uint16_t iTmp = 0xFEFF; // Byte Order Marker |
389 | sOut.write( &iTmp, 2 ); | 404 | sOut.write( &iTmp, 2 ); |
390 | for( Array<uint16_t>::iterator i = aData.begin(); i; i++ ) | 405 | for( Array<uint16_t>::const_iterator i = aData.begin(); i; i++ ) |
391 | { | 406 | { |
392 | iTmp = *i; | 407 | iTmp = *i; |
393 | sOut.write( &iTmp, 2 ); | 408 | sOut.write( &iTmp, 2 ); |
@@ -396,7 +411,7 @@ void Bu::UtfString::writeUtf16le( Bu::Stream &sOut ) | |||
396 | uint16_t iTmp = 0xFEFF; // Byte Order Marker | 411 | uint16_t iTmp = 0xFEFF; // Byte Order Marker |
397 | iTmp = (iTmp>>8) | (iTmp<<8); | 412 | iTmp = (iTmp>>8) | (iTmp<<8); |
398 | sOut.write( &iTmp, 2 ); | 413 | sOut.write( &iTmp, 2 ); |
399 | for( Array<uint16_t>::iterator i = aData.begin(); i; i++ ) | 414 | for( Array<uint16_t>::const_iterator i = aData.begin(); i; i++ ) |
400 | { | 415 | { |
401 | iTmp = *i; | 416 | iTmp = *i; |
402 | iTmp = (iTmp>>8) | (iTmp<<8); | 417 | iTmp = (iTmp>>8) | (iTmp<<8); |
@@ -405,7 +420,7 @@ void Bu::UtfString::writeUtf16le( Bu::Stream &sOut ) | |||
405 | #endif | 420 | #endif |
406 | } | 421 | } |
407 | 422 | ||
408 | void Bu::UtfString::writeUtf32be( Bu::Stream &sOut ) | 423 | void Bu::UtfString::writeUtf32be( Bu::Stream &sOut ) const |
409 | { | 424 | { |
410 | #if BYTE_ORDER == BIG_ENDIAN | 425 | #if BYTE_ORDER == BIG_ENDIAN |
411 | uint32_t iTmp = 0xFEFF; // Byte Order Marker | 426 | uint32_t iTmp = 0xFEFF; // Byte Order Marker |
@@ -430,7 +445,7 @@ void Bu::UtfString::writeUtf32be( Bu::Stream &sOut ) | |||
430 | #endif | 445 | #endif |
431 | } | 446 | } |
432 | 447 | ||
433 | void Bu::UtfString::writeUtf32le( Bu::Stream &sOut ) | 448 | void Bu::UtfString::writeUtf32le( Bu::Stream &sOut ) const |
434 | { | 449 | { |
435 | #if BYTE_ORDER == LITTLE_ENDIAN | 450 | #if BYTE_ORDER == LITTLE_ENDIAN |
436 | uint32_t iTmp = 0xFEFF; // Byte Order Marker | 451 | uint32_t iTmp = 0xFEFF; // Byte Order Marker |
@@ -455,12 +470,12 @@ void Bu::UtfString::writeUtf32le( Bu::Stream &sOut ) | |||
455 | #endif | 470 | #endif |
456 | } | 471 | } |
457 | 472 | ||
458 | Bu::UtfChar Bu::UtfString::get( int iIndex ) | 473 | Bu::UtfChar Bu::UtfString::get( int iIndex ) const |
459 | { | 474 | { |
460 | return nextChar( iIndex ); | 475 | return nextChar( iIndex ); |
461 | } | 476 | } |
462 | 477 | ||
463 | Bu::UtfChar Bu::UtfString::nextChar( int &iIndex ) | 478 | Bu::UtfChar Bu::UtfString::nextChar( int &iIndex ) const |
464 | { | 479 | { |
465 | Bu::UtfChar i = aData[iIndex++]; | 480 | Bu::UtfChar i = aData[iIndex++]; |
466 | switch( i&0xFC00 ) | 481 | switch( i&0xFC00 ) |
@@ -476,14 +491,31 @@ Bu::UtfChar Bu::UtfString::nextChar( int &iIndex ) | |||
476 | } | 491 | } |
477 | } | 492 | } |
478 | 493 | ||
479 | Bu::String Bu::UtfString::get( Encoding eEnc ) | 494 | bool Bu::UtfString::operator==( const Bu::UtfString &rhs ) const |
495 | { | ||
496 | return aData == rhs.aData; | ||
497 | } | ||
498 | |||
499 | Bu::UtfString &Bu::UtfString::operator+=( const Bu::UtfString &rhs ) | ||
500 | { | ||
501 | append( rhs ); | ||
502 | return *this; | ||
503 | } | ||
504 | |||
505 | Bu::UtfString &Bu::UtfString::operator+=( const UtfChar &rhs ) | ||
506 | { | ||
507 | append( rhs ); | ||
508 | return *this; | ||
509 | } | ||
510 | |||
511 | Bu::String Bu::UtfString::get( Encoding eEnc ) const | ||
480 | { | 512 | { |
481 | Bu::MemBuf mb; | 513 | Bu::MemBuf mb; |
482 | write( mb, eEnc ); | 514 | write( mb, eEnc ); |
483 | return mb.getString(); | 515 | return mb.getString(); |
484 | } | 516 | } |
485 | 517 | ||
486 | void Bu::UtfString::debug() | 518 | void Bu::UtfString::debug() const |
487 | { | 519 | { |
488 | sio << "Raw Utf16: "; | 520 | sio << "Raw Utf16: "; |
489 | for( int i = 0; i < aData.getSize(); i++ ) | 521 | for( int i = 0; i < aData.getSize(); i++ ) |
@@ -552,3 +584,21 @@ void Bu::UtfString::debugUtf8( const Bu::String &sUtf8 ) | |||
552 | sio << sio.nl; | 584 | sio << sio.nl; |
553 | } | 585 | } |
554 | */ | 586 | */ |
587 | |||
588 | template<> uint32_t Bu::__calcHashCode<Bu::UtfString>( const Bu::UtfString &k ) | ||
589 | { | ||
590 | uint32_t uCode = 0; | ||
591 | |||
592 | for( Bu::UtfString::const_iterator i = k.begin(); i; i++ ) | ||
593 | { | ||
594 | uCode = *i + (uCode<<6) + (uCode<<16) - uCode; | ||
595 | } | ||
596 | |||
597 | return uCode; | ||
598 | } | ||
599 | |||
600 | template<> bool Bu::__cmpHashKeys<Bu::UtfString>( | ||
601 | const Bu::UtfString &a, const Bu::UtfString &b ) | ||
602 | { | ||
603 | return a == b; | ||
604 | } | ||