2 std-string.cc -- implement external interface for Std_String
4 source file of the GNU LilyPond music typesetter
6 (c) 2006--2008 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "std-string.hh"
10 #include "string-convert.hh"
19 to_string (char c
, int n
)
21 return string (max (n
, 0), c
);
25 to_string (double f
, char const *format
)
27 return String_convert::double_string (f
, format
);
31 to_string (int i
, char const *format
)
33 return String_convert::int_string (i
, format
);
39 return String_convert::bool_string (b
);
45 return String_convert::long_string (b
);
49 to_string (long unsigned b
)
51 return String_convert::unsigned_string (b
);
55 to_string (unsigned u
)
57 return String_convert::unsigned_string (u
);
61 to_string (I64 b
, char const *format
)
63 return String_convert::i64_string (b
, format
);
67 to_string (char const *format
, ...)
70 va_start (args
, format
);
71 string str
= String_convert::vform_string (format
, args
);
77 TODO: this O(n^2) in #occurences of find, due to repeated copying.
80 replace_all (string
*str
, string
const &find
, string
const &replace
)
82 ssize len
= find
.length ();
83 for (ssize i
= str
->find (find
); i
!= NPOS
; i
= str
->find (find
, i
+ len
))
84 *str
= str
->replace (i
, len
, replace
);
89 replace_all (string
*str
, char find
, char replace
)
91 for (ssize i
= str
->find (find
); i
!= NPOS
; i
= str
->find (find
, i
+ 1))
97 string_copy (string s
)
99 ssize len
= s
.length ();
100 char *dest
= new char[len
+ 1];
101 copy (s
.begin (), s
.end (), dest
);
108 string_compare (string
const &a
, string
const &b
)
110 return a
.compare (b
);
113 #include "std-vector.hh"
116 string_split (string str
, char c
)
118 ssize i
= str
.find (c
);
123 string s
= str
.substr (0, i
);
126 str
= str
.substr (i
);
135 string_join (vector
<string
> const &strs
, string infix
)
138 for (vsize i
= 0; i
< strs
.size (); i
++)