]> git.donarmstrong.com Git - lilypond.git/commitdiff
* flower/include/std-string.hh: String/std::string compatibility:
authorJan Nieuwenhuizen <janneke@gnu.org>
Wed, 25 Jan 2006 10:08:46 +0000 (10:08 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Wed, 25 Jan 2006 10:08:46 +0000 (10:08 +0000)
Use NPOS for `not found' (iso -1), use ssize for length () and pos
type.

* flower/rational.cc:
* flower/include/rational.hh:

* flower/offset.cc:
* flower/include/offset.hh:

* flower/interval.cc:
* flower/include/interval.hh:

* flower/string-convert.cc:
* flower/include/string-convert.hh: Use std::string [interface].
Update callers.

24 files changed:
ChangeLog
flower/file-name.cc
flower/file-path.cc
flower/getopt-long.cc
flower/include/file-name.hh
flower/include/getopt-long.hh
flower/include/interval.hh
flower/include/interval.tcc
flower/include/offset.hh
flower/include/rational.hh
flower/include/std-string.hh
flower/include/string-convert.hh
flower/include/string.hh
flower/interval.cc
flower/offset.cc
flower/rational.cc
flower/std-string.cc
flower/string-convert.cc
flower/string.cc
lily/include/lily-guile.hh
lily/lily-guile.cc
lily/lilypond-version.cc
lily/main.cc
lily/template5.cc

index bed29752621eb817e1ced68ce8d67206c80059c7..6d86f5d9d5aafd9486f6a2993dc0af0c492a81d2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2006-01-25  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * flower/include/std-string.hh: String/std::string compatibility:
+       Use NPOS for `not found' (iso -1), use ssize for length () and pos
+       type.
+
+       * flower/rational.cc: 
+       * flower/include/rational.hh: 
+
+       * flower/offset.cc: 
+       * flower/include/offset.hh: 
+
+       * flower/interval.cc: 
+       * flower/include/interval.hh: 
+       
+       * flower/string-convert.cc: 
+       * flower/include/string-convert.hh: Use std::string [interface].
+       Update callers.
+
 2006-01-25  Heikki Junes  <hjunes@cc.hut.fi>
 
        * Documentation/index.html.in: clean up.
index d10e5b4c6a430a1f85068ec30afd8b4bf3838c12..fbd31de4c85f5ceb5f7ee3d3ac7633c4c28e340b 100644 (file)
@@ -94,24 +94,24 @@ File_name::File_name (Std_string file_name)
 #endif
 
   int i = file_name.find (ROOTSEP);
-  if (i >= 0)
+  if (i != NPOS)
     {
-      root_ = Std_string (file_name, 0, i);
-      file_name = Std_string (file_name, i + 1);
+      root_ = file_name.substr (0, i);
+      file_name = file_name.substr (i + 1);
     }
 
   i = file_name.rfind (DIRSEP);
-  if (i >= 0)
+  if (i != NPOS)
     {
-      dir_ = Std_string (file_name, 0, i);
-      file_name = Std_string (file_name, i + 1);
+      dir_ = file_name.substr (0, i);
+      file_name = file_name.substr (i + 1);
     }
 
   i = file_name.rfind ('.');
-  if (i >= 0)
+  if (i != NPOS)
     {
-      base_ = Std_string (file_name, 0, i);
-      ext_ = Std_string (file_name, i + 1);
+      base_ = file_name.substr (0, i);
+      ext_ = file_name.substr (i + 1);
     }
   else
     base_ = file_name;
index e1c387a5ae0152ad6d40ef88c0b6b30861016bfe..19d9d9bfaba0b73d23689a54fe874234070afca6 100644 (file)
@@ -42,10 +42,10 @@ File_path::parse_path (Std_string p)
   while ((len = p.length ()))
     {
       int i = p.find (PATHSEP);
-      if (i < 0)
+      if (i == NPOS)
        i = len;
-      append (String (p, 0, i));
-      p = String (p, i + 1);
+      append (p.substr (0, i));
+      p = p.substr (min (int(len), i + 1));
     }
 }
 
@@ -113,7 +113,7 @@ File_path::find (Std_string name) const
     return name;
 
 #ifdef __MINGW32__
-  if (name.find ('\\') >= 0)
+  if (name.find ('\\') != NPOS)
     programming_error ("file name not normalized: " + name);
 #endif /* __MINGW32__ */
 
index 8829c27ee9d069c6c83691e992dbc2a1210438fa..b7abd93817be4ded6ddf449cdf9397aa70c06eda 100644 (file)
@@ -10,9 +10,8 @@
 #include <cassert>
 #include <cstdlib>
 
-using namespace std;
-
 #include "config.hh"
+#include "string.hh"
 
 #if !HAVE_GETTEXT
 inline char *
index e6247986f96609f5d0dd398c3d2fae46df9ad5eb..b91eb351564f060cd4c65af10994b24b9187d369 100644 (file)
 #include "array.hh"
 #include "std-string.hh"
 
-#if 0// STD_STRING
-#include "string.hh"
-#endif
-
 class File_name
 {
 public:
index 3e5d7000f8c8be827fcadb6dc3dd0dc2acafb730..03b660b30d09ca95d798e05270885a8a397577b4 100644 (file)
@@ -4,9 +4,6 @@
 #include <cstdio>
 
 #include "std-string.hh"
-using namespace std;
-
-#include "string.hh"
 
 /**
    a struct this for initialising the commandline options.
index 9190f28544597f53664f78815f7b753a6a97fb21..6351d35535f7ea138da8bda1b2689d24054bfd0f 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <math.h>
 
+#include "std-string.hh"
+
 #include "flower-proto.hh"
 #include "drul-array.hh"
 
@@ -22,7 +24,7 @@ struct Interval_t : public Drul_array<T>
   Drul_array<T>::elem_ref;
 
   static T infinity ();
-  static String T_to_string (T arg);
+  static Std_string T_to_string (T arg);
   T center () const;
   void translate (T t)
   {
@@ -109,7 +111,7 @@ struct Interval_t : public Drul_array<T>
     Drul_array<Real> da (elem (LEFT), elem (RIGHT));
     return ::linear_combination (da, x);
   }
-  String to_string () const;
+  Std_string to_string () const;
 
   bool contains (T r) const;
   void negate ()
index ec760db5fc245f7757547cbb865219014f1ad983..9af4047a8c35e5d133d28cf39282ece1de610cc8 100644 (file)
 
 #include <cassert>
 
+#include "interval.hh"
+#include "string.hh"
+
 // MacOS 10.3 problems:
 // #include <cmath>
 using namespace std;
 
-#include "interval.hh"
-#include "string.hh"
-
 template<class T>
 int
 _Interval__compare (const Interval_t<T> &a, Interval_t<T> const &b)
@@ -105,15 +105,15 @@ Interval_t<T>::intersect (Interval_t<T> h)
 }
 
 template<class T>
-String
+Std_string
 Interval_t<T>::to_string () const
 {
   if (is_empty ())
     return "[empty]";
-  String s ("[");
+  Std_string s ("[");
 
-  return (s + T_to_string (elem (LEFT)) + String (",")
-         + T_to_string (elem (RIGHT)) + String ("]"));
+  return (s + T_to_string (elem (LEFT)) + Std_string (",")
+         + T_to_string (elem (RIGHT)) + Std_string ("]"));
 }
 
 template<class T>
index 65a856ecac4faa1496e1e669ee912ef2767e6d7e..5ca7e0e68c637130c2c9fe7e42b8d90503b97d77 100644 (file)
@@ -8,9 +8,11 @@
 #define OFFSET_HH
 
 #include "axis.hh"
+#include "std-string.hh"
 #include "string.hh"
 #include "real.hh"
 
+class Offset;
 Offset complex_multiply (Offset, Offset);
 Offset complex_divide (Offset, Offset);
 Offset complex_exp (Offset);
@@ -92,7 +94,7 @@ public:
     coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS] = 0.0;
   }
 
-  String to_string () const;
+  Std_string to_string () const;
 
   Offset &mirror (Axis a)
   {
index d29c7467e95d6bfc89ae83365d531be596395ed5..6c0da7b9a9e1a4cfbff210b721007f70f3954b1c 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef RATIONAL_HH
 #define RATIONAL_HH
 
+#include "std-string.hh"
+
 #include "string.hh"
 
 /**
@@ -67,7 +69,7 @@ public:
   Rational &operator %= (Rational);
   static int compare (Rational const &, Rational const &);
   int sign () const;
-  String to_string () const;
+  Std_string to_string () const;
 };
 
 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, /);
index d623145479b01d71420dfce59cbc3b902b80b8df..4cefb799534c19286ee40c6cd9f7e2f3b1c24f0d 100644 (file)
 #define Std_string String
 #define to_std_string to_string
 class String;
+typedef int ssize;
+#define NPOS -1
+
 #include "string.hh"
 
 #else
 
 #include <string>
 // #warning Using std::string
+using namespace std;
+typedef size_t ssize;
+
+#define NPOS std::string::npos
 
 namespace std {
 
index 5bc8a7dd56604738a92bf9524d146705a1443e10..1e9da716ef99671ff30a55d299aa49fab02e511a 100644 (file)
@@ -9,42 +9,43 @@
 #include <cstdarg>
 using namespace std;
 
+#include "std-string.hh"
 #include "string.hh"
 
-/** The functor String_convert handles all conversions to/from String
+/** The functor Std_string_convert handles all conversions to/from Std_string
     (some time, anyway).  The class is quite empty from data view.  */
 class String_convert
 {
-  static int hex2bin (String hex_string, String &bin_string_r);
+  static int hex2bin (Std_string hex_string, Std_string &bin_string_r);
   static int hex2nibble (Byte byte);
   static Byte nibble2hex_byte (Byte byte);
 public:
-  static String pad_to (String s, int length);
-  static String bool_string (bool b);
-  static String bin2dec (String bin_string);
-  static String bin2hex (String bin_string);
-  static String dec2bin (String str);
-  static int bin2int (String bin_string);
-  static unsigned bin2unsigned (String bin_string);
-  static String char_string (char c, int n);
-  static int dec2int (String dec_string);
-  static double dec2double (String dec_string);
-  static String double_string (double f, char const *fmt = 0);
-  static String form_string (char const *format, ...);
-  static String vform_string (char const *format, va_list args);
-  static int hex2int (String str);
-  static unsigned hex2unsigned (String str);
-  static String hex2bin (String str);
-  static String int_string (int i, char const *fmt = 0);
-  static String long_string (long);
-  static String int2hex (int i, int length_i, char ch);
-  static String unsigned2hex (unsigned u, int length_i, char ch);
-  static String int2dec (int i, int length_i, char ch);
-  static String rational_string (Rational);
-  static String pointer_string (void const *);
-  static String precision_string (double x, int n);
-  static Array<String> split (String str, char c);
-  static String i64_string (I64, char const *fmt = 0);
+  static Std_string pad_to (Std_string s, int length);
+  static Std_string bool_string (bool b);
+  static Std_string bin2dec (Std_string bin_string);
+  static Std_string bin2hex (Std_string bin_string);
+  static Std_string dec2bin (Std_string str);
+  static int bin2int (Std_string bin_string);
+  static unsigned bin2unsigned (Std_string bin_string);
+  static Std_string char_string (char c, int n);
+  static int dec2int (Std_string dec_string);
+  static double dec2double (Std_string dec_string);
+  static Std_string double_string (double f, char const *fmt = 0);
+  static Std_string form_string (char const *format, ...);
+  static Std_string vform_string (char const *format, va_list args);
+  static int hex2int (Std_string str);
+  static unsigned hex2unsigned (Std_string str);
+  static Std_string hex2bin (Std_string str);
+  static Std_string int_string (int i, char const *fmt = 0);
+  static Std_string long_string (long);
+  static Std_string int2hex (int i, int length_i, char ch);
+  static Std_string unsigned2hex (unsigned u, ssize length, char ch);
+  static Std_string int2dec (int i, int length_i, char ch);
+  static Std_string rational_string (Rational);
+  static Std_string pointer_string (void const *);
+  static Std_string precision_string (double x, int n);
+  static Array<Std_string> split (Std_string str, char c);
+  static Std_string i64_string (I64, char const *fmt = 0);
 };
 
 #endif // __STRING_CONVERT_HH //
index 4a4f36f86eceb8920ccd6c6ab83b84f1b84dd592..b541368d7e67520b592829c0879a5a93c9a5b863 100644 (file)
@@ -19,8 +19,6 @@ class ostream;
 #endif
 
 #include "std-string.hh"
-using namespace std;
-
 #include "arithmetic-operator.hh"
 #include "string-handle.hh"
 
@@ -67,13 +65,16 @@ public:
 
   /* std::string interface */
   char const *c_str () const;
+  char const *data () const;
   bool empty () const;
   int find (String &s, int pos=0) const;
   int find (char c) const;
   int rfind (char c) const;
   String replace (int pos, int n, String str);
 
-  String (String const &, int pos, int n=-1);
+  String substr (int pos=0, int n=NPOS) const;
+
+  //String (String const &, int pos, int n=NPOS);
   String (int n, char c);
 
 protected:
@@ -132,9 +133,7 @@ public:
   /// signed comparison,  analogous to memcmp;
   static int compare (String const &s1, const String &s2);
 
-  /// index of rightmost element of string (???)
-  int index_last (char const *string) const;
-
+  /// index of rightmost character C in string
   int index_last (char c) const;
   
   int index (char c) const;
index aaa552353d3d6dc1bc01b094bfff4c7886756b04..a3dc1290196f3f3b484f64aa5164abdced36f01e 100644 (file)
@@ -18,7 +18,7 @@ Interval_t<Real>::infinity ()
 }
 
 template<>
-String
+Std_string
 Interval_t<Real>::T_to_string (Real r)
 {
   return ::to_string (r);
@@ -32,7 +32,7 @@ Interval_t<int>::infinity ()
 }
 
 template<>
-String
+Std_string
 Interval_t<int>::T_to_string (int i)
 {
   return ::to_string (i);
@@ -40,4 +40,3 @@ Interval_t<int>::T_to_string (int i)
 
 template INTERVAL__INSTANTIATE (int);
 template INTERVAL__INSTANTIATE (Real);
-
index 62862327acfdce663fc323f1c0a8c965d0be94ba..9265f12fdaf9800bd5e24ad5647c178044ef8b30 100644 (file)
 
 
 #ifndef STANDALONE
-String
+Std_string
 Offset::to_string () const
 {
-  String s;
-  s = String (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
+  Std_string s;
+  s = Std_string (" (") + ::to_string (coordinate_a_[X_AXIS]) + ", "
     + ::to_string (coordinate_a_[Y_AXIS]) + ")";
   return s;
 }
index b61c84e014a78922a17bcb6f33ce59f1b71786f9..8ecdbccf34f39067e972c39eee8724fea3732e5d 100644 (file)
@@ -269,16 +269,16 @@ Rational::operator -= (Rational r)
   return (*this += r);
 }
 
-String
+Std_string
 Rational::to_string () const
 {
   if (is_infinity ())
     {
-      String s (sign_ > 0 ? "" : "-");
-      return String (s + "infinity");
+      Std_string s (sign_ > 0 ? "" : "-");
+      return Std_string (s + "infinity");
     }
 
-  String s = ::to_string (num ());
+  Std_string s = ::to_string (num ());
   if (den () != 1 && num ())
     s += "/" + ::to_string (den ());
   return s;
index 62edc829bee6cdec1cb309efe24a68e2dea43478..66b94fda316a1de42aa8f21fa8511df4d2c5fd24 100644 (file)
@@ -20,21 +20,15 @@ namespace std {
     return Std_string (n, c);
   }
 
-#define FIND_FAILED string::npos
-#define SIZE_T size_t
 #else /* !STD_STRING */
 
-#define FIND_FAILED -1
-#define SIZE_T int
-
 #endif /* STD_STRING */
 
 Std_string &
 replace_all (Std_string &str, Std_string find, Std_string replace)
 {
-  int len = find.length ();
-  for (SIZE_T i = str.find (find); i != FIND_FAILED; i = str.find (find,
-                                                                  i + len))
+  ssize len = find.length ();
+  for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + len))
     str = str.replace (i, len, replace);
   return str;
 }
index 91ef7e7f93efd5da472585b4f1e0000fe476a946..5f74cc9fa6b8d87e7a12137872f2ad6be191c084 100644 (file)
@@ -27,18 +27,18 @@ using namespace std;
 */
 static const int STRING_BUFFER_LEN = 1024;
 
-String
+Std_string
 String_convert::bool_string (bool b)
 {
-  return String (b ? "true" : "false");
+  return Std_string (b ? "true" : "false");
 }
 
-String
-String_convert::bin2hex (String bin_string)
+Std_string
+String_convert::bin2hex (Std_string bin_string)
 {
-  String str;
-  Byte const *byte = bin_string.to_bytes ();
-  for (int i = 0; i < bin_string.length (); i++)
+  Std_string str;
+  Byte const *byte = (Byte const*)bin_string.data ();
+  for (ssize i = 0; i < bin_string.length (); i++)
     {
       str += to_string ((char)nibble2hex_byte (*byte >> 4));
       str += to_string ((char)nibble2hex_byte (*byte++));
@@ -47,18 +47,18 @@ String_convert::bin2hex (String bin_string)
 }
 
 int
-String_convert::bin2int (String bin_string)
+String_convert::bin2int (Std_string bin_string)
 {
   return bin2unsigned (bin_string);
 }
 
 unsigned
-String_convert::bin2unsigned (String bin_string)
+String_convert::bin2unsigned (Std_string bin_string)
 {
   assert (bin_string.length () <= (int)sizeof (unsigned));
 
   unsigned result_u = 0;
-  for (int i = 0; i < bin_string.length (); i++)
+  for (ssize i = 0; i < bin_string.length (); i++)
     {
       result_u <<= 8;
       result_u += (Byte)bin_string[ i ];
@@ -66,9 +66,9 @@ String_convert::bin2unsigned (String bin_string)
   return result_u;
 }
 
-// breendet imp from String
+// breendet imp from Std_string
 int
-String_convert::dec2int (String dec_string)
+String_convert::dec2int (Std_string dec_string)
 {
   if (!dec_string.length ())
     return 0;
@@ -80,17 +80,17 @@ String_convert::dec2int (String dec_string)
   return (int)l;
 }
 
-String
+Std_string
 String_convert::i64_string (I64 i64, char const *fmt)
 {
   char buffer[STRING_BUFFER_LEN];
   snprintf (buffer, STRING_BUFFER_LEN,
            (fmt ? fmt : "%Ld"), i64); // assume radix 10
-  return String (buffer);
+  return Std_string (buffer);
 }
-// breendet imp from String
+// breendet imp from Std_string
 double
-String_convert::dec2double (String dec_string)
+String_convert::dec2double (Std_string dec_string)
 {
   if (!dec_string.length ())
     return 0;
@@ -101,14 +101,14 @@ String_convert::dec2double (String dec_string)
 }
 
 int
-String_convert::hex2bin (String hex_string, String &bin_string_r)
+String_convert::hex2bin (Std_string hex_string, Std_string &bin_string_r)
 {
   if (hex_string.length () % 2)
     hex_string = "0" + hex_string;
 
   bin_string_r = "";
-  Byte const *byte = hex_string.to_bytes ();
-  int i = 0;
+  Byte const *byte = (Byte const*) hex_string.data ();
+  ssize i = 0;
   while (i < hex_string.length ())
     {
       int high_i = hex2nibble (*byte++);
@@ -121,10 +121,10 @@ String_convert::hex2bin (String hex_string, String &bin_string_r)
   return 0;
 }
 
-String
-String_convert::hex2bin (String hex_string)
+Std_string
+String_convert::hex2bin (Std_string hex_string)
 {
-  String str;
+  Std_string str;
   //  silly, asserts should alway be "on"!
   //    assert (!hex2bin (hex_string, str) );
   int error_i = hex2bin (hex_string, str);
@@ -145,7 +145,7 @@ String_convert::hex2nibble (Byte byte)
 }
 
 // stupido.  Should use int_string ()
-String
+Std_string
 String_convert::int2dec (int i, int length_i, char ch)
 {
   char fill_char = ch;
@@ -153,17 +153,17 @@ String_convert::int2dec (int i, int length_i, char ch)
     fill_char = '0';
 
   // ugh
-  String dec_string = to_string (i);
+  Std_string dec_string = to_string (i);
 
   // ugh
   return to_string (fill_char, length_i - dec_string.length ()) + dec_string;
 }
 
 // stupido.  Should use int_string ()
-String
-String_convert::unsigned2hex (unsigned u, int length_i, char fill_char)
+Std_string
+String_convert::unsigned2hex (unsigned u, ssize length, char fill_char)
 {
-  String str;
+  Std_string str;
   if (!u)
     str = "0";
 
@@ -177,14 +177,14 @@ String_convert::unsigned2hex (unsigned u, int length_i, char fill_char)
   str += int_string (u, "%x"); // hmm. %lx vs. %x -> portability?
 #endif
 
-  str = to_string (fill_char, length_i - str.length ()) + str;
-  while ((str.length () > length_i) && (str[ 0 ] == 'f'))
-    str = str.cut_string (2, INT_MAX);
+  str = to_string (fill_char, length - str.length ()) + str;
+  while ((str.length () > length) && (str[ 0 ] == 'f'))
+    str = str.substr (2);
 
   return str;
 }
 
-String
+Std_string
 String_convert::int2hex (int i, int length_i, char fill_char)
 {
   return unsigned2hex ((unsigned)i, length_i, fill_char);
@@ -204,16 +204,16 @@ String_convert::nibble2hex_byte (Byte byte)
    @param
    #fmt# is a printf style format, default assumes "%d" as format.
 */
-String
+Std_string
 String_convert::int_string (int i, char const *fmt)
 {
   char buffer[STRING_BUFFER_LEN];
   snprintf (buffer, STRING_BUFFER_LEN,
            (fmt ? fmt : "%d"), i); // assume radix 10
-  return String (buffer);
+  return Std_string (buffer);
 }
 
-String
+Std_string
 String_convert::form_string (char const *format, ...)
 {
   va_list args;
@@ -221,15 +221,15 @@ String_convert::form_string (char const *format, ...)
   char buffer[STRING_BUFFER_LEN];
   vsnprintf (buffer, STRING_BUFFER_LEN, format, args);
   va_end (args);
-  return String (buffer);
+  return Std_string (buffer);
 }
 
-String
+Std_string
 String_convert::vform_string (char const *format, va_list args)
 {
   char buffer[STRING_BUFFER_LEN];
   vsnprintf (buffer, STRING_BUFFER_LEN, format, args);
-  return String (buffer);
+  return Std_string (buffer);
 }
 
 /**
@@ -237,13 +237,13 @@ String_convert::vform_string (char const *format, va_list args)
 
    @param #fmt# is a printf style format, default assumes "%lf" as format
 */
-String
+Std_string
 String_convert::double_string (double f, char const *fmt)
 {
   char buf[STRING_BUFFER_LEN];
 
   snprintf (buf, STRING_BUFFER_LEN, fmt ? fmt : "%f", f);
-  return String (buf);
+  return Std_string (buf);
 }
 
 /**
@@ -252,29 +252,33 @@ String_convert::double_string (double f, char const *fmt)
    @param
    #n# is a repetition count, default value is 1
 */
-String
+Std_string
 String_convert::char_string (char c, int n)
 {
   n = n >= 0 ? n : 0;
   char *ch = new char[ n ];
   memset (ch, c, n);
-  String s ((Byte *)ch, n);
+#if STD_STRING
+  Std_string s (ch, n);
+#else
+  Std_string s ((Byte*) ch, n);
+#endif
   delete[] ch;
   return s;
 }
 
-String
+Std_string
 String_convert::rational_string (Rational r)
 {
   return r.to_string ();
 }
 
-String
+Std_string
 String_convert::pointer_string (void const *l)
 {
   char buffer[STRING_BUFFER_LEN];
   snprintf (buffer, STRING_BUFFER_LEN, "%p", l); // assume radix 10
-  return String (buffer);
+  return Std_string (buffer);
 }
 
 /**
@@ -283,57 +287,57 @@ String_convert::pointer_string (void const *l)
    @param
    #n# is the number of nonzero digits
 */
-String
+Std_string
 String_convert::precision_string (double x, int n)
 {
-  String format = "%." + to_string (max (0, n - 1)) + "e";
-  String str = double_string (abs (x), format.c_str ());
+  Std_string format = "%." + to_string (max (0, n - 1)) + "e";
+  Std_string str = double_string (abs (x), format.c_str ());
 
-  int exp = str.right_string (3).to_int ();
-  str = str.left_string (str.length () - 4);
+  int exp = dec2int (str.substr (str.length () - 3));
+  str = str.substr (0, str.length () - 4);
 
   while (str[str.length () - 1] == '0')
-    str = str.left_string (str.length () - 1);
+    str = str.substr (0, str.length () - 1);
   if (str[str.length () - 1] == '.')
-    str = str.left_string (str.length () - 1);
+    str = str.substr (0, str.length () - 1);
 
   if (exp == 0)
     return (sign (x) > 0 ? str : "-" + str);
 
-  str = str.left_string (1) + str.cut_string (2, INT_MAX);
-  int dot = 1 + exp;
+  str = str.substr (0, 1) + str.substr (2);
+  ssize dot = 1 + exp;
   if (dot <= 0)
     str = "0." + to_string ('0', -dot) + str;
   else if (dot >= str.length ())
     str += to_string ('0', dot - str.length ());
   else if ((dot > 0) && (dot < str.length ()))
-    str = str.left_string (dot) + "." + str.cut_string (dot, INT_MAX);
+    str = str.substr (0, dot) + "." + str.substr (dot);
   else
     assert (0);
 
   return (sign (x) > 0 ? str : "-" + str);
 }
 
-Array<String>
-String_convert::split (String str, char c)
+Array<Std_string>
+String_convert::split (Std_string str, char c)
 {
-  Array<String> a;
-  int i = str.index (c);
-  while (i >= 0)
+  Array<Std_string> a;
+  ssize i = str.find (c);
+  while (i != NPOS)
     {
-      String s = str.left_string (i);
+      Std_string s = str.substr (0, i);
       a.push (s);
       while (str[++i] == c)
        ;
-      str = str.cut_string (i, INT_MAX);
-      i = str.index (c);
+      str = str.substr (i);
+      i = str.find (c);
     }
   if (str.length ())
     a.push (str);
   return a;
 }
 
-String
+Std_string
 String_convert::long_string (long l)
 {
   char s[STRING_BUFFER_LEN];
@@ -341,8 +345,8 @@ String_convert::long_string (long l)
   return s;
 }
 
-String
-String_convert::pad_to (String s, int n)
+Std_string
+String_convert::pad_to (Std_string s, int n)
 {
-  return s + to_string (' ', max (n - s.length (), 0));
+  return s + Std_string (max (int(n - s.length ()), 0), ' ');
 }
index e3e8057f7e389903820893676d529f0ced01415c..ec4bd9024387559f5909b93d4885fbce66d375f4 100644 (file)
@@ -41,15 +41,35 @@ String::operator Std_string () const
 
 /* std::string interface */
 
+#if 0
+// FIXME, use .SUBSTR () ?
 String::String (String const &s, int pos, int n)
 {
-  if (n == -1)
+  if (n == -1 || n == INT_MAX || n == NPOS)
     n = s.length () - pos;
   if (pos == 0)
     *this = s.left_string (n);
   else
     *this = s.right_string (s.length () - pos).left_string (n);
 }
+#endif
+
+String
+String::substr (int pos, int n) const
+{
+#if 0
+  if (n == -1 || n == INT_MAX || n == NPOS)
+    n = length () - pos;
+  return cut_string (pos, n);
+#else
+  if (n == -1 || n == INT_MAX || n == NPOS)
+    n = length () - pos;
+  if (pos == 0)
+    return left_string (n);
+  else
+    return right_string (length () - pos).left_string (n);
+#endif
+}
 
 String::String (int n, char c)
 {
@@ -57,6 +77,12 @@ String::String (int n, char c)
 }
 
 
+char const *
+String::data () const
+{
+  return (char const*) to_bytes ();
+}
+
 bool
 String::empty () const
 {
@@ -76,9 +102,9 @@ String::find (String &s, int pos) const
     return index (s);
   String f = right_string (length () - pos);
   int n = f.index (s);
-  if (n != -1)
+  if (n != NPOS)
     return pos + n;
-  return -1;
+  return NPOS;
 }
 
 int
@@ -90,7 +116,7 @@ String::rfind (char c) const
 String
 String::replace (int pos, int n, String str)
 {
-  return String (*this, 0, pos) + str + String (*this, pos + n);
+  return this->substr (0, pos) + str + this->substr (pos + n);
 }
 
 
@@ -245,41 +271,20 @@ int
 String::index_last (char const c) const
 {
   if (!length ())
-    return -1;
+    return NPOS;
 
   char const *me = strh_.c_str ();
   char const *p = (char const *)memrchr ((Byte *)me, length (), c);
   if (p)
     return p - me;
-  return -1;
-}
-
-int
-String::index_last (char const *string) const // UGK!
-{
-  assert (false);              // broken
-  int len = strlen (string); // ugrh
-  if (!length () || !len)
-    return -1;
-
-  int next_i = index (string);
-  if (next_i == -1)
-    return -1;
-
-  int index_i = 0;
-  while (next_i >= 0)
-    {
-      index_i += next_i;
-      next_i = right_string (length () - index_i - len).index (string);
-    }
-  return index_i;
+  return NPOS;
 }
 
 /** find  a character.
 
 @return
 the index of the leftmost character #c# (0 <= return < length ()),
-or   -1 if not found.
+or   NPOS if not found.
 
 ? should return length ()?, as in string.left_string (index (delimiter))
 */
@@ -290,7 +295,7 @@ String::index (char c) const
   char const *p = (char const *) memchr (me, c, length ());
   if (p)
     return p - me;
-  return -1;
+  return NPOS;
 }
 
 /**
@@ -311,14 +316,14 @@ String::index (String searchfor) const
   if (p)
     return p - me;
 
-  return -1;
+  return NPOS;
 }
 
 /** find chars of a set.
 
 @return
 
-the index of the leftmost occurance of an element of #set#.  -1 if
+the index of the leftmost occurance of an element of #set#.  NPOS if
 nothing is found.
 */
 int
@@ -326,7 +331,7 @@ String::index_any (String set) const
 {
   int n = length ();
   if (!n)
-    return -1;
+    return NPOS;
 
   void const *me = (void const *) strh_.c_str ();
   for (int i = 0; i < set.length (); i++)
@@ -335,7 +340,7 @@ String::index_any (String set) const
       if (found)
        return found - (char const *)me;
     }
-  return -1;
+  return NPOS;
 }
 \f
 String
@@ -452,7 +457,7 @@ String::substitute (String find, String replace)
 {
   int n = find.length ();
   int m = replace.length ();
-  for (int i = index (find), j = 0; i > -1;
+  for (int i = index (find), j = 0; i != NPOS;
        i = right_string (length () - j).index (find))
     {
       *this = left_string (i + j)
@@ -466,7 +471,7 @@ String::substitute (String find, String replace)
 String
 String::substitute (char find, char replace)
 {
-  for (int i = index (find); i > - 1; i = index (find))
+  for (int i = index (find); i != NPOS; i = index (find))
     (*this)[i] = replace;
   return *this;
 }
index 2b1afe115e31ca217836324988ff9aee4c7d0c56..de3d8f0e8c37b631a2a6a6fc3f3623c07984d1c5 100644 (file)
@@ -23,7 +23,6 @@
 #define GUILE_ELLIPSIS 
 #endif
 
-
 #include "guile-compatibility.hh"
 #include "interval.hh"
 #include "lily-guile-macros.hh"
index f1c0488e3fc1121929223a4ed14b65a81f677f0e..faa02a66e66ef2fdc0a518d7aa4e607281bf0707 100644 (file)
@@ -356,7 +356,7 @@ ly_assoc_cdr (SCM key, SCM alist)
 }
 
 SCM
-ly_string_array_to_scm (Array<String> a)
+ly_string_array_to_scm (Array<Std_string> a)
 {
   SCM s = SCM_EOL;
   for (int i = a.size () - 1; i >= 0; i--)
index 93a5ceba88128a47263880af2f635478f5ee6805..da44cba73b1b11b998869e6c38ac8c7068981fd2 100644 (file)
@@ -25,18 +25,18 @@ Lilypond_version::Lilypond_version (String str)
   minor_ = 0;
   patch_ = 0;
   
-  Array<String> version;
+  Array<Std_string> version;
   version = String_convert::split (str, '.');
 
   if (version.size () > 0 && isdigit (version[0][0]))
-    major_ = version[0].to_int ();
+    major_ = String_convert::dec2int (version[0]);
   if (version.size () > 1 && isdigit (version[1][0]))
-    minor_ = version[1].to_int ();
+    minor_ = String_convert::dec2int (version[1]);
   
   patch_ = 0;
   if (version.size () >= 3
       && isdigit (version[2][0]))
-    patch_ = version[2].to_int ();
+    patch_ = String_convert::dec2int (version[2]);
 
   if (version.size () >= 4)
     extra_patch_string_ = version[3];
index daac5b01c05d63288beb5e87e06483d162ceadf8..fa0d356f0a90723b041956b3c95cffd50f504307 100644 (file)
@@ -299,7 +299,7 @@ do_chroot_jail ()
       USER_NAME, GROUP_NAME, JAIL, DIR, JAIL_MAX
     };
 
-  Array<String> components = String_convert::split (jail_spec, ',');
+  Array<Std_string> components = String_convert::split (jail_spec, ',');
   if (components.size () != JAIL_MAX)
     {
       error (_f ("expected %d arguments with jail, found: %d", JAIL_MAX,
index 1c1d15d1f6879ae02d559bffb804c178833dd654..d2581833b634cc307a29a2a19e29c883c81fdccb 100644 (file)
@@ -20,7 +20,7 @@ Interval_t<Rational>::infinity ()
 }
 
 template<>
-String
+Std_string
 Interval_t<Rational>::T_to_string (Rational a)
 {
   return a.to_string ();