1999-11-09 22:20:24 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-12-13 00:05:34 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-11-09 22:20:24 +00:00
|
|
|
*
|
1999-11-15 10:54:16 +00:00
|
|
|
* ====================================================== */
|
1999-11-09 22:20:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-11-09 22:20:24 +00:00
|
|
|
#include "LSubstring.h"
|
|
|
|
|
|
|
|
|
|
|
|
LSubstring::LSubstring(string & s, size_type i, size_type l)
|
|
|
|
: ps(&s), pos(i), n(l)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 14:45:17 +00:00
|
|
|
LSubstring::LSubstring(string & s, string const & s2)
|
1999-11-09 22:20:24 +00:00
|
|
|
: ps(&s), n(s2.length())
|
|
|
|
{
|
|
|
|
pos = s.find(s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 14:45:17 +00:00
|
|
|
LSubstring::LSubstring(string & s, string::value_type const * p)
|
1999-11-09 22:20:24 +00:00
|
|
|
: ps(&s)
|
|
|
|
{
|
|
|
|
n = strlen(p);
|
|
|
|
pos = s.find(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 14:45:17 +00:00
|
|
|
LSubstring::LSubstring(string & s, LRegex const & r)
|
1999-11-09 22:20:24 +00:00
|
|
|
: ps(&s)
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
LRegex::MatchPair const res = r.first_match(s);
|
1999-11-09 22:20:24 +00:00
|
|
|
if (res.first != string::npos) {
|
|
|
|
n = res.second;
|
|
|
|
pos = res.first;
|
|
|
|
} else {
|
|
|
|
n = 0;
|
2000-01-24 18:34:46 +00:00
|
|
|
pos = string::npos;
|
1999-11-09 22:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSubstring & LSubstring::operator=(string const & s)
|
|
|
|
{
|
|
|
|
ps->replace(pos, n, s); // write through to *ps
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSubstring & LSubstring::operator=(LSubstring const & s)
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
ps->replace(pos, n, s);
|
1999-11-09 22:20:24 +00:00
|
|
|
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
|
|
|
|
}
|