2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2015 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "std-string.hh"
21 #include "string-convert.hh"
22 #include "std-vector.hh"
25 to_string (const string &s)
31 to_string (char c, int n)
33 return string (max (n, 0), c);
37 to_string (double f, char const *format)
39 return String_convert::double_string (f, format);
43 to_string (int i, char const *format)
45 return String_convert::int_string (i, format);
51 return String_convert::bool_string (b);
57 return String_convert::long_string (b);
61 to_string (long unsigned b)
63 return String_convert::unsigned_long_string (b);
67 to_string (unsigned u)
69 return String_convert::unsigned_string (u);
73 to_string (I64 b, char const *format)
75 return String_convert::i64_string (b, format);
79 to_string (char const *format, ...)
82 va_start (args, format);
83 string str = String_convert::vform_string (format, args);
89 TODO: this O(n^2) in #occurences of find, due to repeated copying.
92 replace_all (string *str, string const &find, string const &replace)
94 ssize len = find.length ();
95 ssize replen = replace.length ();
96 for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + replen))
97 * str = str->replace (i, len, replace);
102 replace_all (string *str, char find, char replace)
104 for (ssize i = str->find (find); i != NPOS; i = str->find (find, i + 1))
110 string_copy (const string &s)
112 ssize len = s.length ();
113 char *dest = new char[len + 1];
114 copy (s.begin (), s.end (), dest);
121 string_split (string str, char c)
123 ssize i = str.find (c);
128 string s = str.substr (0, i);
131 str = str.substr (i);
140 string_join (vector<string> const &strs, const string &infix)
143 for (vsize i = 0; i < strs.size (); i++)