* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-1998 The LyX Team.
+ * Copyright 1995-1999 The LyX Team.
*
- * ======================================================*/
+ * ====================================================== */
#include <config.h>
FileInfo::FileInfo(int fildes)
{
init();
- status = fstat(fildes, buf);
+ status = fstat(fildes, &buf);
if (status) err = errno;
}
-FileInfo::~FileInfo()
-{
- delete[] buf;
-}
-
-
void FileInfo::init()
{
status = 0;
err = NoErr;
- buf = (struct stat*) new char[sizeof(struct stat)];
}
void FileInfo::dostat(bool link)
{
if (link) {
- status = lstat(fname.c_str(), buf);
+ status = lstat(fname.c_str(), &buf);
} else {
- status = stat(fname.c_str(), buf);
+ status = stat(fname.c_str(), &buf);
}
if (status) err = errno;
}
-FileInfo& FileInfo::newFile(string const &path, bool link)
+FileInfo & FileInfo::newFile(string const & path, bool link)
{
fname = path;
}
-FileInfo& FileInfo::newFile(int fildes)
+FileInfo & FileInfo::newFile(int fildes)
{
status = 0;
err = NoErr;
- status = fstat(fildes, buf);
+ status = fstat(fildes, &buf);
if (status) err = errno;
return *this;
}
char const * FileInfo::typeIndicator() const
{
- if (S_ISDIR(buf->st_mode)) return ("/");
+ if (S_ISDIR(buf.st_mode)) return ("/");
#ifdef S_ISLNK
- if (S_ISLNK(buf->st_mode)) return ("@");
+ if (S_ISLNK(buf.st_mode)) return ("@");
#endif
#ifdef S_ISFIFO
- if (S_ISFIFO(buf->st_mode)) return ("|");
+ if (S_ISFIFO(buf.st_mode)) return ("|");
#endif
#ifdef S_ISSOCK
- if (S_ISSOCK(buf->st_mode)) return ("=");
+ if (S_ISSOCK(buf.st_mode)) return ("=");
#endif
- if (S_ISREG(buf->st_mode) && (buf->st_mode & (S_IEXEC | S_IXGRP | S_IXOTH)))
+ if (S_ISREG(buf.st_mode) && (buf.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH)))
return ("*");
return "";
}
mode_t FileInfo::getMode() const
{
- return buf->st_mode;
+ return buf.st_mode;
}
long FileInfo::getBlockSize() const
{
#ifndef __EMX__
- return buf->st_blksize; /* Preferred I/O block size */
+ return buf.st_blksize; /* Preferred I/O block size */
#else
#warning May be fixed in 0.13 (SMiyata)
return 512; /* Assume HPFS */
void FileInfo::modeString(char * szString) const
{
szString[0] = typeLetter();
- flagRWX((buf->st_mode & 0700) << 0, &szString[1]);
- flagRWX((buf->st_mode & 0070) << 3, &szString[4]);
- flagRWX((buf->st_mode & 0007) << 6, &szString[7]);
+ flagRWX((buf.st_mode & 0700) << 0, &szString[1]);
+ flagRWX((buf.st_mode & 0070) << 3, &szString[4]);
+ flagRWX((buf.st_mode & 0007) << 6, &szString[7]);
setSticky(szString);
szString[10] = 0;
}
char FileInfo::typeLetter() const
{
#ifdef S_ISBLK
- if (S_ISBLK(buf->st_mode)) return 'b';
+ if (S_ISBLK(buf.st_mode)) return 'b';
#endif
- if (S_ISCHR(buf->st_mode)) return 'c';
- if (S_ISDIR(buf->st_mode)) return 'd';
- if (S_ISREG(buf->st_mode)) return '-';
+ if (S_ISCHR(buf.st_mode)) return 'c';
+ if (S_ISDIR(buf.st_mode)) return 'd';
+ if (S_ISREG(buf.st_mode)) return '-';
#ifdef S_ISFIFO
- if (S_ISFIFO(buf->st_mode)) return 'p';
+ if (S_ISFIFO(buf.st_mode)) return 'p';
#endif
#ifdef S_ISLNK
- if (S_ISLNK(buf->st_mode)) return 'l';
+ if (S_ISLNK(buf.st_mode)) return 'l';
#endif
#ifdef S_ISSOCK
- if (S_ISSOCK(buf->st_mode)) return 's';
+ if (S_ISSOCK(buf.st_mode)) return 's';
#endif
#ifdef S_ISMPC
- if (S_ISMPC(buf->st_mode)) return 'm';
+ if (S_ISMPC(buf.st_mode)) return 'm';
#endif
#ifdef S_ISNWK
- if (S_ISNWK(buf->st_mode)) return 'n';
+ if (S_ISNWK(buf.st_mode)) return 'n';
#endif
return '?';
}
void FileInfo::setSticky(char * szString) const
{
#ifdef S_ISUID
- if (buf->st_mode & S_ISUID) {
+ if (buf.st_mode & S_ISUID) {
if (szString[3] != 'x') szString[3] = 'S';
else szString[3] = 's';
}
#endif
#ifdef S_ISGID
- if (buf->st_mode & S_ISGID) {
+ if (buf.st_mode & S_ISGID) {
if (szString[6] != 'x') szString[6] = 'S';
else szString[6] = 's';
}
#endif
#ifdef S_ISVTX
- if (buf->st_mode & S_ISVTX) {
+ if (buf.st_mode & S_ISVTX) {
if (szString[9] != 'x') szString[9] = 'T';
else szString[9] = 't';
}
time_t FileInfo::getModificationTime() const
{
- return buf->st_mtime;
+ return buf.st_mtime;
}
time_t FileInfo::getAccessTime() const
{
- return buf->st_atime;
+ return buf.st_atime;
}
time_t FileInfo::getStatusChangeTime() const
{
- return buf->st_ctime;
+ return buf.st_ctime;
}
nlink_t FileInfo::getNumberOfLinks() const
{
- return buf->st_nlink;
+ return buf.st_nlink;
}
-uid_t FileInfo::getUid() const
+uid_t FileInfo::getUid() const
{
- return buf->st_uid;
+ return buf.st_uid;
}
-gid_t FileInfo::getGid() const
+gid_t FileInfo::getGid() const
{
- return buf->st_gid;
+ return buf.st_gid;
}
off_t FileInfo::getSize() const
{
- return buf->st_size;
+ return buf.st_size;
}
bool FileInfo::isLink() const
{
- return S_ISLNK(buf->st_mode);
+ return S_ISLNK(buf.st_mode);
}
bool FileInfo::isRegular() const
{
- return S_ISREG(buf->st_mode);
+ return S_ISREG(buf.st_mode);
}
bool FileInfo::isDir() const
{
- return S_ISDIR(buf->st_mode);
+ return S_ISDIR(buf.st_mode);
}
bool FileInfo::isChar() const
{
- return S_ISCHR(buf->st_mode);
+ return S_ISCHR(buf.st_mode);
}
bool FileInfo::isBlock() const
{
- return S_ISBLK(buf->st_mode);
+ return S_ISBLK(buf.st_mode);
}
bool FileInfo::isFifo() const
{
- return S_ISFIFO(buf->st_mode);
+ return S_ISFIFO(buf.st_mode);
}
bool FileInfo::isSocket() const
{
#ifdef S_ISSOCK
- return S_ISSOCK(buf->st_mode);
+ return S_ISSOCK(buf.st_mode);
#else
return false;
#endif
public:
///
FileInfo();
-
+
/** Get information about file.
- If link is true, the information is about the link itself, not
- the file that is obtained by tracing the links. */
+ If link is true, the information is about the link itself, not
+ the file that is obtained by tracing the links. */
FileInfo(string const & path, bool link = false);
/// File descriptor
FileInfo(int fildes);
- ///
- ~FileInfo();
-
/// Query a new file
- FileInfo& newFile(string const & path, bool link = false);
-
+ FileInfo & newFile(string const & path, bool link = false);
+
/// Query a new file descriptor
- FileInfo& newFile(int fildes);
+ FileInfo & newFile(int fildes);
/// Returns a character describing file type (ls -F)
char const * typeIndicator() const;
-
+
/// File protection mode
mode_t getMode() const;
/// updates mode string to match suid/sgid/sticky bits
void setSticky(char * szString) const;
-
+
///
time_t getModificationTime() const;
-
+
///
time_t getAccessTime() const;
-
+
///
time_t getStatusChangeTime() const;
-
+
/// Total file size in bytes
off_t getSize() const;
-
+
/// Number of hard links
nlink_t getNumberOfLinks() const;
-
+
/// User ID of owner
uid_t getUid() const;
-
+
/// Group ID of owner
gid_t getGid() const;
-
+
/// Is the file information correct? Did the query succeed?
bool isOK() const;
-
+
/// Permission flags
enum perm_test {
rperm = R_OK, // test for read permission
///
void dostat(bool);
///
- struct stat * buf;
+ struct stat buf;
///
int status;
///
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <regex.h>
+#include "LRegex.h"
+
+///
+struct LRegex::Impl {
+ ///
+ re_pattern_buffer * preg;
+
+ ///
+ int error_code;
+
+ ///
+ mutable LRegex::SubMatches matches;
+
+ ///
+ Impl(string const & regex)
+ : preg(new re_pattern_buffer), error_code(0)
+ {
+ error_code = regcomp(preg, regex.c_str(), REG_EXTENDED);
+ }
+
+ ///
+ ~Impl()
+ {
+ regfree(preg);
+ delete preg;
+ }
+
+ ///
+ bool exact_match(string const & str) const
+ {
+ regmatch_t tmp;
+ if (!regexec(preg, str.c_str(), 1, &tmp, 0)) {
+ if (tmp.rm_so == 0 &&
+ tmp.rm_eo == static_cast<signed int>(str.length()))
+ return true;
+ }
+ // no match
+ return false;
+ }
+
+ ///
+ LRegex::MatchPair first_match(string const & str) const
+ {
+ regmatch_t tmp;
+ regexec(preg, str.c_str(), 1, &tmp, 0);
+ unsigned int first = tmp.rm_so != -1 ?
+ static_cast<unsigned int>(tmp.rm_so) : string::npos;
+ unsigned int second = tmp.rm_eo != -1 ?
+ static_cast<unsigned int>(tmp.rm_eo) : string::npos;
+ return make_pair(first, second - first);
+ }
+
+ ///
+ string getError() const
+ {
+ size_t nr = regerror(error_code, preg, 0, 0);
+ char * tmp = new char[nr];
+ regerror(error_code, preg, tmp, nr);
+ string ret(tmp);
+ delete [] tmp;
+ return ret;
+ }
+
+ ///
+ LRegex::SubMatches const & exec(string const & str) const
+ {
+ // Some room for improvement in this func. I realize
+ // that it is double as expensive as needed, but that
+ // is something I am willing to pay to get the nice
+ // interface. One thing that can be done is to only put
+ // valid submatches into matches. That will not make this
+ // func much faster, but client code will be simpler,
+ // because then it will only be needed to scan through
+ // all the entries in matches.
+ size_t subs = (preg->re_nsub != 0 ? (preg->re_nsub + 1) : 1);
+ regmatch_t * mat = new regmatch_t[subs];
+ unsigned int first = 0;
+ unsigned int second = 0;
+ matches.erase(matches.begin(), matches.end());
+ if (!regexec(preg, str.c_str(), subs, mat, 0)) { // some match
+ matches.reserve(subs);
+ for (size_t i = 0; i < subs; ++i) {
+ first = mat[i].rm_so != -1 ?
+ static_cast<unsigned int>
+ (mat[i].rm_so) : string::npos;
+ second = mat[i].rm_eo != -1 ?
+ static_cast<unsigned int>
+ (mat[i].rm_eo) : string::npos;
+ matches.push_back(make_pair(first,
+ second - first));
+ }
+ }
+ delete[] mat;
+ return matches;
+ }
+};
+
+
+LRegex::LRegex(string const & regex)
+ : impl(new Impl(regex)) {}
+
+
+LRegex::~LRegex()
+{
+ delete impl;
+}
+
+
+LRegex::SubMatches const & LRegex::exec(string const & str) const
+{
+ return impl->exec(str);
+}
+
+
+bool LRegex::exact_match(string const & str) const
+{
+ return impl->exact_match(str);
+}
+
+
+LRegex::MatchPair LRegex::first_match(string const & str) const
+{
+ return impl->first_match(str);
+}
+
+
+string LRegex::getError() const
+{
+ return impl->getError();
+}
+
+
+int LRegex::getErrorCode() const
+{
+ return impl->error_code;
+}
+
+
+bool LRegex::ok() const {
+ return impl->error_code == 0;
+}
+
+
+#if 0
+// some built in regular expressions
+
+// this is good
+const LRegex LRXwhite("[ \n\t\r\v\f]+");
+// this is good
+const LRegex LRXint("-?[0-9]+");
+// this is good
+const LRegex LRXdouble("-?(([0-9]+.[0-9]*)|"
+ "([0-9]+)|(.[0-9]+))"
+ "([eE][---+]?[0-9]+)?");
+// not usable
+// const LRegex LRXalpha("[A-Za-z]+");
+// not usable (only ascii)
+// const LRegex LRXlowercase("[a-z]+");
+// not usable (only ascii)
+// const LRegex LRXuppercase("[A-Z]+");
+// not usable (only ascii)
+// const LRegex LRXalphanum("[0-9A-Za-z]+");
+// this is good
+const LRegex LRXidentifier("[A-Za-z_][A-Za-z0-9_]*");
+#endif
--- /dev/null
+// -*- C++ -*-
+
+/* C++ wrapper around the POSIX regex functions:
+ regcomp, regexec, regerror, regfree.
+*/
+
+#ifndef LREGEX_H
+#define LREGEX_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <vector>
+
+#include "LString.h"
+
+///
+class LRegex {
+public:
+ ///
+ LRegex(string const & regex);
+
+ ///
+ ~LRegex();
+
+ ///
+ typedef pair<string::size_type, string::size_type> MatchPair;
+
+ ///
+ typedef vector<MatchPair> SubMatches;
+
+ /// Returns all the matches in a vector
+ SubMatches const & exec(string const & str) const;
+
+ /// The whole of str matches regex.
+ bool exact_match(string const & str) const;
+
+ ///
+ MatchPair first_match(string const & str) const;
+
+ ///
+ string getError() const;
+
+ ///
+ int getErrorCode() const;
+
+ /// Will the next operation fail of not.
+ bool ok() const;
+private:
+ ///
+ struct Impl;
+
+ ///
+ Impl * impl;
+};
+
+
+// We comment out these, we can comment them in when we need them.
+#if 0
+// some built in regular expressions
+
+extern const LRegex LRXwhite; // = "[ \n\t\r\v\f]+"
+extern const LRegex LRXint; // = "-?[0-9]+"
+extern const LRegex LRXdouble; // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
+ // \\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\)
+ // \\([eE][---+]?[0-9]+\\)?"
+//extern const LRegex LRXalpha; // = "[A-Za-z]+"
+//extern const LRegex LRXlowercase; // = "[a-z]+"
+//extern const LRegex LRXuppercase; // = "[A-Z]+"
+//extern const LRegex LRXalphanum; // = "[0-9A-Za-z]+"
+extern const LRegex LRXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
+#endif
+#endif
--- /dev/null
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1995 Matthias Ettrich
+ * Copyright (C) 1995-1998 The LyX Team.
+ *
+ *======================================================*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "LSubstring.h"
+
+
+LSubstring::LSubstring(string & s, size_type i, size_type l)
+ : ps(&s), pos(i), n(l)
+{
+}
+
+
+LSubstring::LSubstring(string & s, string & s2)
+ : ps(&s), n(s2.length())
+{
+ pos = s.find(s2);
+}
+
+
+LSubstring::LSubstring(string & s, char * p)
+ : ps(&s)
+{
+ n = strlen(p);
+ pos = s.find(p);
+}
+
+
+LSubstring::LSubstring(string & s, LRegex & r)
+ : ps(&s)
+{
+ LRegex::MatchPair res = r.first_match(s);
+ if (res.first != string::npos) {
+ n = res.second;
+ pos = res.first;
+ } else {
+ n = 0;
+ pos = 0;
+ }
+}
+
+
+LSubstring & LSubstring::operator=(string const & s)
+{
+ ps->replace(pos, n, s); // write through to *ps
+ return *this;
+}
+
+
+LSubstring & LSubstring::operator=(LSubstring const & s)
+{
+ ps->replace(pos, n, string(s, 0, string::npos));
+ return *this;
+}
+
+
+LSubstring & LSubstring::operator=(char const * p)
+{
+ ps->replace(pos, n, p);
+ return *this;
+}
+
+
+LSubstring & LSubstring::operator=(char c)
+{
+ ps->replace(pos, n, 1, c);
+ return *this;
+}
+
+
+LSubstring::operator string() const
+{
+ return string(*ps, pos, n); // copy from *ps
+}
+
+
+#if 0
+LSubstring::operator char const * () const
+{
+ static string tr;
+ tr.assign(*ps, pos, n);
+ return tr.c_str();
+}
+#endif
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright (C) 1995 Matthias Ettrich
+ * Copyright (C) 1995-1998 The LyX Team.
+ *
+ *======================================================*/
+
+// This one is heavily based on the substring class in The C++
+// Programming Language by Bjarne Stroustrup
+
+#ifndef LSUBSTRING_H
+#define LSUBSTRING_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+#include "LString.h"
+#include "LRegex.h"
+
+///
+class LSubstring {
+public:
+ ///
+ typedef string::size_type size_type;
+ ///
+ LSubstring(string & s, size_type i, size_type n);
+ ///
+ LSubstring(string & s, string & s2);
+ ///
+ LSubstring(string & s, string::value_type * p);
+ ///
+ LSubstring(string & s, LRegex & r);
+ ///
+ LSubstring & operator=(string const &);
+ ///
+ LSubstring & operator=(LSubstring const &);
+ ///
+ LSubstring & operator=(string::value_type const *);
+ ///
+ LSubstring & operator=(string::value_type);
+ ///
+ operator string() const;
+#if 0
+ ///
+ operator char const * () const;
+#endif
+private:
+ ///
+ string * ps;
+ ///
+ size_type pos;
+ ///
+ size_type n;
+};
+
+#endif
LAssert.h \
LIstream.h \
LOstream.h \
+ LRegex.C \
+ LRegex.h \
+ LSubstring.C \
+ LSubstring.h \
filetools.C \
filetools.h \
lstrings.C \
// in this file consult me and/or the standard to discover the
// right behavior.
+// Asserts with a STD! are required by the standard.
+// Asserts with a OURS! are added by me.
// Reference count has been checked, empty_rep removed and
// introduced again in a similar guise. Where is empty_rep _really_
// needed?
// I have so far not tested them extensively and would be
// happy if others took the time to have a peek.
+// Lgb.
///////////////////////////////////////
// The internal string representation
void lyxstring::Srep::insert(lyxstring::size_type pos, const value_type * p,
lyxstring::size_type n)
{
- Assert(pos <= sz);
if (res < n + sz) {
res = sz + n + xtra;
value_type * tmp = new value_type[res + 1];
void lyxstring::Srep::resize(size_type n, value_type c)
{
- Assert(n < npos);
// This resets sz to res_arg
res = min(n, npos - 2); // We keep no xtra when we resize
value_type * tmp = new value_type[res + 1];
value_type const * p, size_type n2)
{
// can be called with p=0 and n2=0
- Assert(i < sz && ((!p && !n2) || p));
n = min(sz - i, n);
sz -= n;
if (res >= n2 + sz) {
lyxstring::lyxstring(lyxstring const & x, size_type pos, size_type n)
{
- Assert(pos < x.rep->sz || pos == 0);
+ Assert(pos <= x.rep->sz); // STD!
if (pos == 0 && n >= x.length()) { // this is the default
x.rep->ref++;
rep = x.rep;
lyxstring::lyxstring(value_type const * s, size_type n)
{
- Assert(s); // we don't allow null pointers
+ 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);
lyxstring::lyxstring(value_type const * s)
{
- Assert(s); // we don't allow null pointers
+ Assert(s); // STD!
static Srep empty_rep(0, "");
if (*s) { // s is not empty string
rep = new Srep(strlen(s), s);
lyxstring::lyxstring(size_type n, value_type c)
{
+ Assert(n < npos); // STD!
rep = new Srep(n, c);
}
void lyxstring::resize(size_type n, value_type c)
{
+ Assert(n <= npos); // STD!
TestlyxstringInvariant(this);
// This resets sz to res_arg
lyxstring & lyxstring::operator=(value_type const * s)
{
- Assert(s);
+ Assert(s); // OURS!
TestlyxstringInvariant(this);
// printf("lyxstring::operator=(value_type const *)\n");
lyxstring & lyxstring::assign(lyxstring const & x, size_type pos, size_type n)
{
+ Assert(pos <= x.rep->sz); // STD!
TestlyxstringInvariant(this);
return assign(x.substr(pos, n));
lyxstring & lyxstring::assign(value_type const * s, size_type n)
{
- Assert(s);
+ Assert(s); // OURS!
TestlyxstringInvariant(this);
n = min(strlen(s), n);
lyxstring & lyxstring::assign(value_type const * s)
{
- Assert(s);
+ Assert(s); // OURS!
TestlyxstringInvariant(this);
return assign(s, strlen(s));
lyxstring::const_reference lyxstring::operator[](size_type pos) const
{
- Assert(pos < rep->sz);
- return rep->s[pos];
+ Assert(pos <= rep->sz); // OURS!
+ return pos == rep->sz ? '\0' : rep->s[pos];
}
lyxstring::reference lyxstring::operator[](size_type pos)
{
- Assert(pos < rep->sz);
+ Assert(pos < rep->sz); // OURS!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring::const_reference lyxstring::at(size_type n) const
{
- Assert(n < rep->sz);
+ Assert(n < rep->sz); // STD!
return rep->s[n];
}
lyxstring::reference lyxstring::at(size_type n)
{
- Assert(n < rep->sz);
+ Assert(n < rep->sz); // STD!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring & lyxstring::operator+=(value_type const * x)
{
- Assert(x);
+ Assert(x); // OURS!
TestlyxstringInvariant(this);
return append(x);
lyxstring & lyxstring::append(lyxstring const & x, size_type pos, size_type n)
{
+ Assert(pos <= x.rep->sz); // STD!
TestlyxstringInvariant(this);
return append(x.substr(pos, n));
lyxstring & lyxstring::append(value_type const * p, size_type n)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
if (!*p || !n) return *this;
lyxstring & lyxstring::append(value_type const * p)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
if (!*p) return *this;
lyxstring & lyxstring::insert(size_type pos, lyxstring const & x,
size_type pos2, size_type n)
{
+ Assert(pos <= rep->sz && pos2 <= x.rep->sz); // STD!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring & lyxstring::insert(size_type pos, value_type const * p, size_type n)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
if (*p && n) {
lyxstring & lyxstring::insert(size_type pos, value_type const * p)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
if (*p) {
lyxstring::size_type lyxstring::find(value_type const * ptr, size_type i,
size_type n) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
if (!rep->sz || !*ptr || i >= rep->sz) return npos;
TestlyxstringInvariant(this);
lyxstring::size_type lyxstring::find(value_type const * s, size_type i) const
{
- Assert(s);
+ Assert(s); // OURS!
if (!rep->sz || i >= rep->sz) return npos;
TestlyxstringInvariant(this);
lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i,
size_type n) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
if (!*ptr) return npos;
lyxstring::size_type lyxstring::rfind(value_type const * ptr,
size_type i) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
if (!*ptr) return npos;
lyxstring::size_type lyxstring::find_first_of(lyxstring const & a,
size_type i) const
{
- Assert(i < rep->sz);
+ Assert(i < rep->sz); // OURS!
TestlyxstringInvariant(this);
for (size_type t = i; t < rep->sz; ++t) {
lyxstring::size_type lyxstring::find_first_of(value_type const * ptr, size_type i,
size_type n) const
{
- Assert(ptr && i < rep->sz);
+ Assert(ptr && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
if (!n) return npos;
lyxstring::size_type lyxstring::find_first_of(value_type const * ptr,
size_type i) const
{
- Assert(ptr && i < rep->sz);
+ Assert(ptr && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
for (size_type t = i; t < rep->sz; ++t) {
lyxstring::size_type lyxstring::find_first_of(value_type c, size_type i) const
{
- Assert(i < rep->sz);
+ Assert(i < rep->sz); // OURS!
TestlyxstringInvariant(this);
for (size_type t = i; t < rep->sz; ++t) {
lyxstring::size_type lyxstring::find_last_of(value_type const * ptr, size_type i,
size_type n) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
if (!n) return npos;
lyxstring::size_type lyxstring::find_last_of(value_type const * ptr,
size_type i) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
size_type ii = min(rep->sz - 1, i);
size_type i,
size_type n) const
{
- Assert(ptr && i < rep->sz);
+ Assert(ptr && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
if (!n) return (i < rep->sz) ? i : npos;
lyxstring::size_type lyxstring::find_first_not_of(value_type const * ptr,
size_type i) const
{
- Assert(ptr && i < rep->sz);
+ Assert(ptr && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
for (size_type t = i; t < rep->sz; ++t) {
size_type i) const
{
if (!rep->sz) return npos;
- Assert(i < rep->sz);
+ Assert(i < rep->sz); // OURS!
TestlyxstringInvariant(this);
for (size_type t = i; t < rep->sz; ++t) {
size_type i,
size_type n) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
if (!n) return npos;
lyxstring::size_type lyxstring::find_last_not_of(value_type const * ptr,
size_type i) const
{
- Assert(ptr);
+ Assert(ptr); // OURS!
TestlyxstringInvariant(this);
size_type ii = min(rep->sz - 1, i);
lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x)
{
- Assert(i < rep->sz || i == 0);
+ Assert(i <= rep->sz); // OURS!
TestlyxstringInvariant(this);
- return replace(i, n, x, 0, x.length());
+ return replace(i, n, x, 0, x.rep->sz);
}
-lyxstring & lyxstring::replace(size_type i,size_type n, lyxstring const & x,
+lyxstring & lyxstring::replace(size_type i, size_type n, lyxstring const & x,
size_type i2, size_type n2)
{
- Assert((i < rep->sz || i == 0) && (i2 < x.rep->sz || i2 == 0));
+ Assert(i <= rep->sz && i2 <= x.rep->sz); // STD!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring & lyxstring::replace(size_type i, size_type n,
value_type const * p, size_type n2)
{
- Assert(p && i < rep->sz);
+ Assert(p && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring & lyxstring::replace(size_type i, size_type n, value_type const * p)
{
- Assert(p && i < rep->sz);
+ Assert(p && i < rep->sz); // OURS!
TestlyxstringInvariant(this);
return replace(i, min(n, rep->sz), p, (!p) ? 0 : strlen(p));
lyxstring & lyxstring::replace(size_type i, size_type n,
size_type n2, value_type c)
{
- Assert(i < rep->sz);
+ Assert(i < rep->sz); // OURS!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring & lyxstring::replace(iterator i, iterator i2,
value_type const * p, size_type n)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
return replace(i - begin(), i2 - i, p, n);
lyxstring & lyxstring::replace(iterator i, iterator i2, value_type const * p)
{
- Assert(p);
+ Assert(p); // OURS!
TestlyxstringInvariant(this);
return replace(i - begin(), i2 - i, p);
lyxstring & lyxstring::erase(size_type i, size_type n)
{
- Assert(i < rep->sz || i == 0);
+ Assert(i <= rep->sz); // STD!
TestlyxstringInvariant(this);
rep = rep->get_own_copy();
lyxstring::size_type lyxstring::copy(value_type * buf, size_type len,
size_type pos) const
{
- Assert(buf);
+ Assert(buf); // OURS!
+ Assert(pos <= rep->sz); // STD!
TestlyxstringInvariant(this);
register int nn = min(len, length() - pos);
int lyxstring::compare(value_type const * s) const
{
- Assert(s);
+ Assert(s); //OURS!
TestlyxstringInvariant(this);
int n = (!s) ? 0 : strlen(s);
return internal_compare(0, rep->sz, s, n, n);
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str) const
{
- Assert(pos < rep->sz || pos == 0);
+ Assert(pos <= rep->sz); // OURS!
TestlyxstringInvariant(this);
return internal_compare(pos, n, str.rep->s, str.rep->sz, str.rep->sz);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
size_type pos2, size_type n2) const
{
- Assert(pos < rep->sz || pos == 0);
- Assert(pos2 < str.rep->sz || pos2 == 0);
+ Assert(pos <= rep->sz); // OURS!
+ Assert(pos2 <= str.rep->sz); // OURS!
TestlyxstringInvariant(this);
return internal_compare(pos, n,
str.rep->s + pos2,
int lyxstring::compare(size_type pos, size_type n, value_type const * s,
size_type n2) const
{
- Assert(s && (pos < rep->sz || pos == 0));
+ Assert(s && pos <= rep->sz); // OURS!
TestlyxstringInvariant(this);
return internal_compare(pos, n, s, (!s) ? 0 : strlen(s), n2);
}
// i = index, n = length
lyxstring lyxstring::substr(size_type i, size_type n) const
{
- Assert(i < rep->sz || i == 0);
+ Assert(i <= rep->sz); // STD!
TestlyxstringInvariant(this);
return lyxstring(*this, i, n);
bool operator==(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) == 0;
}
bool operator==(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) == 0;
}
bool operator!=(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) != 0;
}
bool operator!=(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) != 0;
}
bool operator>(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) < 0; // since we reverse the parameters
}
bool operator>(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) > 0;
}
bool operator<(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) > 0; // since we reverse the parameters
}
bool operator<(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) < 0;
}
bool operator>=(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) <= 0; // since we reverse the parameters
}
bool operator>=(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) >= 0;
}
bool operator<=(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
return b.compare(a) >= 0; // since we reverse the parameters
}
bool operator<=(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
return a.compare(b) <= 0;
}
lyxstring operator+(lyxstring::value_type const * a, lyxstring const & b)
{
- Assert(a);
+ Assert(a); // OURS!
lyxstring tmp(a);
tmp += b;
return tmp;
lyxstring operator+(lyxstring const & a, lyxstring::value_type const * b)
{
- Assert(b);
+ Assert(b); // OURS!
lyxstring tmp(a);
tmp += b;
return tmp;