lyx_mirror/src/support/LSubstring.C
Lars Gullik Bjønnes d6665cba42 get rid of dead code, some new functions constify variables.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1041 a592a061-630c-0410-9148-cb99ea01b6c8
2000-09-26 13:54:57 +00:00

89 lines
1.4 KiB
C

/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2000 The LyX Team.
*
* ====================================================== */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef __GNUG__
#pragma implementation
#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 const & s2)
: ps(&s), n(s2.length())
{
pos = s.find(s2);
}
LSubstring::LSubstring(string & s, string::value_type const * p)
: ps(&s)
{
n = strlen(p);
pos = s.find(p);
}
LSubstring::LSubstring(string & s, LRegex const & r)
: ps(&s)
{
LRegex::MatchPair const res = r.first_match(s);
if (res.first != string::npos) {
n = res.second;
pos = res.first;
} else {
n = 0;
pos = string::npos;
}
}
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, s);
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
}