X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Fstd-string.cc;h=6d8ebd52f5ba7fe7d00319176feec7150b14eb9d;hb=666c669990584a38b18cd00f50f22d93959d4f18;hp=62edc829bee6cdec1cb309efe24a68e2dea43478;hpb=48ca3ba1f7e7de37716da3b6dfa2b223114c0cad;p=lilypond.git diff --git a/flower/std-string.cc b/flower/std-string.cc index 62edc829be..6d8ebd52f5 100644 --- a/flower/std-string.cc +++ b/flower/std-string.cc @@ -1,5 +1,5 @@ /* - std-tring.cc -- implement external interface for Std_String + std-string.cc -- implement external interface for Std_String source file of the GNU LilyPond music typesetter @@ -7,38 +7,118 @@ */ #include "std-string.hh" +#include "string-convert.hh" -#if STD_STRING +string +to_string (string s) +{ + return s; +} + +string +to_string (char c, int n) +{ + return string (max (n, 0), c); +} + +string +to_string (double f, char const *format) +{ + return String_convert::double_string (f, format); +} + +string +to_string (int i, char const *format) +{ + return String_convert::int_string (i, format); +} -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); - } +string +to_string (bool b) +{ + return String_convert::bool_string (b); +} -#define FIND_FAILED string::npos -#define SIZE_T size_t -#else /* !STD_STRING */ +string +to_string (long b) +{ + return String_convert::long_string (b); +} + +string +to_string (long unsigned b) +{ + return String_convert::unsigned_string (b); +} -#define FIND_FAILED -1 -#define SIZE_T int +string +to_string (unsigned u) +{ + return String_convert::unsigned_string (u); +} -#endif /* STD_STRING */ +string +to_string (char const *format, ...) +{ + va_list args; + va_start (args, format); + string str = String_convert::vform_string (format, args); + va_end (args); + return str; +} -Std_string & -replace_all (Std_string &str, Std_string find, Std_string replace) +string & +replace_all (string &str, string find, 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; } -#if STD_STRING +string & +replace_all (string &str, char find, char replace) +{ + for (ssize i = str.find (find); i != NPOS; i = str.find (find, i + 1)) + str[i] = replace; + return str; +} + +char * +string_copy (string s) +{ + ssize len = s.length (); + char *dest = new char[len + 1]; + copy (s.begin (), s.end (), dest); + dest[len] = 0; + + return dest; +} + +int +string_compare (string const &a, string const &b) +{ + return a.compare (b); +} + +#include "std-vector.hh" + +vector +string_split (string str, char c) +{ + ssize i = str.find (c); + + vector a; + while (i != NPOS) + { + string s = str.substr (0, i); + a.push_back (s); + while (str[++i] == c) + ; + str = str.substr (i); + i = str.find (c); + } + if (str.length ()) + a.push_back (str); + return a; } -#endif