From: fred Date: Thu, 27 Feb 1997 22:08:49 +0000 (+0000) Subject: flower-1.1.3 X-Git-Tag: release/1.5.59~6293 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=eae5856a349a50bd807019370de137356389a0ec;p=lilypond.git flower-1.1.3 --- diff --git a/flower/NEWS b/flower/NEWS index a01d6a140b..d6d6d86aed 100644 --- a/flower/NEWS +++ b/flower/NEWS @@ -1,3 +1,12 @@ +pl 1.1.3-1 + - great renaming of String and String_convert interfaces + - more conversions moved (copied actually) to String_convert + - String indexing now all base = 0, not found = -1 + - renamed by to byte + +pl 1.1.3 + - String::mid + - memmove test code pl 1.1.2 - StringConversio::bin2int_i diff --git a/flower/Sources.make b/flower/Sources.make index 3964ba9be5..82454e3e3c 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -1,6 +1,6 @@ cc=choleski.cc datafile.cc dstream.cc lgetopt.cc matdebug.cc matrix.cc\ -path.cc scalar.cc smat.cc string.cc stringconversion.cc stringutil.cc\ +path.cc scalar.cc smat.cc string.cc string-convert.cc stringutil.cc\ textdb.cc textstream.cc unionfind.cc vector.cc templatecc=cursor.tcc list.tcc plist.tcc interval.tcc\ @@ -11,7 +11,7 @@ inl=link.inl list.inl cursor.inl plist.inl stringdata.inl stringhandle.inl hh=assoc.hh associter.hh choleski.hh compare.hh cursor.hh dstream.hh\ fproto.hh handle.hh interval.hh iterate.hh lgetopt.hh link.hh list.hh\ matrix.hh path.hh pcursor.hh plist.hh rational.hh real.hh scalar.hh\ -smat.hh string.hh stringconversion.hh stringhandle.hh stringdata.hh\ +smat.hh string.hh string-convert.hh stringhandle.hh stringdata.hh\ textdb.hh textstream.hh unionfind.hh pqueue.hh\ varray.hh vector.hh vsmat.hh datafile.hh diff --git a/flower/dstream.cc b/flower/dstream.cc index 92790b5a08..8452b742eb 100644 --- a/flower/dstream.cc +++ b/flower/dstream.cc @@ -13,16 +13,16 @@ const INDTAB = 3; static String strip_pretty(String pret) { - String cl(pret.left(pret.pos('(')-1)); - int l = cl.lastPos(' '); - cl = cl.right(cl.len() -l); + String cl(pret.left_str(pret.index_i('('))); + int l = cl.index_last_i(' '); + cl = cl.right_str(cl.len() - l - 1); return cl; } static String strip_member(String pret) { - String cl(pret.left(pret.lastPos(':')-2)); + String cl(pret.left_str(pret.index_last_i(':')-1)); return cl; } diff --git a/flower/fproto.hh b/flower/fproto.hh index 1d643ed621..509d25d3fa 100644 --- a/flower/fproto.hh +++ b/flower/fproto.hh @@ -29,6 +29,7 @@ struct Getopt_long ; struct Matrix ; struct String_data ; struct String_handle ; +struct String_convert; struct String; struct virtual_smat ; struct Vector ; diff --git a/flower/path.cc b/flower/path.cc index 3dc38366f2..c79962f00f 100644 --- a/flower/path.cc +++ b/flower/path.cc @@ -17,30 +17,29 @@ split_path(String path, String &drive, String &dirs, String &filebase, String &extension) { // peel off components, one by one. - int di = path.pos(':'); - if (di) + int di = path.index_i(':'); + if (di >= 0) { - drive = path.left(di); - path = path.right(path.len() - di); + drive = path.left_str(di + 1); + path = path.right_str(path.len() - di -1); } else drive = ""; - di = path.lastPos(PATHSEP); - if (di) + di = path.index_last_i(PATHSEP); + if (di >=0) { - dirs = path.left(di); - path = path.right(path.len()-di); + dirs = path.left_str(di + 1); + path = path.right_str(path.len()-di -1); } else dirs = ""; - di = path.lastPos('.'); - if (di) + di = path.index_last_i('.'); + if (di >= 0) { - di --; // don't forget '.' - filebase = path.left(di); - extension =path.right(path.len()-di); + filebase = path.left_str(di); + extension =path.right_str(path.len()-di); } else { diff --git a/flower/scalar.cc b/flower/scalar.cc index 044b4d0b0f..5edd9e997f 100644 --- a/flower/scalar.cc +++ b/flower/scalar.cc @@ -10,15 +10,14 @@ Scalar::Scalar(Rational r) Scalar::operator Rational() { - int p = pos('/'); - if (!p) + int p = index_i('/'); + if (p == -1) return int(*this); - String s2 = right(len()-p); - p--; - String s1 = left(p); + String s2 = right_str(len()-p-1); + String s1 = left_str(p); - return Rational(s1.value(), s2.value()); + return Rational(s1.value_i(), s2.value_i()); } bool @@ -35,13 +34,13 @@ Scalar::isnum() Scalar::operator Real() { assert (isnum()); - return fvalue(); + return value_f(); } Scalar::operator int() { assert (isnum()); - return value(); + return value_i(); } @@ -52,8 +51,7 @@ Scalar::operator bool() const if (*this == "0") return false; String u (*this); - u.upper(); - if (u== "FALSE") + if ( u.upper_str() == "FALSE") return false; return true; } diff --git a/flower/string-convert.cc b/flower/string-convert.cc new file mode 100644 index 0000000000..ccd62a0a5a --- /dev/null +++ b/flower/string-convert.cc @@ -0,0 +1,141 @@ +/* + PROJECT: FlowerSoft C++ library + FILE : string-convert.cc + +--*/ + + +#include +#include "string.hh" + +String +String_convert::bin2hex_str( String bin_str ) +{ + String str; + Byte const* byte_c_l = bin_str.byte_c_l(); + for ( int i = 0; i < bin_str.length_i(); i++ ) { + str += (char)nibble2hex_byte( *byte_c_l >> 4 ); + str += (char)nibble2hex_byte( *byte_c_l++ ); + } + return str; +} + +int +String_convert::bin2_i( String bin_str ) +{ + assert( bin_str.length_i() <= 4 ); + + int result_i = 0; + for ( int i = 0; i < bin_str.length_i(); i++ ) { + result_i <<= 8; + result_i += (Byte)bin_str[ i ]; + } + return result_i; +} + +// breendet imp from String +int +String_convert::dec2_i( String dec_str ) +{ + if ( !dec_str.length_i() ) + return 0; + + long l = 0; + int conv = sscanf( dec_str.ch_c_l(), "%ld", &l ); + assert( conv ); + + return (int)l; +} + +// breendet imp from String +double +String_convert::dec2_f( String dec_str ) +{ + if ( !dec_str.length_i() ) + return 0; + double d = 0; + int conv = sscanf( dec_str.ch_c_l(), "%lf", &d ); + assert( conv ); + return d; +} + +int +String_convert::hex2bin_i( String hex_str, String& bin_str_r ) +{ + if ( hex_str.length_i() % 2 ) + hex_str = "0" + hex_str; + + bin_str_r = ""; + Byte const* byte_c_l= hex_str.byte_c_l(); + int i = 0; + while ( i < hex_str.length_i() ) { + int high_i = hex2nibble_i( *byte_c_l++ ); + int low_i = hex2nibble_i( *byte_c_l++ ); + if ( high_i < 0 || low_i < 0 ) + return 1; // illegal char + bin_str_r += String( (char)( high_i << 4 | low_i ), 1 ); + i += 2; + } + return 0; +} + +String +String_convert::hex2bin_str( String hex_str ) +{ + String str; +// silly, asserts should alway be "on"! +// assert( !hex2bin_i( hex_str, str ) ); + int error_i = hex2bin_i( hex_str, str ); + assert( !error_i ); + return str; +} + +int +String_convert::hex2nibble_i( Byte byte ) +{ + if ( byte >= '0' && byte <= '9' ) + return byte - '0'; + if ( byte >= 'A' && byte <= 'F' ) + return byte - 'A' + 10; + if ( byte >= 'a' && byte <= 'f') + return byte - 'a' + 10; + return -1; +} + +String +String_convert::i2dec_str( int i, int length_i, char ch ) +{ + char fill_ch = ch; + if ( fill_ch) + fill_ch = '0'; + + // ugh + String dec_str( i ); + + // ugh + return String( fill_ch, length_i - dec_str.length_i() ) + dec_str; +} + +String +String_convert::i2hex_str( int i, int length_i, char ch ) +{ + String str; + if ( !i ) + str = "0"; + while ( i ) { + str = ( i % 16 )["0123456789abcdef"] + str; + i /= 16; + } + if ( str.length_i() < length_i ) + str = String( ch, length_i - str.length_i() ) + str; + return str; +} + +Byte +String_convert::nibble2hex_byte( Byte byte ) +{ + if ( ( byte & 0x0f ) <= 9 ) + return ( byte & 0x0f ) + '0'; + else + return ( byte & 0x0f ) - 10 + 'a'; +} diff --git a/flower/string-convert.hh b/flower/string-convert.hh new file mode 100644 index 0000000000..b96af44bd0 --- /dev/null +++ b/flower/string-convert.hh @@ -0,0 +1,34 @@ +/* + PROJECT: FlowerSoft C++ library + FILE : string-convert.hh + +*/ + +#ifndef STRING_CONVERT_HH +#define STRING_CONVERT_HH + +/// +#define functor class // :-) +/** + The functor String_convert handles all conversions to/from String (some + time, anyway). + The class is quite empty from data view. + */ +functor String_convert { + static int hex2bin_i( String hex_str, String& bin_str_r ); + static int hex2nibble_i( Byte byte ); + static Byte nibble2hex_byte( Byte byte ); +public: + static String bin2dec_str( String dec_str ); + static String bin2hex_str( String bin_str ); + static String dec2bin_str( String str ); + static int bin2_i( String str ); + static int dec2_i( String dec_str ); + static double dec2_f( String dec_str ); + static int hex2int_i( String str ); + static String hex2bin_str( String str ); + static String i2hex_str( int i, int length_i, char ch ); + static String i2dec_str( int i, int length_i, char ch ); +}; + +#endif // __STRING_CONVERT_HH // diff --git a/flower/string.cc b/flower/string.cc index 6e7378fdcc..a9368fe4e4 100644 --- a/flower/string.cc +++ b/flower/string.cc @@ -16,7 +16,7 @@ #include "string.hh" #ifdef STRING_DEBUG -void* mymemmove( void* dest, void* src, size_t n ); +void* mymemmove( void* dest, void const* src, size_t n ); #define memmove mymemmove #endif @@ -25,11 +25,10 @@ strlwr( char* s ) { char* p = s; - while( *p ) - { + while( *p ) { *p = tolower( *p ); /* a macro on some compilers */ p++; - } + } return s; } @@ -38,11 +37,10 @@ strupr( char* s ) { char* p = s; - while( *p ) - { + while( *p ) { *p = toupper( *p ); /* a macro on some compilers */ p++; - } + } return s; } @@ -71,7 +69,7 @@ String::copy_byte_p() const } void -String::printOn(ostream& os) const +String::print_on(ostream& os) const { if ( length_i() == strlen( ch_c_l() ) ) os << ch_c_l(); @@ -128,13 +126,13 @@ String::String(int i) String::String( const int i, const int n, char const c ) { - char fillChar = c; - if ( fillChar) - fillChar = '0'; + char fill_ch = c; + if ( fill_ch) + fill_ch = '0'; String v( i ); - String str = String( fillChar, n - v.length_i() ) + String( v ); + String str = String( fill_ch, n - v.length_i() ) + String( v ); strh_.set( str.byte_c_l(), str.length_i() ); } @@ -164,7 +162,7 @@ String::ch_l() // signed comparison, analogous to memcmp; int -String::compare(String const& s1, String const& s2 ) +String::compare_i(String const& s1, String const& s2 ) { Byte const* p1 = s1.byte_c_l(); Byte const* p2 = s2.byte_c_l(); @@ -181,96 +179,96 @@ String::compare(String const& s1, String const& s2 ) int -String::lastPos( char const c ) const +String::index_last_i( char const c ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strrchr(me, c ); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } int -String::lastPos( char const* string ) const +String::index_last_i( char const* string ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - int pos = 0; - int length = strlen( string ); - if ( length_i() && length ) - { - int nextpos = this->pos( string ); - while( nextpos ) - { - pos += nextpos; - nextpos = right( length_i() - pos - length + 1 ).pos( string ); - } - } - return pos; + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + + int length = strlen( string ); + if ( !length_i() || !length ) + return -1; + + int next_i = index_i( string ); + if ( next_i == -1 ) + return -1; + + int index_i = 0; + while( next_i >= 0 ) { + index_i += next_i; + next_i = right_str( length_i() - index_i - length ).index_i( string ); + } + return index_i; } // find c -// return 0 if not found. +// return -1 if not found. -// ? should return length_i()?, as in string.left(pos(delimiter)) +// ? should return length_i()?, as in string.left_str(index_i(delimiter)) int -String::pos(char c ) const +String::index_i(char c ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strchr( me, c ); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } // find searchfor. (what if this == "" && searchfor == "") ??? int -String::pos( char const* searchfor ) const -{ - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - char const* me = strh_.ch_c_l(); - int pos = 0; - if ( length_i() && searchfor) - { +String::index_i( char const* searchfor ) const +{ + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + if ( !length_i() || !searchfor ) + return -1; + + char const* me = strh_.ch_c_l(); char const* p = strstr(me, searchfor); - if ( p ) - pos = p - me + 1; - } - return pos; + if ( p ) + return p - me; + return -1; } // find chars of a set. int -String::posAny( char const* string ) const +String::index_any_i( char const* string ) const { - // not binary safe - assert( length_i() == strlen( ch_c_l() ) ); - int pos = 0; - char const* s = (char const* )strh_.ch_c_l(); - if ( length_i() && string ) - { + // not binary safe + assert( length_i() == strlen( ch_c_l() ) ); + + if ( !length_i() || !string ) + return -1; + + char const* s = (char const* )strh_.ch_c_l(); char const* p = strpbrk( s, string ); - if ( p ) - pos = p - s + 1; - } - return pos; + if ( p ) + return p - s; + return -1; } String -String::left( int n ) const +String::left_str( int n ) const { if (n >= length_i()) return *this; @@ -287,7 +285,7 @@ String::left( int n ) const // n rightmst chars String -String::right( int n ) const +String::right_str( int n ) const { if (n > length_i()) return *this; @@ -300,57 +298,53 @@ String::right( int n ) const String -String::nomid( const int pos, const int n ) const +String::nomid_str( int index_i, int n ) const { - String retval; - - if ( pos < 1 ) - return String(""); - if ( pos > length_i()) - return *this; + if ( index_i < 0 ) + return String(); + if ( index_i >= length_i() ) + return *this; - return String( String( left( pos - 1 ) ) + right( length_i() - pos - n + 1 )); + return String( String( left_str( index_i ) ) + right_str( length_i() - index_i - n )); } String -String::mid( int pos, int n ) const +String::mid_str( int index_i, int n ) const { - // HWN. This SUX: JCN: yep, please change me + all my invocations - // pos 1 == strh_->string[ 0 ]; - // pos 0 allowed for convenience - if ( !length_i() || ( pos < 0 ) || ( pos > length_i() ) && ( n < 1 ) ) - return String(); + if ( !length_i() || ( index_i < 0 ) || ( index_i >= length_i() ) || ( n < 1 ) ) + return String(); - // overflow... - if ( ( n > length_i() ) || ( pos + n - 1 > length_i() ) ) - n = length_i() - pos + 1; + if ( ( n > length_i() ) || ( index_i + n > length_i() ) ) + n = length_i() - index_i; - return String( byte_c_l() + pos -1, n ); + return String( byte_c_l() + index_i, n ); } -// to uppercase +// return uppercase String -String::upper() +String::upper_str() const { // not binary safe assert( length_i() == strlen( ch_c_l() ) ); - char *s = strh_.byte_l(); + String str = *this; + char *s = str.strh_.byte_l(); strupr( s ); - return *this; + return str; } -// to lowercase +// return lowercase String -String::lower() +String::lower_str() const { // not binary safe assert( length_i() == strlen( ch_c_l() ) ); - char* s = strh_.byte_l(); + String str = *this; + char* s = str.strh_.ch_l(); strlwr(s); - return *this; + return str; } String::String (double f, char const* fmt) @@ -369,53 +363,45 @@ String::String (double f, char const* fmt) *this = buf; } -long -String::value() const +int +String::value_i() const { - long l =0; - if (length_i()) { - int conv = sscanf(strh_.ch_c_l(), "%ld", &l); - assert(conv); - } - return l; + return String_convert::dec2_i( *this ); } double -String::fvalue() const +String::value_f() const { - double d =0; - if (length_i()) { - int conv = sscanf(strh_.ch_c_l(), "%lf", &d); - assert(conv); - } - return d; + return String_convert::dec2_f( *this ); } -String quoteString( String msg, String quote) +#if 0 +String +quoteString( String msg, String quote) { - return msg + " `" + quote + "' "; + return msg + " `" + quote + "' "; } - +#endif // 0 Byte* strrev( Byte* byte_l, int length_i ) { - Byte by; + Byte byte; Byte* left_byte_l = byte_l; Byte* right_byte_l = byte_l + length_i; while ( right_byte_l > left_byte_l ) { - by = *left_byte_l; + byte = *left_byte_l; *left_byte_l++ = *right_byte_l; - *right_byte_l-- = by; + *right_byte_l-- = byte; } return byte_l; } String -String::reversed() const +String::reversed_str() const { String str = *this; strrev( str.byte_l(), str.length_i() ); diff --git a/flower/string.hh b/flower/string.hh index a253b7ca61..7aa19047d1 100644 --- a/flower/string.hh +++ b/flower/string.hh @@ -25,20 +25,21 @@ ref counting through #String_handle# \item - conversion from bool, int, double, char *, char. + conversion from bool, int, double, char* , char. \item - conversion to int, upcase, downcase + to be moved to String_convert: + conversion to int, upcase, downcase \item printable. \item - indexing (pos, posAny, lastPos) + indexing (index_i, index_any_i, last_index_i) \item - cutting (left, right, mid) + cutting (left_str, right_str, mid_str) \item concat (+=, +) @@ -48,7 +49,7 @@ \item No operator[] is provided, since this would be enormously slow. If needed, - convert to const char *. + convert to char const* . \end{itemize} */ class String @@ -62,9 +63,9 @@ public: String() { } String(Rational); /// String s = "abc"; - String( const char* source ); + String( char const* source ); - String( Byte const* l_byte_c, int length_i ); + String( Byte const* byte_c_l, int length_i ); /// "ccccc" String( char c, int n = 1 ); @@ -76,7 +77,7 @@ public: String(bool ); /// String s( 3.14, 6, '#' ); - String ( double f , const char *fmt =0); + String ( double f , char const* fmt =0); String( int i, int n, char c = ' ' ); /// return a "new"-ed copy of contents @@ -88,7 +89,7 @@ public: Byte* byte_l(); /// deprecated; use ch_c_l() - operator const char *() const { return ch_c_l(); } + operator char const* () const { return ch_c_l(); } String operator =( const String & source ) { strh_ = source.strh_; return *this; } @@ -99,82 +100,82 @@ public: char operator []( int n ) const { return strh_[n]; } /// return n leftmost chars - String left( int n ) const; + String left_str( int n ) const; /// return n rightmost chars - String right( int n ) const; + String right_str( int n ) const; - /// convert this to upcase - String upper(); + /// return uppercase of *this + String upper_str() const; - /// convert this to downcase - String lower(); // & ?? + /// return lowercase of *this + String lower_str() const; /// return the "esrever" of *this - String reversed() const; + String reversed_str() const; - /// return a piece starting at pos (first char = pos 1), ength n - String mid(int pos, int n ) const; + /// return a piece starting at index_i (first char = index_i 0), length n + String mid_str(int index_i, int n ) const; /// cut out a middle piece, return remainder - String nomid(int pos, int n ) const; + String nomid_str(int index_i, int n ) const; /// signed comparison, analogous to memcmp; - static int compare(const String& s1,const String& s2); + static int compare_i(const String& s1,const String& s2); /// index of rightmost c - int lastPos( char c) const; + int index_last_i( char c) const; /// index of rightmost element of string - int lastPos( const char* string ) const; + int index_last_i( char const* string ) const; /** index of leftmost c. @return - 0 if not found, else index + 1 + -1 if not found, else index */ - int pos(char c ) const; - int pos(const char* string ) const; - int posAny(const char* string ) const; + int index_i(char c ) const; + int index_i(char const* string ) const; + int index_any_i(char const* string ) const; /// provide Stream output - void printOn(ostream& os) const; + void print_on(ostream& os) const; - /// convert to an integer - long value() const; - - /// convert to a double - double fvalue() const; - /// the length of the string int length_i() const; - // deprecated + // ***** depreciated int len() const { return length_i(); } + /// convert to an integer + int value_i() const; + + /// convert to a double + double value_f() const; + // ***** }; #include "compare.hh" -instantiate_compare(const String &, String::compare); +instantiate_compare(const String &, String::compare_i); -// because const char* also has an operator ==, this is for safety: -inline bool operator==(String s1, const char *s2){ +// because char const* also has an operator ==, this is for safety: +inline bool operator==(String s1, char const* s2){ return s1 == String(s2); } -inline bool operator==(const char *s1, String s2) +inline bool operator==(char const* s1, String s2) { return String(s1)==s2; } -inline bool operator!=(String s1, const char *s2 ) { +inline bool operator!=(String s1, char const* s2 ) { return s1!=String(s2); } -inline bool operator!=(const char *s1,String s2) { +inline bool operator!=(char const* s1,String s2) { return String(s2) !=s1; } @@ -189,13 +190,13 @@ operator + (String s1, String s2) inline ostream & operator << ( ostream& os, String d ) { - d.printOn(os); + d.print_on(os); return os; } -String quoteString(String message, String quote); +// String quoteString(String message, String quote); -#include "stringconversion.hh" +#include "string-convert.hh" #endif diff --git a/flower/stringconversion.cc b/flower/stringconversion.cc deleted file mode 100644 index 8b9144a9a7..0000000000 --- a/flower/stringconversion.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - PROJECT: FlowerSoft C++ library - FILE : stringconversion.cc - ---*/ - - -#include -#include "string.hh" - -String -StringConversion::bin2hex_str( String bin_str ) -{ - String str; - Byte const* byte_c_l = bin_str.byte_c_l(); - for ( int i = 0; i < bin_str.length_i(); i++ ) { - str += (char)nibble2hex_by( *byte_c_l >> 4 ); - str += (char)nibble2hex_by( *byte_c_l++ ); - } - return str; -} - -int -StringConversion::bin2int_i( String bin_str ) -{ - assert( bin_str.length_i() <= 4 ); - - int result_i = 0; - for ( int i = 0; i < bin_str.length_i(); i++ ) { - result_i <<= 8; - result_i |= bin_str[ i ]; - } - return result_i; -} - - -int -StringConversion::hex2bin_i( String hex_str, String& bin_str_r ) -{ - if ( hex_str.length_i() % 2 ) - hex_str = "0" + hex_str; - - bin_str_r = ""; - Byte const* byte_c_l= hex_str.byte_c_l(); - int i = 0; - while ( i < hex_str.length_i() ) { - int high_i = hex2nibble_i( *byte_c_l++ ); - int low_i = hex2nibble_i( *byte_c_l++ ); - if ( high_i < 0 || low_i < 0 ) - return 1; // illegal char - bin_str_r += String( (char)( high_i << 4 | low_i ), 1 ); - i += 2; - } - return 0; -} - -String -StringConversion::hex2bin_str( String hex_str ) -{ - String str; -// silly, asserts should alway be "on"! -// assert( !hex2bin_i( hex_str, str ) ); - int error_i = hex2bin_i( hex_str, str ); - assert( !error_i ); - return str; -} - -int -StringConversion::hex2nibble_i( Byte by ) -{ - if ( by >= '0' && by <= '9' ) - return by - '0'; - if ( by >= 'A' && by <= 'F' ) - return by - 'A' + 10; - if ( by >= 'a' && by <= 'f') - return by - 'a' + 10; - return -1; -} - -String -StringConversion::int2hex_str( int i, int length_i, char ch ) -{ - String str; - if ( !i ) - str = "0"; - while ( i ) { - str = ( i % 16 )["0123456789abcdef"] + str; - i /= 16; - } - if ( str.length_i() < length_i ) - str = String( ch, length_i - str.length_i() ) + str; - return str; -} - -Byte -StringConversion::nibble2hex_by( Byte by ) -{ - if ( ( by & 0x0f ) <= 9 ) - return ( by & 0x0f ) + '0'; - else - return ( by & 0x0f ) - 10 + 'a'; -} diff --git a/flower/stringconversion.hh b/flower/stringconversion.hh deleted file mode 100644 index 0bcd7f5c4c..0000000000 --- a/flower/stringconversion.hh +++ /dev/null @@ -1,30 +0,0 @@ -/* - PROJECT: FlowerSoft C++ library - FILE : stringconversion.hh - -*/ - -#ifndef STRING_CONVERSION_HH -#define STRING_CONVERSION_HH - -/** - all conversions from/to String go in here.( some time, anyway ) - The class is quite empty from data view. - */ -class StringConversion { - static int hex2bin_i( String hex_str, String& bin_str_r ); - static int hex2nibble_i( Byte by ); - static Byte nibble2hex_by( Byte by ); -public: - static String bin2dec_str( String dec_str ); - static String bin2hex_str( String bin_str ); - static String dec2bin_str( String str ); - static int bin2int_i( String str ); - static int dec2int_i( String str ); - static int hex2int_i( String str ); - static String hex2bin_str( String str ); - static String int2hex_str( int i, int length_i, char ch ); - static String int2dec_str( int i, int length_i, char ch ); -}; - -#endif // __STRING_CONVERSION_HH // diff --git a/flower/stringtest.cc b/flower/stringtest.cc index 71c1557912..c0c50da5c6 100644 --- a/flower/stringtest.cc +++ b/flower/stringtest.cc @@ -9,17 +9,17 @@ main() String str( "hai" ); cout << str << endl; cout << "left" << endl; - cout << " 0:" << str.left( 0 ) << endl; - cout << " 1:" << str.left( 1 ) << endl; - cout << " 2:" << str.left( 2 ) << endl; - cout << " 3:" << str.left( 3 ) << endl; - cout << " 4:" << str.left( 4 ) << endl; + cout << " 0:" << str.left_str( 0 ) << endl; + cout << " 1:" << str.left_str( 1 ) << endl; + cout << " 2:" << str.left_str( 2 ) << endl; + cout << " 3:" << str.left_str( 3 ) << endl; + cout << " 4:" << str.left_str( 4 ) << endl; cout << "right" << endl; - cout << " 0:" << str.right( 0 ) << endl; - cout << " 1:" << str.right( 1 ) << endl; - cout << " 2:" << str.right( 2 ) << endl; - cout << " 3:" << str.right( 3 ) << endl; - cout << " 4:" << str.right( 4 ) << endl; + cout << " 0:" << str.right_str( 0 ) << endl; + cout << " 1:" << str.right_str( 1 ) << endl; + cout << " 2:" << str.right_str( 2 ) << endl; + cout << " 3:" << str.right_str( 3 ) << endl; + cout << " 4:" << str.right_str( 4 ) << endl; str += " daar"; cout << str << endl; @@ -35,9 +35,9 @@ main() fn = ""; fn += ""; - delete fn.copy_by_p(); + delete fn.copy_byte_p(); - delete str.copy_by_p(); + delete str.copy_byte_p(); - cout << StringConversion::bin2hex_str( String( (char)0xff ) ) << endl; + cout << String_convert::bin2hex_str( String( (char)0xff ) ) << endl; }