From e1115a28535663cfe404791ede5bb7ca70399053 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 24 Apr 2023 09:16:32 -0700 Subject: Additions to blob/utfstring for json. --- src/unstable/utfstring.cpp | 55 +++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'src/unstable/utfstring.cpp') 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 @@ #include "bu/utfstring.h" #include "bu/string.h" +#include "bu/blob.h" #include "bu/stream.h" #include "bu/config.h" #include "bu/sio.h" @@ -36,11 +37,16 @@ Bu::UtfString::UtfString( const Bu::String &sInput, Encoding eEnc ) set( sInput, eEnc ); } -Bu::UtfString::UtfString( const char *sInput, Encoding eEnc ) +Bu::UtfString::UtfString( const Bu::Blob &sInput, Encoding eEnc ) { set( sInput, eEnc ); } +Bu::UtfString::UtfString( const char *sInput, Encoding eEnc ) +{ + set( Bu::Blob(sInput), eEnc ); +} + Bu::UtfString::~UtfString() { } @@ -56,6 +62,11 @@ Bu::UtfString::const_iterator Bu::UtfString::begin() const } void Bu::UtfString::set( const Bu::String &sInput, Encoding eEnc ) +{ + set( sInput, eEnc ); +} + +void Bu::UtfString::set( const Bu::Blob &sInput, Encoding eEnc ) { switch( eEnc ) { @@ -122,9 +133,9 @@ void Bu::UtfString::append( const UtfString &rSrc ) iCharLen += rSrc.iCharLen; } -void Bu::UtfString::setUtf8( const Bu::String &sInput ) +void Bu::UtfString::setUtf8( const Bu::Blob &sInput ) { - for( Bu::String::const_iterator i = sInput.begin(); i; i++ ) + for( Bu::Blob::const_iterator i = sInput.begin(); i; i++ ) { if( ((int)(uint8_t)*i)&0x80 ) { @@ -145,9 +156,9 @@ void Bu::UtfString::setUtf8( const Bu::String &sInput ) } } -void Bu::UtfString::setUtf16( const Bu::String &sInput ) +void Bu::UtfString::setUtf16( const Bu::Blob &sInput ) { -// Bu::String::const_iterator i = sInput.begin(); +// Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*sInput.begin() == 0xFF && (uint8_t)*(sInput.begin()+1) == 0xFE ) { @@ -157,9 +168,9 @@ void Bu::UtfString::setUtf16( const Bu::String &sInput ) setUtf16be( sInput ); } -void Bu::UtfString::setUtf16be( const Bu::String &sInput ) +void Bu::UtfString::setUtf16be( const Bu::Blob &sInput ) { - Bu::String::const_iterator i = sInput.begin(); + Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*sInput.begin() == 0xFE && (uint8_t)*(sInput.begin()+1) == 0xFF ) @@ -184,9 +195,9 @@ void Bu::UtfString::setUtf16be( const Bu::String &sInput ) } } -void Bu::UtfString::setUtf16le( const Bu::String &sInput ) +void Bu::UtfString::setUtf16le( const Bu::Blob &sInput ) { - Bu::String::const_iterator i = sInput.begin(); + Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*sInput.begin() == 0xFF && (uint8_t)*(sInput.begin()+1) == 0xFE ) { @@ -210,9 +221,9 @@ void Bu::UtfString::setUtf16le( const Bu::String &sInput ) } } -void Bu::UtfString::setUtf32( const Bu::String &sInput ) +void Bu::UtfString::setUtf32( const Bu::Blob &sInput ) { - Bu::String::const_iterator i = sInput.begin(); + Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*i == 0x00 && (uint8_t)*(++i) == 0x00 && (uint8_t)*(++i) == 0xFF && @@ -224,9 +235,9 @@ void Bu::UtfString::setUtf32( const Bu::String &sInput ) setUtf32be( sInput ); } -void Bu::UtfString::setUtf32be( const Bu::String &sInput ) +void Bu::UtfString::setUtf32be( const Bu::Blob &sInput ) { - Bu::String::const_iterator i = sInput.begin(); + Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*i == 0x00 && (uint8_t)*(++i) == 0x00 && (uint8_t)*(++i) == 0xFE && @@ -250,9 +261,9 @@ void Bu::UtfString::setUtf32be( const Bu::String &sInput ) } } -void Bu::UtfString::setUtf32le( const Bu::String &sInput ) +void Bu::UtfString::setUtf32le( const Bu::Blob &sInput ) { - Bu::String::const_iterator i = sInput.begin(); + Bu::Blob::const_iterator i = sInput.begin(); if( (uint8_t)*i == 0x00 && (uint8_t)*(++i) == 0x00 && (uint8_t)*(++i) == 0xFF && @@ -443,12 +454,12 @@ int Bu::UtfString::writePoint( Bu::Stream &sOut, const Bu::UtfChar &c, int32_t Bu::UtfString::toInt32( int iRadix ) const { - return strtol( get().getStr(), NULL, iRadix ); + return strtol( get().getData(), NULL, iRadix ); } int64_t Bu::UtfString::toInt64( int iRadix ) const { - return strtoll( get().getStr(), NULL, iRadix ); + return strtoll( get().getData(), NULL, iRadix ); } void Bu::UtfString::writeUtf8( Bu::Stream &sOut ) const @@ -626,7 +637,7 @@ bool Bu::UtfString::operator==( const Bu::UtfString &rhs ) const return aData == rhs.aData; } -bool Bu::UtfString::operator==( const Bu::String &rhs ) const +bool Bu::UtfString::operator==( const Bu::Blob &rhs ) const { // Nieve comparison if( aData.getSize() != rhs.getSize() ) @@ -718,11 +729,11 @@ bool Bu::UtfString::operator>=( const Bu::UtfString &rhs ) const return false; } -Bu::String Bu::UtfString::get( Encoding eEnc ) const +Bu::Blob Bu::UtfString::get( Encoding eEnc ) const { Bu::MemBuf mb; write( mb, eEnc ); - return mb.getString(); + return Bu::Blob( mb.getString().getStr(), mb.getString().getSize() ); } void Bu::UtfString::debug() const @@ -745,9 +756,9 @@ void Bu::UtfString::debug() const sio << sio.nl; } /* -void Bu::UtfString::debugUtf8( const Bu::String &sUtf8 ) +void Bu::UtfString::debugUtf8( const Bu::Blob &sUtf8 ) { - for( Bu::String::const_iterator i = sUtf8.begin(); i; i++ ) + for( Bu::Blob::const_iterator i = sUtf8.begin(); i; i++ ) { if( i != sUtf8.begin() ) sio << ", "; -- cgit v1.2.3