]> git.donarmstrong.com Git - lilypond.git/commitdiff
* configure.in (--enable-std-string): New option.
authorjanneke <janneke>
Sun, 22 Jan 2006 20:56:17 +0000 (20:56 +0000)
committerjanneke <janneke>
Sun, 22 Jan 2006 20:56:17 +0000 (20:56 +0000)
* flower/std-string.cc:
* flower/include/std-string.hh: New file.

* flower/file-name.cc[STD_STRING]:
* flower/include/file-name.hh[STD_STRING]: Use it.

ChangeLog
configure.in
flower/file-name.cc
flower/file-path.cc
flower/include/file-name.hh
flower/include/std-string.hh [new file with mode: 0644]
flower/include/string.hh
flower/std-string.cc [new file with mode: 0644]
flower/string.cc

index 48dc685a44f7802738e1106e17ded7c9922fdd40..9e4da867d4347d1a084af4d5738c8132085bacda 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-01-22  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * configure.in (--enable-std-string): New option.
+
+       * flower/std-string.cc: 
+       * flower/include/std-string.hh: New file.
+
+       * flower/file-name.cc[STD_STRING]:
+       * flower/include/file-name.hh[STD_STRING]: Use it.
+
 2006-01-22  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
        * scm/define-markup-commands.scm (with-dimensions):
index a4910f113011e8454a631feb56679b75cb2239e0..d2818093a7df0f23d94542c1e5335acf6012ed37 100644 (file)
@@ -30,9 +30,18 @@ AC_SUBST(DOCUMENTATION)
 
 gui_b=no
 AC_ARG_ENABLE(gui,
-    [  --enable-gui            compile with experimental GNOME output module.  Default: off],
+    [  --enable-gui            compile with experimental GNOME output.  Default: off],
     [gui_b=$enableval])
 
+std_string=no
+AC_ARG_ENABLE(std-string,
+    [  --enable-std-string     compile with experimental std::string.  Default: off],
+    [std_string=$enableval])
+if test "$std_string" = "yes"; then
+    # Store in config.make rather than in config.hh and have every
+    # source file depend on that.
+    DEFINES="$DEFINES -DSTD_STRING=1"
+fi
 
 NCSB_DIR=unknown
 AC_ARG_WITH(ncsb-dir,
index b75e44fdbfc559ce034f7661f9bce2cf2cf934ca..d10e5b4c6a430a1f85068ec30afd8b4bf3838c12 100644 (file)
@@ -36,8 +36,8 @@ using namespace std;
 #endif
 
 #ifdef __CYGWIN__
-static String
-dos_to_posix (String file_name)
+static Std_string
+dos_to_posix (Std_string file_name)
 {
   char buf[PATH_MAX] = "";
   char *s = file_name.get_copy_str0 ();
@@ -53,8 +53,8 @@ dos_to_posix (String file_name)
 #ifdef __MINGW32__
 /** Use slash as directory separator.  On Windows, they can pretty
     much be exchanged.  */
-static String
-slashify (String file_name)
+static Std_string
+slashify (Std_string file_name)
 {
   file_name.substitute ('\\', '/');
   file_name.substitute ("//", "/");
@@ -63,25 +63,25 @@ slashify (String file_name)
 #endif /* __MINGW32__ */
 
 /* Join components to full file_name. */
-String
+Std_string
 File_name::to_string () const
 {
-  String s;
-  if (!root_.is_empty ())
-    s = root_ + ::to_string (ROOTSEP);
-  if (!dir_.is_empty ())
+  Std_string s;
+  if (!root_.empty ())
+    s = root_ + ::to_std_string (ROOTSEP);
+  if (!dir_.empty ())
     {
       s += dir_;
-      if (!base_.is_empty () || !ext_.is_empty ())
-       s += ::to_string (DIRSEP);
+      if (!base_.empty () || !ext_.empty ())
+       s += ::to_std_string (DIRSEP);
     }
   s += base_;
-  if (!ext_.is_empty ())
-    s += ::to_string (EXTSEP) + ext_;
+  if (!ext_.empty ())
+    s += ::to_std_string (EXTSEP) + ext_;
   return s;
 }
 
-File_name::File_name (String file_name)
+File_name::File_name (Std_string file_name)
 {
 #ifdef __CYGWIN__
   /* All system functions would work, even if we do not convert to
@@ -93,25 +93,25 @@ File_name::File_name (String file_name)
   file_name = slashify (file_name);
 #endif
 
-  int i = file_name.index (ROOTSEP);
+  int i = file_name.find (ROOTSEP);
   if (i >= 0)
     {
-      root_ = file_name.left_string (i);
-      file_name = file_name.right_string (file_name.length () - i - 1);
+      root_ = Std_string (file_name, 0, i);
+      file_name = Std_string (file_name, i + 1);
     }
 
-  i = file_name.index_last (DIRSEP);
+  i = file_name.rfind (DIRSEP);
   if (i >= 0)
     {
-      dir_ = file_name.left_string (i);
-      file_name = file_name.right_string (file_name.length () - i - 1);
+      dir_ = Std_string (file_name, 0, i);
+      file_name = Std_string (file_name, i + 1);
     }
 
-  i = file_name.index_last ('.');
+  i = file_name.rfind ('.');
   if (i >= 0)
     {
-      base_ = file_name.left_string (i);
-      ext_ = file_name.right_string (file_name.length () - i - 1);
+      base_ = Std_string (file_name, 0, i);
+      ext_ = Std_string (file_name, i + 1);
     }
   else
     base_ = file_name;
@@ -125,3 +125,10 @@ File_name::is_absolute () const
    */
   return (dir_.length () && dir_[0] == DIRSEP) || root_.length ();
 }
+
+#if 0 //STD_STRING
+File_name::File_name (String file_name)
+{
+  *this = File_name (Std_string (file_name));
+}
+#endif
index 74b0b25cd055aae9345e868dd68d7f9c017e76e3..d6e0e0440300bf2f3bbe7c368597a70c437aed7a 100644 (file)
@@ -125,12 +125,12 @@ File_path::find (String name) const
   for (int i = 0; i < dirs_.size (); i++)
     {
       File_name file_name (name);
-      File_name dir = dirs_[i];
+      File_name dir = (Std_string) dirs_[i];
       file_name.root_ = dir.root_;
       dir.root_ = "";
-      if (file_name.dir_.is_empty ())
+      if (file_name.dir_.empty ())
        file_name.dir_ = dir.to_string ();
-      else if (!dir.to_string ().is_empty ())
+      else if (!dir.to_string ().empty ())
        file_name.dir_ = dir.to_string ()
          + ::to_string (DIRSEP) + file_name.dir_;
       if (is_file (file_name.to_string ()))
@@ -157,7 +157,7 @@ File_path::find (String name, char const *extensions[])
   for (int i = 0; extensions[i]; i++)
     {
       file_name.ext_ = orig_ext;
-      if (*extensions[i] && !file_name.ext_.is_empty ())
+      if (*extensions[i] && !file_name.ext_.empty ())
        file_name.ext_ += ".";
       file_name.ext_ += extensions[i];
       String found = find (file_name.to_string ());
index 8defff15ca38b57cf6fa25d83497ed2a392d5f27..e6247986f96609f5d0dd398c3d2fae46df9ad5eb 100644 (file)
 #define FILE_NAME_HH
 
 #include "array.hh"
+#include "std-string.hh"
+
+#if 0// STD_STRING
 #include "string.hh"
+#endif
 
 class File_name
 {
 public:
-  String root_;
-  String dir_;
-  String base_;
-  String ext_;
+  Std_string root_;
+  Std_string dir_;
+  Std_string base_;
+  Std_string ext_;
 
+  File_name (Std_string);
+#if 0// STD_STRING
   File_name (String);
+#endif
 
   bool is_absolute () const;
-  String to_string () const;
+  Std_string to_string () const;
 };
 
 #endif /* FILE_NAME */
diff --git a/flower/include/std-string.hh b/flower/include/std-string.hh
new file mode 100644 (file)
index 0000000..d2b2ffd
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+  std-string.hh -- declare Std_string
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2006 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef STD_STRING_HH
+#define STD_STRING_HH
+
+#if !STD_STRING
+
+#define Std_string
+#define to_std_string to_string
+#include "string.hh"
+
+#else
+
+#include <string>
+#warning Using std::string
+
+namespace std {
+
+#if 0
+  class Std_string : public string
+  {
+  public:
+    Std_string ();
+    Std_string (char const*);
+    Std_string (Std_string const&, int pos, int n=npos);
+    ///Std_string (String const&, int pos, int n);
+    ////Std_string (String const &);
+    ////operator String ();
+  };
+#else  
+  typedef string Std_string;
+#endif
+
+  //operator Std_string (String const&);
+
+  Std_string to_std_string (Std_string s);
+  Std_string to_std_string (char c, int n = 1);
+  Std_string to_std_string (int i, char const *format = 0);
+  Std_string to_std_string (double f, char const *format = 0);
+  Std_string to_std_string (long b);
+  Std_string to_std_string (bool b);
+  Std_string to_std_string (char const *format, ...);
+}
+
+#endif /* STD_STRING */
+
+#endif /* STD_STRING_HH */
index ed5773e73c96ed2b9259aeddbeac9c1d1d432575..bf83b5ba8fd6e4482921bea0649d375c98af48a5 100644 (file)
@@ -17,6 +17,8 @@
 class ostream;
 #endif
 #endif
+
+#include "std-string.hh"
 using namespace std;
 
 #include "arithmetic-operator.hh"
@@ -56,6 +58,22 @@ convert to char const* .
 */
 class String
 {
+public:
+
+#if STD_STRING
+  String (Std_string const &);
+  operator Std_string () const;
+#endif /* STD_STRING */
+
+  /* std::string interface */
+  char const *c_str () const;
+  bool empty () const;
+  int size () const;
+  int find (char c) const;
+  int rfind (char c) const;
+
+  String (String const &, int pos, int n=-1);
+
 protected:
   String_handle strh_;
 
diff --git a/flower/std-string.cc b/flower/std-string.cc
new file mode 100644 (file)
index 0000000..d457d50
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+  std-tring.cc -- implement external interface for Std_String
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2006  Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#if STD_STRING
+#include "std-string.hh"
+
+namespace std {
+  Std_string to_std_string (char c, int n)
+  {
+    /* FIXME, remove this function and use std::string interface for
+       String?  This interface is a bit clumsy, almost alway you want
+       n=1.  */
+    return Std_string (n, c);
+  }
+}
+
+#endif /* STD_STRING */
index 4d7fd9019bc096bafb9030334b934743293c158d..622ef5917e1c5954a3f77bcb3d2eabec8356e9a3 100644 (file)
@@ -21,6 +21,64 @@ using namespace std;
 #include "libc-extension.hh"
 #include "string-convert.hh"
 
+#if STD_STRING
+
+#include "std-string.hh"
+
+String::String (Std_string const &s)
+{
+  *this = String (s.c_str ());
+}
+#endif
+
+
+String::String (String const &s, int pos, int n)
+{
+  if (n == -1)
+    n = s.size () - pos;
+  if (pos == 0)
+    *this = s.left_string (n);
+  else
+    *this = s.right_string (s.size () - pos).left_string (n);
+}
+
+String::operator Std_string () const
+{
+  return Std_string (this->c_str ());
+}
+
+char const *
+String::c_str () const
+{
+  return to_str0 ();
+}
+
+bool
+String::empty () const
+{
+  return is_empty ();
+}
+
+int
+String::size () const
+{
+  return length ();
+}
+
+int
+String::find (char c) const
+{
+  return index (c);
+}
+
+int
+String::rfind (char c) const
+{
+  return index_last (c);
+}
+
+
+
 #ifdef STRING_DEBUG
 void *mymemmove (void *dest, void const *src, size_t n);
 #define memmove mymemmove