]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxstring.C
small cleanup, doxygen, formatting changes
[lyx.git] / src / support / lyxstring.C
index 65ef99a00fc92f681dee3cb5414f61a8591e18e8..bc17eef026a3cc8252fabeecf664c69c4a86c7a7 100644 (file)
@@ -3,8 +3,8 @@
  * 
  *           LyX, The Document Processor
  *      
- *         Copyright (C) 1995 Matthias Ettrich
- *          Copyright (C) 1995-1999 The LyX Team.
+ *         Copyright 1995 Matthias Ettrich
+ *          Copyright 1995-2000 The LyX Team.
  *
  * ====================================================== */
 
 
 #include "LAssert.h"
 
+#include "debug.h"
+
 using std::min;
+using std::istream;
+using std::ostream;
 
 // This class is supposed to be functionaly equivalent to a
 // standard conformant string. This mean among others that we
@@ -59,6 +63,7 @@ using std::min;
 
 // Lgb.
 
+
 ///////////////////////////////////////
 // The internal string representation
 ///////////////////////////////////////
@@ -111,10 +116,10 @@ private:
 };
 
 
-inline
 lyxstring::Srep::Srep(lyxstring::size_type nsz, const value_type * p)
 {
-// can be called with p == 0 by lyxstring::assign(const value_type *, size_type)
+       // can be called with p == 0 by
+       // lyxstring::assign(const value_type *, size_type)
 
        sz = nsz;
        ref = 1;
@@ -131,7 +136,6 @@ lyxstring::Srep::Srep(lyxstring::size_type nsz, const value_type * p)
 }
 
 
-inline
 lyxstring::Srep::Srep(lyxstring::size_type nsz, value_type ch)
 {
        sz = nsz;
@@ -147,10 +151,10 @@ lyxstring::Srep::Srep(lyxstring::size_type nsz, value_type ch)
 }
        
 
-inline
 void lyxstring::Srep::assign(lyxstring::size_type nsz, const value_type * p)
 {
-// can be called with p == 0 by lyxstring::assign(const value_type *, size_type)
+       // can be called with p == 0
+       // by lyxstring::assign(const value_type *, size_type)
 
        if (res < nsz) {
                delete[] s;
@@ -171,7 +175,6 @@ void lyxstring::Srep::assign(lyxstring::size_type nsz, const value_type * p)
 }
 
 
-inline
 void lyxstring::Srep::assign(lyxstring::size_type nsz, value_type ch)
 {
        sz = nsz;
@@ -189,7 +192,6 @@ void lyxstring::Srep::assign(lyxstring::size_type nsz, value_type ch)
 }
 
 
-inline
 void lyxstring::Srep::append(lyxstring::size_type asz, const value_type * p)
 {
        register unsigned int const len = sz + asz;
@@ -210,7 +212,6 @@ void lyxstring::Srep::append(lyxstring::size_type asz, const value_type * p)
 }
 
 
-inline
 void lyxstring::Srep::push_back(value_type c)
 {
        s[sz] = c; // it is always room to put a value_type at the end
@@ -227,9 +228,8 @@ void lyxstring::Srep::push_back(value_type c)
 }
 
 
-inline
 void lyxstring::Srep::insert(lyxstring::size_type pos, const value_type * p,
-                          lyxstring::size_type n)
+                            lyxstring::size_type n)
 {
        if (res < n + sz) {
                do {
@@ -250,7 +250,6 @@ void lyxstring::Srep::insert(lyxstring::size_type pos, const value_type * p,
 }
 
 
-inline
 void lyxstring::Srep::resize(size_type n, value_type c)
 {
        // This resets sz to res_arg
@@ -265,7 +264,6 @@ void lyxstring::Srep::resize(size_type n, value_type c)
 }
 
 
-inline
 void lyxstring::Srep::reserve(lyxstring::size_type res_arg)
 {
        // This keeps the old sz, but
@@ -278,9 +276,8 @@ void lyxstring::Srep::reserve(lyxstring::size_type res_arg)
 }
 
 
-inline
 void lyxstring::Srep::replace(lyxstring::size_type i, lyxstring::size_type n,
-                           value_type const * p, size_type n2)
+                             value_type const * p, size_type n2)
 {
 // can be called with p= 0 and n2= 0
        n = min(sz - i, n);
@@ -307,7 +304,7 @@ void lyxstring::Srep::replace(lyxstring::size_type i, lyxstring::size_type n,
 ///////////////////////////////////////
 // The lyxstring Invariant tester
 ///////////////////////////////////////
-#ifdef DEVEL_VERSION
+#ifdef ENABLE_ASSERTIONS
 
 /** Testing of the lyxstring invariant
  * By creating an object that tests the lyxstring invariant during its
@@ -351,7 +348,6 @@ private:
 // NOTE: The easiest way to catch this snippet of the output is to wait for
 //       the splash screen to disappear and then open and close Help->Credits
 //
-inline
 lyxstringInvariant::lyxstringInvariant(lyxstring const * ls) : object(ls)
 {
        // printf("lyxstringInvariant constructor\n");
@@ -359,7 +355,6 @@ lyxstringInvariant::lyxstringInvariant(lyxstring const * ls) : object(ls)
 }
 
 
-inline
 lyxstringInvariant::~lyxstringInvariant()
 {
        helper();
@@ -367,7 +362,6 @@ lyxstringInvariant::~lyxstringInvariant()
 }
 
 
-inline
 void lyxstringInvariant::helper() const
 {
        // Some of these tests might look pointless but they are
@@ -389,7 +383,7 @@ void lyxstringInvariant::helper() const
 #define TestlyxstringInvariant(s) lyxstringInvariant lyxstring_invariant(s);
 #else
 #define TestlyxstringInvariant(s)
-#endif //DEVEL_VERSION
+#endif /* ENABLE_ASSERTIONS */
 
 
 ///////////////////////////////////////
@@ -400,7 +394,6 @@ lyxstring::size_type const lyxstring::npos =
 static_cast<lyxstring::size_type>(-1);
 
 
-inline
 lyxstring::lyxstring()
 {
        static Srep empty_rep(0, "");
@@ -409,7 +402,6 @@ lyxstring::lyxstring()
 }
 
 
-inline
 lyxstring::lyxstring(lyxstring const & x, size_type pos, size_type n)
 {
        Assert(pos <= x.rep->sz); // STD!
@@ -422,13 +414,12 @@ lyxstring::lyxstring(lyxstring const & x, size_type pos, size_type n)
 }
 
 
-inline
 lyxstring::lyxstring(value_type const * s, size_type n)
 {
        Assert(s && n < npos); // STD!
        static Srep empty_rep(0, "");
-       if (*s && n) { // s is not empty string and n > 0
-               rep = new Srep(min(strlen(s), n), s);
+       if (n) { // n > 0
+               rep = new Srep(n, s);
        } else {
                ++empty_rep.ref;
                rep = &empty_rep;
@@ -436,7 +427,6 @@ lyxstring::lyxstring(value_type const * s, size_type n)
 }
 
 
-inline
 lyxstring::lyxstring(value_type const * s)
 {
        Assert(s); // STD!
@@ -450,7 +440,6 @@ lyxstring::lyxstring(value_type const * s)
 }
 
 
-inline
 lyxstring::lyxstring(size_type n, value_type c)
 {
        Assert(n < npos); // STD!
@@ -458,14 +447,12 @@ lyxstring::lyxstring(size_type n, value_type c)
 }
 
 
-inline
 lyxstring::lyxstring(const_iterator first, const_iterator last)
 {
        rep = new Srep(last - first, first);
 }
 
 
-inline
 lyxstring::~lyxstring()
 {
        if (--rep->ref == 0) delete rep;
@@ -475,56 +462,50 @@ lyxstring::~lyxstring()
 // Iterators
 ///////////////////////
 
-inline
 lyxstring::iterator lyxstring::begin()
 {
+       rep = rep->get_own_copy();
        return rep->s;
 }
 
 
-inline
 lyxstring::const_iterator lyxstring::begin() const
 {
        return rep->s;
 }
 
 
-inline
 lyxstring::iterator lyxstring::end()
 {
+       rep = rep->get_own_copy();
        return rep->s + rep->sz;
 }
 
 
-inline
 lyxstring::const_iterator lyxstring::end() const
 {
        return rep->s + rep->sz;
 }
 
 #if 0
-inline
 reverse_iterator lyxstring::rbegin()
 {
        return reverse_iterator( end() );
 }
 
 
-inline
 const_reverse_iterator lyxstring::rbegin() const
 {
        return const_reverse_iterator( end() );
 }
 
 
-inline
 reverse_iterator lyxstring::rend()
 {
        return reverse_iterator( begin() );
 }
 
 
-inline
 const_reverse_iterator lyxstring::rend() const
 {
        return const_reverse_iterator( begin() );
@@ -536,14 +517,12 @@ const_reverse_iterator lyxstring::rend() const
 // Size and Capacity
 ///////////////////////
 
-inline
 lyxstring::size_type lyxstring::size() const
 { 
        return rep->sz;
 }
 
 
-inline
 void lyxstring::resize(size_type n, value_type c)
 {
        Assert(n <= npos); // STD!
@@ -555,14 +534,12 @@ void lyxstring::resize(size_type n, value_type c)
 }
 
 
-inline
 lyxstring::size_type lyxstring::capacity() const
 {
        return rep->res;
 }
 
 
-inline
 void lyxstring::reserve(size_type res_arg)
 {
        TestlyxstringInvariant(this);
@@ -576,8 +553,7 @@ void lyxstring::reserve(size_type res_arg)
 // Assignment
 ////////////////
 
-inline
-lyxstring & lyxstring::operator= (lyxstring const & x)
+lyxstring & lyxstring::operator=(lyxstring const & x)
 {
        TestlyxstringInvariant(this);
 
@@ -585,8 +561,7 @@ lyxstring & lyxstring::operator= (lyxstring const & x)
 }
 
 
-inline
-lyxstring & lyxstring::operator= (value_type const * s)
+lyxstring & lyxstring::operator=(value_type const * s)
 {
        Assert(s); // OURS!
        TestlyxstringInvariant(this);
@@ -596,7 +571,6 @@ lyxstring & lyxstring::operator= (value_type const * s)
 }
 
 
-inline
 lyxstring & lyxstring::operator=(value_type c)
 {
        TestlyxstringInvariant(this);
@@ -613,7 +587,6 @@ lyxstring & lyxstring::operator=(value_type c)
 }
 
 
-inline
 lyxstring & lyxstring::assign(lyxstring const & x)
 {
        TestlyxstringInvariant(this);
@@ -625,7 +598,6 @@ lyxstring & lyxstring::assign(lyxstring const & x)
 }
        
 
-inline
 lyxstring & lyxstring::assign(lyxstring const & x, size_type pos, size_type n)
 {
        Assert(pos <= x.rep->sz); // STD!
@@ -635,24 +607,21 @@ lyxstring & lyxstring::assign(lyxstring const & x, size_type pos, size_type n)
 }
        
 
-inline
 lyxstring & lyxstring::assign(value_type const * s, size_type n)
 {
-       Assert(s); // OURS!
+       Assert(s && n < npos); // STD!
        TestlyxstringInvariant(this);
 
-       n = min(strlen(s), n);
        if (rep->ref == 1) // recycle rep
                rep->assign(n, s);
        else {
-               rep->ref--;
+               --rep->ref;
                rep = new Srep(n, s);
        }
        return *this;
 }
        
 
-inline
 lyxstring & lyxstring::assign(value_type const * s)
 {
        Assert(s); // OURS!
@@ -662,7 +631,6 @@ lyxstring & lyxstring::assign(value_type const * s)
 }
 
 
-inline
 lyxstring & lyxstring::assign(size_type n, value_type ch)
 {
        TestlyxstringInvariant(this);
@@ -673,7 +641,6 @@ lyxstring & lyxstring::assign(size_type n, value_type ch)
 }
 
 
-inline
 lyxstring & lyxstring::assign(const_iterator first, const_iterator last)
 {
        TestlyxstringInvariant(this);
@@ -688,7 +655,6 @@ lyxstring & lyxstring::assign(const_iterator first, const_iterator last)
 // Element Access
 ////////////////////
 
-inline
 lyxstring::const_reference lyxstring::operator[](size_type pos) const
 {
        Assert(pos <= rep->sz); // OURS!
@@ -697,7 +663,6 @@ lyxstring::const_reference lyxstring::operator[](size_type pos) const
 }
 
 
-inline
 lyxstring::reference lyxstring::operator[](size_type pos)
 {
        Assert(pos < rep->sz); // OURS!
@@ -708,7 +673,6 @@ lyxstring::reference lyxstring::operator[](size_type pos)
 }
 
 
-inline
 lyxstring::const_reference lyxstring::at(size_type n) const
 {
        Assert(n < rep->sz); // STD!
@@ -716,7 +680,6 @@ lyxstring::const_reference lyxstring::at(size_type n) const
 }
 
 
-inline
 lyxstring::reference lyxstring::at(size_type n)
 {
        Assert(n < rep->sz); // STD!
@@ -731,7 +694,6 @@ lyxstring::reference lyxstring::at(size_type n)
 // Insert
 /////////////
 
-inline
 lyxstring & lyxstring::operator+=(lyxstring const & x)
 {
        TestlyxstringInvariant(this);
@@ -740,7 +702,6 @@ lyxstring & lyxstring::operator+=(lyxstring const & x)
 }
 
 
-inline
 lyxstring & lyxstring::operator+=(value_type const * x)
 {
        Assert(x); // OURS!
@@ -750,7 +711,6 @@ lyxstring & lyxstring::operator+=(value_type const * x)
 }
 
 
-inline
 lyxstring & lyxstring::operator+=(value_type c)
 {
        TestlyxstringInvariant(this);
@@ -760,7 +720,6 @@ lyxstring & lyxstring::operator+=(value_type c)
 }
 
 
-inline
 void lyxstring::push_back(value_type c)
 {
        TestlyxstringInvariant(this);
@@ -770,7 +729,6 @@ void lyxstring::push_back(value_type c)
 }
 
 
-inline
 lyxstring & lyxstring::append(lyxstring const & x)
 {
        TestlyxstringInvariant(this);
@@ -782,7 +740,6 @@ lyxstring & lyxstring::append(lyxstring const & x)
 }
 
 
-inline
 lyxstring & lyxstring::append(lyxstring const & x, size_type pos, size_type n)
 {
        Assert(pos <= x.rep->sz); // STD!
@@ -792,7 +749,6 @@ lyxstring & lyxstring::append(lyxstring const & x, size_type pos, size_type n)
 }
 
 
-inline
 lyxstring & lyxstring::append(value_type const * p, size_type n)
 {
        Assert(p); // OURS!
@@ -800,25 +756,18 @@ lyxstring & lyxstring::append(value_type const * p, size_type n)
 
        if (!*p || !n) return *this;
        rep = rep->get_own_copy();
-       rep->append(min(n, strlen(p)), p);
+       rep->append(n, p);
        return *this;
 }
 
 
-inline
 lyxstring & lyxstring::append(value_type const * p)
 {
        Assert(p); // OURS!
-       TestlyxstringInvariant(this);
-
-       if (!*p) return *this;
-       rep = rep->get_own_copy();
-       rep->append(strlen(p), p);
-       return *this;
+       return append(p, strlen(p));
 }
 
 
-inline
 lyxstring & lyxstring::append(size_type n, value_type c)
 {
        TestlyxstringInvariant(this);
@@ -832,7 +781,6 @@ lyxstring & lyxstring::append(size_type n, value_type c)
 }
 
 
-inline
 lyxstring & lyxstring::append(iterator first, iterator last)
 {
        TestlyxstringInvariant(this);
@@ -842,9 +790,8 @@ lyxstring & lyxstring::append(iterator first, iterator last)
        return *this;
 }
 
-// insert value_typeacters before (*this)[pos]
+// insert characters before (*this)[pos]
 
-inline
 lyxstring & lyxstring::insert(size_type pos, lyxstring const & x)
 {
        TestlyxstringInvariant(this);
@@ -853,9 +800,8 @@ lyxstring & lyxstring::insert(size_type pos, lyxstring const & x)
 }
 
 
-inline
 lyxstring & lyxstring::insert(size_type pos, lyxstring const & x,
-                         size_type pos2, size_type n)
+                             size_type pos2, size_type n)
 {
        Assert(pos <= rep->sz && pos2 <= x.rep->sz); // STD!
        TestlyxstringInvariant(this);
@@ -866,7 +812,6 @@ lyxstring & lyxstring::insert(size_type pos, lyxstring const & x,
 }
 
 
-inline
 lyxstring & lyxstring::insert(size_type pos, value_type const * p, size_type n)
 {
        Assert(p); // OURS!
@@ -875,28 +820,19 @@ lyxstring & lyxstring::insert(size_type pos, value_type const * p, size_type n)
        if (*p && n) {
                // insert nothing and you change nothing
                rep = rep->get_own_copy();
-               rep->insert(pos, p, min(n, strlen(p)));
+               rep->insert(pos, p, n);
        }
        return *this;
 }
 
 
-inline
 lyxstring & lyxstring::insert(size_type pos, value_type const * p)
 {
        Assert(p); // OURS!
-       TestlyxstringInvariant(this);
-
-       if (*p) {
-               // insert nothing and you change nothing
-               rep = rep->get_own_copy();
-               rep->insert(pos, p, strlen(p));
-       }
-       return *this;
+       return insert(pos, p, strlen(p));
 }
 
 
-inline
 lyxstring & lyxstring::insert(size_type pos, size_type n, value_type c)
 {
        TestlyxstringInvariant(this);
@@ -910,7 +846,6 @@ lyxstring & lyxstring::insert(size_type pos, size_type n, value_type c)
 }
 
 
-inline
 lyxstring::iterator lyxstring::insert(iterator p, value_type c)
 {
        TestlyxstringInvariant(this);
@@ -922,7 +857,6 @@ lyxstring::iterator lyxstring::insert(iterator p, value_type c)
 }
 
 
-inline
 void lyxstring::insert(iterator p, size_type n , value_type c)
 {
        TestlyxstringInvariant(this);
@@ -931,7 +865,6 @@ void lyxstring::insert(iterator p, size_type n , value_type c)
 }
 
 
-inline
 void lyxstring::insert(iterator p, iterator first, iterator last)
 {
        TestlyxstringInvariant(this);
@@ -949,19 +882,20 @@ void lyxstring::insert(iterator p, iterator first, iterator last)
          // some of the parameters wrong, also some of the funcs can surely
          // be written more effectively.
 
-inline
 lyxstring::size_type lyxstring::find(lyxstring const & a, size_type i) const
 {
        if (!rep->sz || i >= rep->sz) return npos;
        
        TestlyxstringInvariant(this);
 
-       for (size_type t = i; rep->sz - t >= a.length(); ++t) {
+       size_type n = a.length();
+       if (!n) return npos;
+       for (size_type t = i; rep->sz - t >= n; ++t) {
                // search until (*this)[i] == a[0]
                if (rep->s[t] == a[0]) {
                        // check if the rest of the value_types match
                        bool equal = true;
-                       for (size_type j = 0; j < a.length(); ++j) {
+                       for (size_type j = 1; j < n; ++j) {
                                if (rep->s[t + j] != a[j]) {
                                        equal = false;
                                        break;
@@ -974,9 +908,8 @@ lyxstring::size_type lyxstring::find(lyxstring const & a, size_type i) const
 }
 
 
-inline
 lyxstring::size_type lyxstring::find(value_type const * ptr, size_type i,
-                                size_type n) const
+                                    size_type n) const
 {
        Assert(ptr); // OURS!
        if (!rep->sz || !*ptr || i >= rep->sz) return npos;
@@ -988,12 +921,13 @@ lyxstring::size_type lyxstring::find(value_type const * ptr, size_type i,
        // for ptr in? For now I will assume that "n" tells the length
        // of ptr. (Lgb)
        n = min(n, strlen(ptr));
+       if (!n) return npos;
        for (size_type t = i; rep->sz - t >= n; ++t) {
                // search until (*this)[i] == a[0]
                if (rep->s[t] == ptr[0]) {
                        // check if the rest of the value_types match
                        bool equal = true;
-                       for (size_type j = 0; j < n; ++j) {
+                       for (size_type j = 1; j < n; ++j) {
                                if (rep->s[t + j] != ptr[j]) {
                                        equal = false;
                                        break;
@@ -1006,7 +940,6 @@ lyxstring::size_type lyxstring::find(value_type const * ptr, size_type i,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find(value_type const * s, size_type i) const
 {
        Assert(s); // OURS!
@@ -1019,7 +952,6 @@ lyxstring::size_type lyxstring::find(value_type const * s, size_type i) const
 }
 
 
-inline
 lyxstring::size_type lyxstring::find(value_type c, size_type i) const
 {
        if (!rep->sz || i >= rep->sz) return npos;
@@ -1033,90 +965,88 @@ lyxstring::size_type lyxstring::find(value_type c, size_type i) const
 }
 
 
-inline
 lyxstring::size_type lyxstring::rfind(lyxstring const & a, size_type i) const
 {
        TestlyxstringInvariant(this);
 
-       size_type ii = min(rep->sz - 1, i);
+       size_type n = a.length();
+       if (!n || rep->sz < n)
+               return npos;
+
+       size_type t = min(rep->sz - n, i);
        do {
-               if (a[a.length() - 1] == rep->s[ii]) {
-                       int t = rep->sz - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (a[t] != rep->s[l]) break;
+               if (rep->s[t] == a[0]) {
+                       // check if the rest of the value_types match
+                       bool equal = true;
+                       for (size_type j = 1; j < n; ++j) {
+                               if (rep->s[t + j] != a[j]) {
+                                       equal = false;
+                                       break;
+                               }
                        }
-                       if (a[t] == rep->s[l]) return l;
+                       if (equal) return t;
                }
-       } while(ii-- > 0);
+       } while(t-- > 0);
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i,
-                                 size_type n) const
+                                     size_type n) const
 {
        Assert(ptr); // OURS!
        TestlyxstringInvariant(this);
-       if (!*ptr) return npos;
 
-       size_type ii = min(rep->sz - 1, i);
+       n = min(n, strlen(ptr));
+       if (!n || rep->sz < n)
+               return npos;
+
+       size_type t = min(rep->sz - n, i);
        do {
-               if (ptr[n - 1] == rep->s[ii]) {
-                       int t = n - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (ptr[t] != rep->s[l]) break;
+               if (rep->s[t] == ptr[0]) {
+                       // check if the rest of the value_types match
+                       bool equal = true;
+                       for (size_type j = 1; j < n; ++j) {
+                               if (rep->s[t + j] != ptr[j]) {
+                                       equal = false;
+                                       break;
+                               }
                        }
-                       if (ptr[t] == rep->s[l]) return l;
+                       if (equal) return t;
                }
-       } while (ii-- > 0);
+       } while (t-- > 0);
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::rfind(value_type const * ptr,
                                      size_type i) const
 {
        Assert(ptr); // OURS!
-       TestlyxstringInvariant(this);
-       if (!*ptr) return npos;
 
-       size_type ii = min(rep->sz - 1, i);
-       do {
-               if (ptr[strlen(ptr) - 1] == rep->s[ii]) {
-                       int t = strlen(ptr) - 2;
-                       size_type l = ii - 1;
-                       for (; t >= 0; --t, --l) {
-                               if (ptr[t] != rep->s[l]) break;
-                       }
-                       if (ptr[t] == rep->s[l]) return l;
-               }
-       } while (ii-- > 0);
-       return npos;
+       if (!ptr || !*ptr) return npos;
+       return rfind(ptr, i, strlen(ptr));
 }
 
 
-inline
 lyxstring::size_type lyxstring::rfind(value_type c, size_type i) const
 {
        TestlyxstringInvariant(this);
 
-       size_type ii = min(rep->sz - 1, i);
-        for (size_type t = ii; t != 0; --t) {
-               if (rep->s[t] == c) return t;
-       }
-        return npos;
+       size_type const sz = rep->sz;
+       if (sz < 1) return npos;
+       size_type ii = min(sz - 1, i);
+       do {
+               if (rep->s[ii] == c) return ii;
+       } while (ii-- > 0);
+       return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_of(lyxstring const & a,
                                              size_type i) const
 {
-       Assert(i < rep->sz); // OURS!
+       Assert(i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        for (size_type t = i; t < rep->sz; ++t) {
@@ -1126,27 +1056,25 @@ lyxstring::size_type lyxstring::find_first_of(lyxstring const & a,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_of(value_type const * ptr,
                                              size_type i,
                                              size_type n) const
 {
-       Assert(ptr && i < rep->sz); // OURS!
+       Assert(ptr && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
        if (!n) return npos;
 
        for (size_type t = i; t < rep->sz; ++t) {
-               if(memchr(ptr, rep->s[t], n) != 0) return t;
+               if (memchr(ptr, rep->s[t], n) != 0) return t;
        }
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_of(value_type const * ptr,
                                              size_type i) const
 {
-       Assert(ptr && i < rep->sz); // OURS!
+       Assert(ptr && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        for (size_type t = i; t < rep->sz; ++t) {
@@ -1156,10 +1084,9 @@ lyxstring::size_type lyxstring::find_first_of(value_type const * ptr,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_of(value_type c, size_type i) const
 {
-       Assert(i < rep->sz); // OURS!
+       Assert(i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        for (size_type t = i; t < rep->sz; ++t) {
@@ -1169,7 +1096,6 @@ lyxstring::size_type lyxstring::find_first_of(value_type c, size_type i) const
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_of(lyxstring const & a,
                                             size_type i) const
 {
@@ -1183,7 +1109,6 @@ lyxstring::size_type lyxstring::find_last_of(lyxstring const & a,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_of(value_type const * ptr,
                                             size_type i,
                                             size_type n) const
@@ -1194,13 +1119,12 @@ lyxstring::size_type lyxstring::find_last_of(value_type const * ptr,
 
        size_type ii = min(rep->sz - 1, i);
        for (int t = ii; t >= 0; --t) {
-               if(memchr(ptr, rep->s[t], n) != 0) return t;
+               if (memchr(ptr, rep->s[t], n) != 0) return t;
        }
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_of(value_type const * ptr,
                                             size_type i) const
 {
@@ -1215,7 +1139,6 @@ lyxstring::size_type lyxstring::find_last_of(value_type const * ptr,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_of(value_type c, size_type i) const
 {
        TestlyxstringInvariant(this);
@@ -1229,14 +1152,13 @@ lyxstring::size_type lyxstring::find_last_of(value_type c, size_type i) const
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_not_of(lyxstring const & a,
                                                  size_type i) const
 {
        TestlyxstringInvariant(this);
 
        if (!rep->sz) return npos;
-       Assert(i < rep->sz);
+       Assert(i <= rep->sz);
        for (size_type t = i; t < rep->sz; ++t) {
                if (a.find(rep->s[t]) == npos) return t;
        }
@@ -1244,27 +1166,25 @@ lyxstring::size_type lyxstring::find_first_not_of(lyxstring const & a,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_not_of(value_type const * ptr,
                                                  size_type i,
                                                  size_type n) const
 {
-       Assert(ptr && i < rep->sz); // OURS!
+       Assert(ptr && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        if (!n) return (i < rep->sz) ? i : npos;
        for (size_type t = i; t < rep->sz; ++t) {
-               if(memchr(ptr, rep->s[t], n) == 0) return t;
+               if (memchr(ptr, rep->s[t], n) == 0) return t;
        }
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_not_of(value_type const * ptr,
                                                  size_type i) const
 {
-       Assert(ptr && i < rep->sz); // OURS!
+       Assert(ptr && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        for (size_type t = i; t < rep->sz; ++t) {
@@ -1274,12 +1194,11 @@ lyxstring::size_type lyxstring::find_first_not_of(value_type const * ptr,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_first_not_of(value_type c,
                                                  size_type i) const
 {
        if (!rep->sz) return npos;
-       Assert(i < rep->sz); // OURS!
+       Assert(i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        for (size_type t = i; t < rep->sz; ++t) {
@@ -1289,7 +1208,6 @@ lyxstring::size_type lyxstring::find_first_not_of(value_type c,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_not_of(lyxstring const & a,
                                                 size_type i) const
 {
@@ -1303,7 +1221,6 @@ lyxstring::size_type lyxstring::find_last_not_of(lyxstring const & a,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_not_of(value_type const * ptr,
                                                 size_type i,
                                                 size_type n) const
@@ -1315,13 +1232,12 @@ lyxstring::size_type lyxstring::find_last_not_of(value_type const * ptr,
        size_type ii = min(rep->sz - 1, i);
 
        for (int t = ii; t >= 0; --t) {
-               if(memchr(ptr, rep->s[t], n) == 0) return t;
+               if (memchr(ptr, rep->s[t], n) == 0) return t;
        }
        return npos;
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_not_of(value_type const * ptr,
                                                 size_type i) const
 {
@@ -1336,7 +1252,6 @@ lyxstring::size_type lyxstring::find_last_not_of(value_type const * ptr,
 }
 
 
-inline
 lyxstring::size_type lyxstring::find_last_not_of(value_type c,
                                                 size_type i) const
 {
@@ -1354,7 +1269,6 @@ lyxstring::size_type lyxstring::find_last_not_of(value_type c,
 // Replace
 /////////////////
 
-inline
 lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x)
 {
        Assert(i <= rep->sz); // OURS!
@@ -1364,7 +1278,6 @@ lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x)
 }
 
 
-inline
 lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x,
                               size_type i2, size_type n2)
 {
@@ -1377,11 +1290,10 @@ lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x,
 }
 
 
-inline
 lyxstring & lyxstring::replace(size_type i, size_type n,
                               value_type const * p, size_type n2)
 {
-       Assert(p && i < rep->sz); // OURS!
+       Assert(p && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        rep = rep->get_own_copy();
@@ -1390,21 +1302,19 @@ lyxstring & lyxstring::replace(size_type i, size_type n,
 }
 
 
-inline
 lyxstring & lyxstring::replace(size_type i, size_type n, value_type const * p)
 {
-       Assert(p && i < rep->sz); // OURS!
+       Assert(p && i <= rep->sz); // OURS!
        TestlyxstringInvariant(this);
 
        return replace(i, min(n, rep->sz), p, (!p) ? 0 : strlen(p));
 }
 
 
-inline
 lyxstring & lyxstring::replace(size_type i, size_type n,
                               size_type n2, value_type c)
 {
-       Assert(i < rep->sz);  // OURS!
+       Assert(i <= rep->sz);  // OURS!
        TestlyxstringInvariant(this);
 
        rep = rep->get_own_copy();
@@ -1416,7 +1326,6 @@ lyxstring & lyxstring::replace(size_type i, size_type n,
 }
 
 
-inline
 lyxstring & lyxstring::replace(iterator i, iterator i2, const lyxstring & str)
 {
        TestlyxstringInvariant(this);
@@ -1425,7 +1334,6 @@ lyxstring & lyxstring::replace(iterator i, iterator i2, const lyxstring & str)
 }
 
 
-inline
 lyxstring & lyxstring::replace(iterator i, iterator i2,
                               value_type const * p, size_type n)
 {
@@ -1436,7 +1344,6 @@ lyxstring & lyxstring::replace(iterator i, iterator i2,
 }
 
 
-inline
 lyxstring & lyxstring::replace(iterator i, iterator i2, value_type const * p)
 {
        Assert(p); // OURS!
@@ -1446,7 +1353,6 @@ lyxstring & lyxstring::replace(iterator i, iterator i2, value_type const * p)
 }
 
 
-inline
 lyxstring & lyxstring::replace(iterator i, iterator i2,
                               size_type n , value_type c)
 {
@@ -1456,7 +1362,6 @@ lyxstring & lyxstring::replace(iterator i, iterator i2,
 }
        
 
-inline
 lyxstring & lyxstring::replace(iterator i, iterator i2,
                               iterator j, iterator j2)
 {
@@ -1466,7 +1371,6 @@ lyxstring & lyxstring::replace(iterator i, iterator i2,
 }
 
 
-inline
 void lyxstring::swap(lyxstring & str)
 {
        if (rep == str.rep) return;
@@ -1476,7 +1380,6 @@ void lyxstring::swap(lyxstring & str)
 }
 
 
-inline
 lyxstring & lyxstring::erase(size_type i, size_type n)
 {
        Assert(i <= rep->sz); // STD!
@@ -1494,7 +1397,6 @@ lyxstring & lyxstring::erase(size_type i, size_type n)
 }
 
 
-inline
 lyxstring::iterator lyxstring::erase(iterator i)
 {
        TestlyxstringInvariant(this);
@@ -1506,7 +1408,6 @@ lyxstring::iterator lyxstring::erase(iterator i)
 }
 
 
-inline
 lyxstring::iterator lyxstring::erase(iterator first, iterator last)
 {
        TestlyxstringInvariant(this);
@@ -1520,7 +1421,6 @@ lyxstring::iterator lyxstring::erase(iterator first, iterator last)
 // Conversion to C-style Strings
 /////////////////////////////////////
 
-inline
 lyxstring::value_type const * lyxstring::c_str() const
 {
        rep->s[length()] = '\0';
@@ -1528,14 +1428,12 @@ lyxstring::value_type const * lyxstring::c_str() const
 }
 
 
-inline
 lyxstring::value_type const * lyxstring::data() const
 {
        return rep->s;
 }
 
 
-inline
 lyxstring::size_type lyxstring::copy(value_type * buf, size_type len,
                                     size_type pos) const
 {
@@ -1555,7 +1453,6 @@ lyxstring::size_type lyxstring::copy(value_type * buf, size_type len,
 
 // Compare funcs should be verified.
 
-inline
 int lyxstring::internal_compare(size_type pos, size_type n,
                                value_type const * s,
                                size_type slen, size_type n2) const
@@ -1579,7 +1476,6 @@ int lyxstring::internal_compare(size_type pos, size_type n,
 }
 
 
-inline
 int lyxstring::compare(lyxstring const & str) const
 {
        TestlyxstringInvariant(this);
@@ -1588,7 +1484,6 @@ int lyxstring::compare(lyxstring const & str) const
 }
 
 
-inline
 int lyxstring::compare(value_type const * s) const
 {
        Assert(s); //OURS!
@@ -1598,7 +1493,6 @@ int lyxstring::compare(value_type const * s) const
 }
 
 
-inline
 int lyxstring::compare(size_type pos, size_type n,
                       lyxstring const & str) const
 {
@@ -1608,7 +1502,6 @@ int lyxstring::compare(size_type pos, size_type n,
 }
 
 
-inline
 int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
                       size_type pos2, size_type n2) const
 {
@@ -1621,7 +1514,6 @@ int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
 }
 
 
-inline
 int lyxstring::compare(size_type pos, size_type n, value_type const * s,
                       size_type n2) const
 {
@@ -1636,7 +1528,6 @@ int lyxstring::compare(size_type pos, size_type n, value_type const * s,
 /////////////////
 
 // i = index, n = length
-inline
 lyxstring lyxstring::substr(size_type i, size_type n) const
 {
        Assert(i <= rep->sz); // STD!
@@ -1868,3 +1759,12 @@ istream & getline(istream & is, lyxstring & s,
        }
        return is;
 }
+
+#ifdef TEST_MAIN
+int main() {
+       lyxstring a = "abcac";
+       cout << a.rfind("ab") << endl;
+       cout << a.rfind("c") << endl;
+       cout << a.rfind("d") << endl;
+}
+#endif