Add operator+ for ASCII characters and ASCII C strings

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14969 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-09-11 07:13:56 +00:00
parent bb61b2655f
commit 189d298d96
2 changed files with 50 additions and 0 deletions

View File

@ -68,3 +68,40 @@ bool operator==(lyx::docstring const & l, char const * r)
} }
return r[len] == '\0'; return r[len] == '\0';
} }
lyx::docstring operator+(lyx::docstring const & l, char const * r)
{
lyx::docstring s(l);
for (char const * c = r; *c; ++c) {
BOOST_ASSERT(static_cast<unsigned char>(*c) < 0x80);
s.push_back(*c);
}
return s;
}
lyx::docstring operator+(char const * l, lyx::docstring const & r)
{
lyx::docstring s;
for (char const * c = l; *c; ++c) {
BOOST_ASSERT(static_cast<unsigned char>(*c) < 0x80);
s.push_back(*c);
}
s += r;
return s;
}
lyx::docstring operator+(lyx::docstring const & l, char r)
{
BOOST_ASSERT(static_cast<unsigned char>(r) < 0x80);
return l + lyx::docstring::value_type(r);
}
lyx::docstring operator+(char l, lyx::docstring const & r)
{
BOOST_ASSERT(static_cast<unsigned char>(l) < 0x80);
return lyx::docstring::value_type(l) + r;
}

View File

@ -47,6 +47,19 @@ inline bool operator!=(lyx::docstring const & l, char const * r) { return !(l ==
/// Compare a C string of ASCII characters with a docstring /// Compare a C string of ASCII characters with a docstring
inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); } inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); }
/// Concatenate a docstring and a C string of ASCII characters
lyx::docstring operator+(lyx::docstring const &, char const *);
/// Concatenate a C string of ASCII characters and a docstring
lyx::docstring operator+(char const *, lyx::docstring const &);
/// Concatenate a docstring and a single ASCII character
lyx::docstring operator+(lyx::docstring const & l, char r);
/// Concatenate a single ASCII character and a docstring
lyx::docstring operator+(char l, lyx::docstring const & r);
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
// Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn. // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
namespace std { namespace std {