]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.1.3
authorfred <fred>
Thu, 27 Feb 1997 22:08:49 +0000 (22:08 +0000)
committerfred <fred>
Thu, 27 Feb 1997 22:08:49 +0000 (22:08 +0000)
13 files changed:
flower/NEWS
flower/Sources.make
flower/dstream.cc
flower/fproto.hh
flower/path.cc
flower/scalar.cc
flower/string-convert.cc [new file with mode: 0644]
flower/string-convert.hh [new file with mode: 0644]
flower/string.cc
flower/string.hh
flower/stringconversion.cc [deleted file]
flower/stringconversion.hh [deleted file]
flower/stringtest.cc

index a01d6a140bf56399a5f3699e3f59706949c744c9..d6d6d86aed3c938ad0247a5505c968a646539bcc 100644 (file)
@@ -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
index 3964ba9be5fe3a5d3eb0ca6cef4ed74a9d43e16d..82454e3e3cf84e9f5a3cacb3234ea986f65eab26 100644 (file)
@@ -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
 
index 92790b5a08113c425aa9ca4d31bdb8fde5ae0c74..8452b742ebb682761810976889d96a1bfa2c29b8 100644 (file)
@@ -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;
 }
 
index 1d643ed621a167370edfc196f53916cf840f7b57..509d25d3fa7c80cd1357193ce7d686f582ce9bb5 100644 (file)
@@ -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  ;
index 3dc38366f26405fa583c5def9d921f6dca61e27d..c79962f00fc384caad3b3909eb71087fbe66c3d7 100644 (file)
@@ -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 
        {
index 044b4d0b0fe7a1bae4193cfe9aadd0429255d17c..5edd9e997f3ba2128cc2760282419c198074e5c6 100644 (file)
@@ -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 (file)
index 0000000..ccd62a0
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+  PROJECT: FlowerSoft C++ library
+  FILE   : string-convert.cc
+
+--*/
+
+
+#include <assert.h>
+#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 (file)
index 0000000..b96af44
--- /dev/null
@@ -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 //
index 6e7378fdcc854ef295bd5349ee3f143f66b9f34b..a9368fe4e4cc623006b2820bcb25531ac64af24c 100644 (file)
@@ -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() );
index a253b7ca613a6859f0d9e67531f0a920464bf1f0..7aa19047d1731e29b200f3db2fbd1dda5a26336a 100644 (file)
   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 (file)
index 8b9144a..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-  PROJECT: FlowerSoft C++ library
-  FILE   : stringconversion.cc
-
---*/
-
-
-#include <assert.h>
-#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 (file)
index 0bcd7f5..0000000
+++ /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 //
index 71c15579124426eb3d3f0a616b0642bcfef7c8c3..c0c50da5c6e4acd586d79a74c57d9b27d44ceaea 100644 (file)
@@ -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;
 }