+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):
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,
#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 ();
#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 ("//", "/");
#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
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;
*/
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
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 ()))
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 ());
#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 */
--- /dev/null
+/*
+ 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 */
class ostream;
#endif
#endif
+
+#include "std-string.hh"
using namespace std;
#include "arithmetic-operator.hh"
*/
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_;
--- /dev/null
+/*
+ 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 */
#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