]> git.lyx.org Git - lyx.git/commitdiff
Use typedef for std::basic_string in trivstring
authorGeorg Baum <baum@lyx.org>
Sun, 28 Dec 2014 16:06:34 +0000 (17:06 +0100)
committerGeorg Baum <baum@lyx.org>
Sun, 28 Dec 2014 16:06:34 +0000 (17:06 +0100)
This fixes compilation for llvm-gcc-4.2 on OS X and makes the code a bit more
readable.

src/support/trivstring.cpp
src/support/trivstring.h

index fad1565c6a621cb4182b75eef9b57e00cb0d1690..c780aa7f6d4eab9037fee46c7b5c41e0e17b8a82 100644 (file)
@@ -59,8 +59,7 @@ trivial_string<Char>::trivial_string(Char const * that, size_t n) : size_(n)
 template trivial_string<char>::trivial_string(string const &);
 template trivial_string<char_type>::trivial_string(docstring const &);
 template<typename Char>
-trivial_string<Char>::trivial_string(
-               basic_string<Char, char_traits<Char>, allocator<Char> > const & that)
+trivial_string<Char>::trivial_string(_stdstring const & that)
        : size_(that.length())
 {
        if (use_sso()) {
@@ -108,7 +107,7 @@ template trivial_string<char_type> &
 trivial_string<char_type>::operator=(docstring const &);
 template<typename Char>
 trivial_string<Char> &
-trivial_string<Char>::operator=(basic_string<Char, char_traits<Char>, allocator<Char> > const & that)
+trivial_string<Char>::operator=(_stdstring const & that)
 {
        if (!use_sso())
                delete[] data_;
@@ -167,7 +166,7 @@ trivial_string<Char> trivial_string<Char>::substr(size_t pos, size_t n) const
 {
        if (pos > length())
                throw out_of_range("trivial_string::substr");
-       if (n == basic_string<Char, char_traits<Char>, allocator<Char> >::npos)
+       if (n == _stdstring::npos)
                n = length() - pos; 
        size_t const l = min(pos + n, length());
        return trivial_string(c_str() + pos, l - pos);
@@ -177,16 +176,14 @@ trivial_string<Char> trivial_string<Char>::substr(size_t pos, size_t n) const
 template trivial_string<char>::operator string() const;
 template trivial_string<char_type>::operator docstring() const;
 template<typename Char>
-trivial_string<Char>::operator basic_string<Char, char_traits<Char>, allocator<Char> >() const
+trivial_string<Char>::operator _stdstring() const
 {
        if (use_sso())
-               return basic_string<Char, char_traits<Char>, allocator<Char> >(
-                               data_sso(), size_);
+               return _stdstring(data_sso(), size_);
        if (size_ > 0)
-               return basic_string<Char, char_traits<Char>, allocator<Char> >(
-                               data_, size_);
+               return _stdstring(data_, size_);
        // Happens only for really big Char types
-       return basic_string<Char, char_traits<Char>, allocator<Char> >();
+       return _stdstring();
 }
 
 
index a54889c2d77c56f1c0f760810f4e5412b916ee66..6b935eee02eb325ad6cbe200de1334ba29b91cf5 100644 (file)
@@ -39,6 +39,8 @@ namespace lyx {
 template <typename Char> class trivial_string
 {
 public:
+       /// Corresponding std::basic_string
+       typedef std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> > _stdstring;
        /// Construct an empty string
        trivial_string() : size_(0), data_(0) {}
        /// Construct a string from a copy of \p that
@@ -46,13 +48,13 @@ public:
        /// Construct a string from a copy of \p that
        trivial_string(Char const * that, size_t n);
        /// Construct a string from a copy of \p that
-       trivial_string(std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> > const & that);
+       trivial_string(_stdstring const & that);
        ///
        ~trivial_string() { if (!use_sso()) delete[] data_; }
        /// Assign a copy of \p that
        trivial_string & operator=(trivial_string const & that);
        /// Assign a copy of \p that
-       trivial_string & operator=(std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> > const & that);
+       trivial_string & operator=(_stdstring const & that);
        /// Exchange contents with contents of \p that
        void swap(trivial_string & that);
        /// The length of the string, excluding the final 0 character
@@ -62,10 +64,9 @@ public:
        /// Is this string ordered before, at the same position or after \p other?
        int compare(trivial_string const & other) const;
        /// Return substring of length \p n starting at \p pos
-       trivial_string substr(size_t pos = 0, size_t n = std::basic_string<Char,
-                               std::char_traits<Char>, std::allocator<Char> >::npos) const;
+       trivial_string substr(size_t pos = 0, size_t n = _stdstring::npos) const;
        /// Create a copy as std::basic_string
-       operator std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> >() const;
+       operator _stdstring() const;
        /// Return a C-compatible string, terminated by a 0 character.
        /// This is never a copy and only valid for the life time of the trivial_string instance.
        Char const * c_str() const;