#include "LAssert.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
{
Assert(s && n < npos); // STD!
static Srep empty_rep(0, "");
- if (*s && n) { // s is not empty string and n > 0
+ if (n) { // n > 0
rep = new Srep(n, s);
} else {
++empty_rep.ref;
// Assignment
////////////////
-lyxstring & lyxstring::operator= (lyxstring const & x)
+lyxstring & lyxstring::operator=(lyxstring const & x)
{
TestlyxstringInvariant(this);
}
-lyxstring & lyxstring::operator= (value_type const * s)
+lyxstring & lyxstring::operator=(value_type const * s)
{
Assert(s); // OURS!
TestlyxstringInvariant(this);
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;
if (!*p || !n) return *this;
rep = rep->get_own_copy();
- rep->append(min(n, strlen(p)), p);
+ rep->append(n, p);
return *this;
}
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));
}
return *this;
}
-// insert value_typeacters before (*this)[pos]
+// insert characters before (*this)[pos]
lyxstring & lyxstring::insert(size_type pos, lyxstring const & x)
{
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;
}
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));
}
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;
}
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;
}
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;
}
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;
}