From cb219e9b51f3436b9fb6d63a2c7a05333e4c86ed Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 11 Aug 2009 14:55:17 +0000 Subject: 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. --- src/fbasicstring.h | 21 +++++++++++++ src/fstring.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/fstring.h | 16 ++++++++++ 3 files changed, 127 insertions(+) (limited to 'src') diff --git a/src/fbasicstring.h b/src/fbasicstring.h index fbfc5ef..33a82cb 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -1226,6 +1226,19 @@ namespace Bu append( s, e ); } + /** + * Resize the string, possibly to make room for a copy. At the moment + * this operation *is* destructive. What was in the string will in no + * way be preserved. + *@param iSize the new size in bytes. The string is guranteed to have + * at least this much contiguous space available when done. + */ + void setSize( long iSize ) + { + clear(); + appendChunk( newChunk( iSize ) ); + } + void expand() { flatten(); @@ -1520,6 +1533,14 @@ namespace Bu } } +// template +// void to( out &dst ); +/* { + flatten(); + + dst = strtol( pFirst->pData, NULL, 0 ); + } */ + const_iterator find( const chr cChar, const_iterator iStart=typename MyType::const_iterator() ) const { 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( const Bu::FString &v ) printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); } +bool &Bu::operator<<( bool &dst, const Bu::FString &sIn ) +{ + if( sIn == "true" || sIn == "yes" || sIn == "t" ) + dst = true; + else + dst = false; + + return dst; +} + +uint8_t &Bu::operator<<( uint8_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%hhu", &dst ); + return dst; +} + +int8_t &operator<<( int8_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%hhd", &dst ); + return dst; +} + +char &operator<<( char &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%hhd", &dst ); + return dst; +} + +uint16_t &operator<<( uint16_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%hu", &dst ); + return dst; +} + +int16_t &operator<<( int16_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%hd", &dst ); + return dst; +} + +uint32_t &operator<<( uint32_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%u", &dst ); + return dst; +} + +int32_t &operator<<( int32_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%d", &dst ); + return dst; +} + +uint64_t &operator<<( uint64_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%llu", &dst ); + return dst; +} + +int64_t &operator<<( int64_t &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%lld", &dst ); + return dst; +} + +float &operator<<( float &dst, const Bu::FString &sIn ) +{ + double tmp; + sscanf( sIn.getStr(), "%f", &tmp ); + dst = tmp; + return dst; +} + +double &operator<<( double &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%f", &dst ); + return dst; +} + +long double &operator<<( long double &dst, const Bu::FString &sIn ) +{ + sscanf( sIn.getStr(), "%Lf", &dst ); + return dst; +} + +Bu::FString &operator<<( Bu::FString &dst, const Bu::FString &sIn ) +{ + dst = sIn; + return dst; +} + diff --git a/src/fstring.h b/src/fstring.h index 0793154..1fc02ca 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -20,6 +20,22 @@ namespace Bu template void __tracer_format( const t &v ); template<> void __tracer_format( const FString &v ); + + bool &operator<<( bool &dst, const FString &sIn ); + uint8_t &operator<<( uint8_t &dst, const FString &sIn ); + int8_t &operator<<( int8_t &dst, const FString &sIn ); + char &operator<<( char &dst, const FString &sIn ); + uint16_t &operator<<( uint16_t &dst, const FString &sIn ); + int16_t &operator<<( int16_t &dst, const FString &sIn ); + uint32_t &operator<<( uint32_t &dst, const FString &sIn ); + int32_t &operator<<( int32_t &dst, const FString &sIn ); + uint64_t &operator<<( uint64_t &dst, const FString &sIn ); + int64_t &operator<<( int64_t &dst, const FString &sIn ); + float &operator<<( float &dst, const FString &sIn ); + double &operator<<( double &dst, const FString &sIn ); + long double &operator<<( long double &dst, const FString &sIn ); + Bu::FString &operator<<( Bu::FString &dst, const FString &sIn ); + } /***** I dunno about this block, I don't really want to have it... ***** -- cgit v1.2.3