]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxstring.C
Fix small typos
[lyx.git] / src / support / lyxstring.C
index 3f8deedfb55a18595f9b722aced6ae17ab750b37..4e7438d69f5128183056ac42d59ea9d2311c9291 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-1999 The LyX Team.
+ *          Copyright 1995-2000 The LyX Team.
  *
  * ====================================================== */
 
@@ -414,8 +414,8 @@ 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;
@@ -460,6 +460,7 @@ lyxstring::~lyxstring()
 
 lyxstring::iterator lyxstring::begin()
 {
+       rep = rep->get_own_copy();
        return rep->s;
 }
 
@@ -472,6 +473,7 @@ lyxstring::const_iterator lyxstring::begin() const
 
 lyxstring::iterator lyxstring::end()
 {
+       rep = rep->get_own_copy();
        return rep->s + rep->sz;
 }
 
@@ -547,7 +549,7 @@ void lyxstring::reserve(size_type res_arg)
 // Assignment
 ////////////////
 
-lyxstring & lyxstring::operator= (lyxstring const & x)
+lyxstring & lyxstring::operator=(lyxstring const & x)
 {
        TestlyxstringInvariant(this);
 
@@ -555,7 +557,7 @@ lyxstring & lyxstring::operator= (lyxstring const & x)
 }
 
 
-lyxstring & lyxstring::operator= (value_type const * s)
+lyxstring & lyxstring::operator=(value_type const * s)
 {
        Assert(s); // OURS!
        TestlyxstringInvariant(this);
@@ -603,14 +605,13 @@ lyxstring & lyxstring::assign(lyxstring const & x, size_type pos, size_type n)
 
 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;
@@ -751,7 +752,7 @@ 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;
 }
 
@@ -759,12 +760,7 @@ lyxstring & lyxstring::append(value_type const * p, size_type n)
 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));
 }
 
 
@@ -790,7 +786,7 @@ lyxstring & lyxstring::append(iterator first, iterator last)
        return *this;
 }
 
-// insert value_typeacters before (*this)[pos]
+// insert characters before (*this)[pos]
 
 lyxstring & lyxstring::insert(size_type pos, lyxstring const & x)
 {
@@ -820,7 +816,7 @@ 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;
 }
@@ -829,14 +825,7 @@ lyxstring & lyxstring::insert(size_type pos, value_type const * p, size_type n)
 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));
 }
 
 
@@ -1315,7 +1304,7 @@ lyxstring & lyxstring::replace(size_type i, size_type n, value_type const * p)
 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();