From: Jan Nieuwenhuizen Date: Sun, 22 Jan 2006 20:56:17 +0000 (+0000) Subject: * configure.in (--enable-std-string): New option. X-Git-Tag: release/2.7.29~39 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=df5e5095a9275a20e2c89326ee7fcf47cdd6a45b;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 48dc685a44..9e4da867d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-22 Jan Nieuwenhuizen + + * 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 * scm/define-markup-commands.scm (with-dimensions): diff --git a/configure.in b/configure.in index a4910f1130..d2818093a7 100644 --- a/configure.in +++ b/configure.in @@ -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, diff --git a/flower/file-name.cc b/flower/file-name.cc index b75e44fdbf..d10e5b4c6a 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -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 diff --git a/flower/file-path.cc b/flower/file-path.cc index 74b0b25cd0..d6e0e04403 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -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 ()); diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh index 8defff15ca..e6247986f9 100644 --- a/flower/include/file-name.hh +++ b/flower/include/file-name.hh @@ -10,20 +10,27 @@ #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 index 0000000000..d2b2ffd1a3 --- /dev/null +++ b/flower/include/std-string.hh @@ -0,0 +1,53 @@ +/* + std-string.hh -- declare Std_string + + source file of the GNU LilyPond music typesetter + + (c) 2006 Jan Nieuwenhuizen +*/ + +#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 +#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 */ diff --git a/flower/include/string.hh b/flower/include/string.hh index ed5773e73c..bf83b5ba8f 100644 --- a/flower/include/string.hh +++ b/flower/include/string.hh @@ -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 index 0000000000..d457d50655 --- /dev/null +++ b/flower/std-string.cc @@ -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 +*/ + +#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 */ diff --git a/flower/string.cc b/flower/string.cc index 4d7fd9019b..622ef5917e 100644 --- a/flower/string.cc +++ b/flower/string.cc @@ -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