mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
get rid of LRegex and LSubstring, use boost::regex instead
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4206 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
724ef59519
commit
08b4385454
@ -1,3 +1,19 @@
|
||||
2002-05-25 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* vc-backend.C (scanMaster): use boost regex and get rid of LRegex
|
||||
and LSubstring
|
||||
|
||||
* chset.C: change include order
|
||||
(loadFile): use boost regex and get rid of LRegex and LSubstring
|
||||
|
||||
* Makefile.am (BOOST_LIBS): new variable
|
||||
(lyx_LDADD): use it
|
||||
|
||||
* LaTeX.C: change include order.
|
||||
(scanAuxFile): use boost regex and get rid of LRegex and
|
||||
LSubstring
|
||||
(deplog): ditto
|
||||
|
||||
2002-05-24 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* ColorHandler.h:
|
||||
@ -10,20 +26,20 @@
|
||||
|
||||
* Makefile.am:
|
||||
* lyx_gui.C:
|
||||
* lyxfont.C:
|
||||
* lyxfont.C:
|
||||
* lyxfunc.C: changes from above
|
||||
|
||||
|
||||
2002-05-24 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* LColor.C: remove spurious X include
|
||||
|
||||
|
||||
* BufferView_pimpl.C:
|
||||
* Makefile.am:
|
||||
* font.h:
|
||||
* font.C:
|
||||
* text.C:
|
||||
* text2.C: move font metrics to frontends/
|
||||
|
||||
|
||||
2002-05-24 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* undo_funcs.C (textHandleUndo): fix the cursor selection after
|
||||
@ -39,7 +55,7 @@
|
||||
* WorkArea.h:
|
||||
* WorkArea.C:
|
||||
* screen.C: move WorkArea into frontends/
|
||||
|
||||
|
||||
* lyxscreen.h:
|
||||
* screen.C:
|
||||
* text.C:
|
||||
@ -64,8 +80,8 @@
|
||||
* buffer.C:
|
||||
* bufferlist.C:
|
||||
* bufferview_funcs.C:
|
||||
* converter.C:
|
||||
* importer.C:
|
||||
* converter.C:
|
||||
* importer.C:
|
||||
* lyx_cb.C:
|
||||
* lyx_gui.C:
|
||||
* lyx_main.C:
|
||||
@ -77,7 +93,7 @@
|
||||
* text2.C:
|
||||
* trans.C:
|
||||
* vc-backend.C: move LyX/XFormsView into frontends/
|
||||
|
||||
|
||||
2002-05-23 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* Makefile.am:
|
||||
@ -91,7 +107,7 @@
|
||||
* tabular.C:
|
||||
* text.C:
|
||||
* text2.C: move Painter to frontends/
|
||||
|
||||
|
||||
2002-05-22 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* buffer.C: comment out some some code that depend upon lyx_format
|
||||
|
88
src/LaTeX.C
88
src/LaTeX.C
@ -16,7 +16,6 @@
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <fstream>
|
||||
|
||||
#include "LaTeX.h"
|
||||
#include "bufferlist.h"
|
||||
@ -25,13 +24,15 @@
|
||||
#include "debug.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/LRegex.h"
|
||||
#include "support/LSubstring.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/systemcall.h"
|
||||
#include "support/os.h"
|
||||
#include "support/path.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstdio> // sscanf
|
||||
|
||||
using std::ifstream;
|
||||
@ -39,6 +40,9 @@ using std::getline;
|
||||
using std::endl;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
using boost::regex;
|
||||
using boost::regex_match;
|
||||
using boost::smatch;
|
||||
|
||||
// TODO: in no particular order
|
||||
// - get rid of the extern BufferList and the call to
|
||||
@ -415,17 +419,16 @@ void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
|
||||
|
||||
ifstream ifs(file.c_str());
|
||||
string token;
|
||||
LRegex reg1("\\\\citation\\{([^}]+)\\}");
|
||||
LRegex reg2("\\\\bibdata\\{([^}]+)\\}");
|
||||
LRegex reg3("\\\\bibstyle\\{([^}]+)\\}");
|
||||
LRegex reg4("\\\\@input\\{([^}]+)\\}");
|
||||
regex reg1("\\\\citation\\{([^}]+)\\}");
|
||||
regex reg2("\\\\bibdata\\{([^}]+)\\}");
|
||||
regex reg3("\\\\bibstyle\\{([^}]+)\\}");
|
||||
regex reg4("\\\\@input\\{([^}]+)\\}");
|
||||
|
||||
while (getline(ifs, token)) {
|
||||
token = strip(token, '\r');
|
||||
if (reg1.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg1.exec(token);
|
||||
string data = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
smatch sub;
|
||||
if (regex_match(token, sub, reg1)) {
|
||||
string data = sub[1];
|
||||
while (!data.empty()) {
|
||||
string citation;
|
||||
data = split(data, citation, ',');
|
||||
@ -433,10 +436,8 @@ void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
|
||||
<< citation << endl;
|
||||
aux_info.citations.insert(citation);
|
||||
}
|
||||
} else if (reg2.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg2.exec(token);
|
||||
string data = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (regex_match(token, sub, reg2)) {
|
||||
string data = sub[1];
|
||||
// data is now all the bib files separated by ','
|
||||
// get them one by one and pass them to the helper
|
||||
while (!data.empty()) {
|
||||
@ -447,20 +448,16 @@ void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
|
||||
<< database << "'" << endl;
|
||||
aux_info.databases.insert(database);
|
||||
}
|
||||
} else if (reg3.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg3.exec(token);
|
||||
string style = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (regex_match(token, sub, reg3)) {
|
||||
string style = sub[1];
|
||||
// token is now the style file
|
||||
// pass it to the helper
|
||||
style = ChangeExtension(style, "bst");
|
||||
lyxerr[Debug::LATEX] << "Bibtex style: `"
|
||||
<< style << "'" << endl;
|
||||
aux_info.styles.insert(style);
|
||||
} else if (reg4.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg4.exec(token);
|
||||
string file2 = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (regex_match(token, sub, reg4)) {
|
||||
string file2 = sub[1];
|
||||
scanAuxFile(file2, aux_info);
|
||||
}
|
||||
}
|
||||
@ -656,16 +653,16 @@ void LaTeX::deplog(DepTable & head)
|
||||
|
||||
string const logfile = OnlyFilename(ChangeExtension(file, ".log"));
|
||||
|
||||
LRegex reg1("\\)* *\\(([^ )]+).*");
|
||||
LRegex reg2("File: ([^ ]+).*");
|
||||
LRegex reg3("No file ([^ ]+)\\..*");
|
||||
LRegex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*");
|
||||
regex reg1("\\)* *\\(([^ )]+).*");
|
||||
regex reg2("File: ([^ ]+).*");
|
||||
regex reg3("No file ([^ ]+)\\..*");
|
||||
regex reg4("\\\\openout[0-9]+.*=.*`([^ ]+)'\\..*");
|
||||
// If an index should be created, MikTex does not write a line like
|
||||
// \openout# = 'sample,idx'.
|
||||
// but intstead only a line like this into the log:
|
||||
// Writing index file sample.idx
|
||||
LRegex reg5("Writing index file ([^ ]+).*");
|
||||
LRegex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
|
||||
regex reg5("Writing index file ([^ ]+).*");
|
||||
regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
|
||||
|
||||
ifstream ifs(logfile.c_str());
|
||||
while (ifs) {
|
||||
@ -680,26 +677,17 @@ void LaTeX::deplog(DepTable & head)
|
||||
token = strip(token, '\r');
|
||||
if (token.empty()) continue;
|
||||
|
||||
if (reg1.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg1.exec(token);
|
||||
foundfile = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (reg2.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg2.exec(token);
|
||||
foundfile = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (reg3.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg3.exec(token);
|
||||
foundfile = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (reg4.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg4.exec(token);
|
||||
foundfile = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
} else if (reg5.exact_match(token)) {
|
||||
LRegex::SubMatches const & sub = reg5.exec(token);
|
||||
foundfile = LSubstring(token, sub[1].first,
|
||||
sub[1].second);
|
||||
smatch sub;
|
||||
if (regex_match(token, sub, reg1)) {
|
||||
foundfile = sub[1];
|
||||
} else if (regex_match(token, sub, reg2)) {
|
||||
foundfile = sub[1];
|
||||
} else if (regex_match(token, sub, reg3)) {
|
||||
foundfile = sub[1];
|
||||
} else if (regex_match(token, sub, reg4)) {
|
||||
foundfile = sub[1];
|
||||
} else if (regex_match(token, sub, reg5)) {
|
||||
foundfile = sub[1];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -732,7 +720,7 @@ void LaTeX::deplog(DepTable & head)
|
||||
// (2) foundfile is in the tmpdir
|
||||
// insert it into head
|
||||
else if (FileInfo(OnlyFilename(foundfile)).exist()) {
|
||||
if (unwanted.exact_match(foundfile)) {
|
||||
if (regex_match(foundfile, unwanted)) {
|
||||
lyxerr[Debug::DEPEND]
|
||||
<< "We don't want "
|
||||
<< OnlyFilename(foundfile)
|
||||
|
@ -15,9 +15,11 @@ LYX_CONV_LIBS = mathed/libmathed.la insets/libinsets.la \
|
||||
graphics/libgraphics.la \
|
||||
support/libsupport.la
|
||||
|
||||
BOOST_LIBS = ../boost/libs/regex/src/libboostregex.la
|
||||
|
||||
#lyx_DEPENDENCIES = $(LYX_CONV_LIBS) $(INCLUDED_SIGC)
|
||||
|
||||
lyx_LDADD = $(LYX_CONV_LIBS) $(SIGC_LIBS) $(INCLUDED_SIGC) @INTLLIBS@ \
|
||||
lyx_LDADD = $(LYX_CONV_LIBS) $(SIGC_LIBS) $(BOOST_LIBS) $(INCLUDED_SIGC) @INTLLIBS@ \
|
||||
$(PSPELL_LIBS) @AIKSAURUS_LIBS@
|
||||
|
||||
# @FRONTEND_LDFLAGS@ @FRONTEND_LIBS@
|
||||
@ -212,7 +214,7 @@ lyx_SOURCES = \
|
||||
lyx_main.o: lyx_main.C lyx_main.h config.h version.h lyx_gui.h \
|
||||
lyxrc.h support/path.h support/filetools.h \
|
||||
bufferlist.h debug.h support/FileInfo.h lastfiles.h intl.h \
|
||||
lyxserver.h layout.h gettext.h kbmap.h commandtags.h language.h
|
||||
lyxserver.h layout.h gettext.h kbmap.h commandtags.h language.h
|
||||
$(CXXCOMPILE) -DLYX_DIR=\"$(pkgdatadir)\" \
|
||||
-DTOP_SRCDIR=\"$(top_srcdir)\" -c $(top_srcdir)/src/lyx_main.C
|
||||
|
||||
|
23
src/chset.C
23
src/chset.C
@ -4,20 +4,23 @@
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "chset.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/LRegex.h"
|
||||
#include "support/LSubstring.h"
|
||||
#include "support/lyxlib.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
using std::ifstream;
|
||||
using std::getline;
|
||||
using std::pair;
|
||||
using std::make_pair;
|
||||
using std::endl;
|
||||
using boost::regex;
|
||||
using boost::regex_match;
|
||||
using boost::smatch;
|
||||
|
||||
bool CharacterSet::loadFile(string const & fname)
|
||||
{
|
||||
@ -44,14 +47,12 @@ bool CharacterSet::loadFile(string const & fname)
|
||||
// the fastest way to parse the cdef files, but I though it
|
||||
// was a bit neat. Anyway it is wrong to use the lyxlex parse
|
||||
// without the use of a keyword table.
|
||||
LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
|
||||
regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
|
||||
while (getline(ifs, line)) {
|
||||
if (reg.exact_match(line)) {
|
||||
LRegex::SubMatches const & sub = reg.exec(line);
|
||||
int const n = lyx::atoi(line.substr(sub[1].first,
|
||||
sub[1].second));
|
||||
string const str = LSubstring(line, sub[2].first,
|
||||
sub[2].second);
|
||||
smatch sub;
|
||||
if (regex_match(line, sub, reg)) {
|
||||
int const n = lyx::atoi(sub[1]);
|
||||
string const str = sub[2];
|
||||
if (lyxerr.debugging(Debug::KBMAP))
|
||||
lyxerr << "Chardef: " << n
|
||||
<< " to [" << str << "]" << endl;
|
||||
|
@ -1,3 +1,10 @@
|
||||
2002-05-25 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* biblio.h: include vector
|
||||
|
||||
* biblio.C: change include order
|
||||
(regexSearch): use boost regex and get rid of LRegex
|
||||
|
||||
2002-05-23 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* ControlAboutlyx.C:
|
||||
@ -30,7 +37,7 @@
|
||||
* ControlToc.C:
|
||||
* ControlUrl.C:
|
||||
* ControlVCLog.C: LyXView moved into frontends
|
||||
|
||||
|
||||
2002-05-22 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* ControlExternal.C: add scoped_ptr.hpp
|
||||
|
@ -14,9 +14,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
@ -27,7 +24,10 @@
|
||||
#include "helper_funcs.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/LAssert.h"
|
||||
#include "support/LRegex.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::find;
|
||||
using std::min;
|
||||
@ -122,11 +122,11 @@ regexSearch(InfoMap const & theMap,
|
||||
vector<string>::const_iterator start,
|
||||
Direction dir)
|
||||
{
|
||||
LRegex reg(expr);
|
||||
boost::regex reg(expr);
|
||||
|
||||
for (vector<string>::const_iterator it = start;
|
||||
// End condition is direction-dependent.
|
||||
(dir == FORWARD) ? (it<keys.end()) : (it>=keys.begin());
|
||||
(dir == FORWARD) ? (it < keys.end()) : (it >= keys.begin());
|
||||
// increment is direction-dependent.
|
||||
(dir == FORWARD) ? (++it) : (--it)) {
|
||||
|
||||
@ -135,8 +135,9 @@ regexSearch(InfoMap const & theMap,
|
||||
if (info != theMap.end())
|
||||
data += " " + info->second;
|
||||
|
||||
if (reg.exec(data).size() > 0)
|
||||
if (boost::regex_match(data, reg)) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
return keys.end();
|
||||
@ -380,7 +381,7 @@ string const parseBibTeX(string data, string const & findkey)
|
||||
// at first we delete all characters right of '%' and
|
||||
// replace tabs through a space and remove leading spaces
|
||||
// we read the data line by line so that the \n are
|
||||
// ignored, too.
|
||||
// ignored, too.
|
||||
string data_;
|
||||
int Entries = 0;
|
||||
string dummy = token(data,'\n', Entries);
|
||||
@ -390,7 +391,7 @@ string const parseBibTeX(string data, string const & findkey)
|
||||
// ignore lines with a beginning '%' or ignore all right of %
|
||||
string::size_type const idx =
|
||||
dummy.empty() ? string::npos : dummy.find('%');
|
||||
if (idx != string::npos)
|
||||
if (idx != string::npos)
|
||||
dummy.erase(idx, string::npos);
|
||||
// do we have a new token or a new line of
|
||||
// the same one? In the first case we ignore
|
||||
@ -398,7 +399,7 @@ string const parseBibTeX(string data, string const & findkey)
|
||||
// with a space
|
||||
if (!dummy.empty()) {
|
||||
if (!contains(dummy, "="))
|
||||
data_ += (' ' + dummy);
|
||||
data_ += (' ' + dummy);
|
||||
else
|
||||
data_ += dummy;
|
||||
}
|
||||
@ -424,10 +425,10 @@ string const parseBibTeX(string data, string const & findkey)
|
||||
dummy = token(data, ',', Entries++);
|
||||
if (!dummy.empty()) {
|
||||
found = contains(lowercase(dummy), findkey);
|
||||
if (findkey == "title" &&
|
||||
if (findkey == "title" &&
|
||||
contains(lowercase(dummy), "booktitle"))
|
||||
found = false;
|
||||
}
|
||||
}
|
||||
} while (!found && !dummy.empty());
|
||||
if (dummy.empty())
|
||||
// no such keyword
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define BIBLIOHELPERS_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
@ -62,7 +63,7 @@ namespace biblio
|
||||
|
||||
// rturn the year from the bibtex data record
|
||||
string const getYear(InfoMap const & map, string const & key);
|
||||
|
||||
|
||||
/// return the short form of an authorlist
|
||||
string const getAbbreviatedAuthor(InfoMap const & map, string const & key);
|
||||
|
||||
|
@ -1,3 +1,20 @@
|
||||
2002-05-25 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* filetools.C: do not include LSubstring.h
|
||||
|
||||
* lstrings.C: change include order
|
||||
(regexMatch): use boost regex get rid of LRegex and LSubstring
|
||||
|
||||
* Makefile.am (libsupport_la_SOURCES): delete regex and substring
|
||||
stuff.
|
||||
|
||||
* LSubstring.h: remove file
|
||||
* regex.c: ditto
|
||||
* lyxregex.h: ditto
|
||||
* LRegex.C: ditto
|
||||
* LRegex.h: ditto
|
||||
* LSubstring.C: ditto
|
||||
|
||||
2002-05-24 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* lyxsum.C: include local includes first (self containment)
|
||||
|
@ -1,180 +0,0 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef HAVE_REGEX_H
|
||||
#include <regex.h>
|
||||
#else
|
||||
#include "lyxregex.h"
|
||||
#endif
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "LRegex.h"
|
||||
|
||||
using std::make_pair;
|
||||
|
||||
///
|
||||
struct LRegex::Impl {
|
||||
///
|
||||
regex_t * preg;
|
||||
|
||||
///
|
||||
int error_code;
|
||||
|
||||
///
|
||||
mutable LRegex::SubMatches matches;
|
||||
|
||||
///
|
||||
Impl(string const & regex)
|
||||
: preg(new regex_t), 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 const first_match(string const & str) const
|
||||
{
|
||||
regmatch_t tmp;
|
||||
regexec(preg, str.c_str(), 1, &tmp, 0);
|
||||
string::size_type const first = tmp.rm_so != -1 ?
|
||||
tmp.rm_so : string::npos;
|
||||
string::size_type const second = tmp.rm_eo != -1 ?
|
||||
tmp.rm_eo : string::npos;
|
||||
return make_pair(first, second - first);
|
||||
}
|
||||
|
||||
///
|
||||
string const getError() const
|
||||
{
|
||||
size_t nr = regerror(error_code, preg, 0, 0);
|
||||
char * tmp = new char[nr];
|
||||
regerror(error_code, preg, tmp, nr);
|
||||
string const 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 const subs =
|
||||
(preg->re_nsub != 0 ? (preg->re_nsub + 1) : 1);
|
||||
regmatch_t * mat = new regmatch_t[subs];
|
||||
string::size_type first = 0;
|
||||
string::size_type 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 ?
|
||||
mat[i].rm_so : string::npos;
|
||||
second = mat[i].rm_eo != -1 ?
|
||||
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 const LRegex::first_match(string const & str) const
|
||||
{
|
||||
return impl->first_match(str);
|
||||
}
|
||||
|
||||
|
||||
string const 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
|
@ -1,59 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
/* C++ wrapper around the POSIX regex functions:
|
||||
regcomp, regexec, regerror, regfree.
|
||||
*/
|
||||
|
||||
#ifndef LREGEX_H
|
||||
#define LREGEX_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "LString.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
///
|
||||
class LRegex {
|
||||
public:
|
||||
///
|
||||
explicit
|
||||
LRegex(string const & regex);
|
||||
|
||||
///
|
||||
~LRegex();
|
||||
|
||||
///
|
||||
typedef std::pair<string::size_type, string::size_type> MatchPair;
|
||||
|
||||
///
|
||||
typedef std::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 const first_match(string const & str) const;
|
||||
|
||||
///
|
||||
string const getError() const;
|
||||
|
||||
///
|
||||
int getErrorCode() const;
|
||||
|
||||
/// Will the next operation fail of not.
|
||||
bool ok() const;
|
||||
private:
|
||||
///
|
||||
struct Impl;
|
||||
|
||||
///
|
||||
Impl * impl;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,93 +0,0 @@
|
||||
/* This file is part of
|
||||
* ======================================================
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-2001 The LyX Team.
|
||||
*
|
||||
* ====================================================== */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "LSubstring.h"
|
||||
|
||||
#ifndef CXX_GLOBAL_CSTD
|
||||
using std::strlen;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
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=(string::value_type const * p)
|
||||
{
|
||||
ps->replace(pos, n, p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LSubstring & LSubstring::operator=(string::value_type c)
|
||||
{
|
||||
ps->replace(pos, n, 1, c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LSubstring::operator string() const
|
||||
{
|
||||
return string(*ps, pos, n); // copy from *ps
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/* This file is part of
|
||||
* ======================================================
|
||||
*
|
||||
* LyX, The Document Processor
|
||||
*
|
||||
* Copyright 1995 Matthias Ettrich
|
||||
* Copyright 1995-2001 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 const & s2);
|
||||
///
|
||||
LSubstring(string & s, string::value_type const * p);
|
||||
///
|
||||
LSubstring(string & s, LRegex const & r);
|
||||
///
|
||||
LSubstring & operator=(string const &);
|
||||
///
|
||||
LSubstring & operator=(LSubstring const &);
|
||||
///
|
||||
LSubstring & operator=(string::value_type const *);
|
||||
///
|
||||
LSubstring & operator=(string::value_type);
|
||||
///
|
||||
operator string() const;
|
||||
private:
|
||||
///
|
||||
string * ps;
|
||||
///
|
||||
size_type pos;
|
||||
///
|
||||
size_type n;
|
||||
};
|
||||
|
||||
#endif
|
@ -4,15 +4,12 @@ noinst_LTLIBRARIES = libsupport.la
|
||||
|
||||
INCLUDES = -I$(srcdir)/../ $(SIGC_INCLUDES) $(BOOST_INCLUDES)
|
||||
|
||||
EXTRA_DIST = lyxstring.C lyxstring.h regex.c lyxregex.h \
|
||||
os_unix.C os_win32.C os_os2.C
|
||||
EXTRA_DIST = lyxstring.C lyxstring.h \
|
||||
os_unix.C os_win32.C os_os2.C
|
||||
|
||||
if USE_LYXSTRING
|
||||
LYXSTRING = lyxstring.C lyxstring.h
|
||||
endif
|
||||
if USE_REGEX
|
||||
REGEX = regex.c lyxregex.h
|
||||
endif
|
||||
|
||||
libsupport_la_SOURCES = \
|
||||
DebugStream.C \
|
||||
@ -23,10 +20,6 @@ libsupport_la_SOURCES = \
|
||||
LAssert.h \
|
||||
LIstream.h \
|
||||
LOstream.h \
|
||||
LRegex.C \
|
||||
LRegex.h \
|
||||
LSubstring.C \
|
||||
LSubstring.h \
|
||||
os.C \
|
||||
os.h \
|
||||
StrPool.C \
|
||||
@ -67,7 +60,7 @@ libsupport_la_SOURCES = \
|
||||
snprintf.h \
|
||||
snprintf.c \
|
||||
sstream.h \
|
||||
$(REGEX) systemcall.C \
|
||||
systemcall.C \
|
||||
systemcall.h \
|
||||
tempname.C \
|
||||
textutils.h \
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include "filetools.h"
|
||||
#include "LSubstring.h"
|
||||
#include "frontends/Alert.h"
|
||||
#include "FileInfo.h"
|
||||
#include "support/path.h" // I know it's OS/2 specific (SMiyata)
|
||||
|
@ -14,17 +14,18 @@
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "LString.h"
|
||||
#include "lstrings.h"
|
||||
#include "LAssert.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "LString.h"
|
||||
#include "lstrings.h"
|
||||
#include "LRegex.h"
|
||||
#include "LAssert.h"
|
||||
#include "debug.h"
|
||||
|
||||
using std::count;
|
||||
using std::transform;
|
||||
using std::vector;
|
||||
@ -476,8 +477,8 @@ bool regexMatch(string const & a, string const & pattern)
|
||||
string regex(pattern);
|
||||
regex = subst(regex, ".", "\\.");
|
||||
regex = subst(regex, "*", ".*");
|
||||
LRegex reg(regex);
|
||||
return reg.exact_match(a);
|
||||
boost::regex reg(regex);
|
||||
return boost::regex_match(a, reg);
|
||||
}
|
||||
|
||||
|
||||
@ -674,4 +675,3 @@ string const getStringFromVector(vector<string> const & vec,
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -1,505 +0,0 @@
|
||||
/* Definitions for data structures and routines for the regular
|
||||
expression library, version 0.12.
|
||||
|
||||
Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef __REGEXP_LIBRARY_H__
|
||||
#define __REGEXP_LIBRARY_H__
|
||||
|
||||
/* LyX added. */
|
||||
#ifdef HAVE_REGEX_H
|
||||
#error This header should not be used when the system has a regex.h
|
||||
#endif
|
||||
|
||||
/* POSIX says that <sys/types.h> must be included (by the caller) before
|
||||
<regex.h>. */
|
||||
|
||||
#ifdef VMS
|
||||
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
|
||||
should be there. */
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
/* LyX added. */
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* The following bits are used to determine the regexp syntax we
|
||||
recognize. The set/not-set meanings are chosen so that Emacs syntax
|
||||
remains the value 0. The bits are given in alphabetical order, and
|
||||
the definitions shifted by one from the previous bit; thus, when we
|
||||
add or remove a bit, only one other definition need change. */
|
||||
typedef unsigned reg_syntax_t;
|
||||
|
||||
/* If this bit is not set, then \ inside a bracket expression is literal.
|
||||
If set, then such a \ quotes the following character. */
|
||||
#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
|
||||
|
||||
/* If this bit is not set, then + and ? are operators, and \+ and \? are
|
||||
literals.
|
||||
If set, then \+ and \? are operators and + and ? are literals. */
|
||||
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
|
||||
|
||||
/* If this bit is set, then character classes are supported. They are:
|
||||
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
|
||||
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
|
||||
If not set, then character classes are not supported. */
|
||||
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
|
||||
|
||||
/* If this bit is set, then ^ and $ are always anchors (outside bracket
|
||||
expressions, of course).
|
||||
If this bit is not set, then it depends:
|
||||
^ is an anchor if it is at the beginning of a regular
|
||||
expression or after an open-group or an alternation operator;
|
||||
$ is an anchor if it is at the end of a regular expression, or
|
||||
before a close-group or an alternation operator.
|
||||
|
||||
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
|
||||
POSIX draft 11.2 says that * etc. in leading positions is undefined.
|
||||
We already implemented a previous draft which made those constructs
|
||||
invalid, though, so we haven't changed the code back. */
|
||||
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
|
||||
|
||||
/* If this bit is set, then special characters are always special
|
||||
regardless of where they are in the pattern.
|
||||
If this bit is not set, then special characters are special only in
|
||||
some contexts; otherwise they are ordinary. Specifically,
|
||||
* + ? and intervals are only special when not after the beginning,
|
||||
open-group, or alternation operator. */
|
||||
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
|
||||
|
||||
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
|
||||
immediately after an alternation or begin-group operator. */
|
||||
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
|
||||
|
||||
/* If this bit is set, then . matches newline.
|
||||
If not set, then it doesn't. */
|
||||
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
|
||||
|
||||
/* If this bit is set, then . doesn't match NUL.
|
||||
If not set, then it does. */
|
||||
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
|
||||
|
||||
/* If this bit is set, nonmatching lists [^...] do not match newline.
|
||||
If not set, they do. */
|
||||
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
|
||||
|
||||
/* If this bit is set, either \{...\} or {...} defines an
|
||||
interval, depending on RE_NO_BK_BRACES.
|
||||
If not set, \{, \}, {, and } are literals. */
|
||||
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
|
||||
|
||||
/* If this bit is set, +, ? and | aren't recognized as operators.
|
||||
If not set, they are. */
|
||||
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
|
||||
|
||||
/* If this bit is set, newline is an alternation operator.
|
||||
If not set, newline is literal. */
|
||||
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
|
||||
|
||||
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
|
||||
are literals.
|
||||
If not set, then `\{...\}' defines an interval. */
|
||||
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
|
||||
|
||||
/* If this bit is set, (...) defines a group, and \( and \) are literals.
|
||||
If not set, \(...\) defines a group, and ( and ) are literals. */
|
||||
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
|
||||
|
||||
/* If this bit is set, then \<digit> matches <digit>.
|
||||
If not set, then \<digit> is a back-reference. */
|
||||
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
|
||||
|
||||
/* If this bit is set, then | is an alternation operator, and \| is literal.
|
||||
If not set, then \| is an alternation operator, and | is literal. */
|
||||
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
|
||||
|
||||
/* If this bit is set, then an ending range point collating higher
|
||||
than the starting range point, as in [z-a], is invalid.
|
||||
If not set, then when ending range point collates higher than the
|
||||
starting range point, the range is ignored. */
|
||||
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
|
||||
|
||||
/* If this bit is set, then an unmatched ) is ordinary.
|
||||
If not set, then an unmatched ) is invalid. */
|
||||
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
|
||||
|
||||
/* This global variable defines the particular regexp syntax to use (for
|
||||
some interfaces). When a regexp is compiled, the syntax used is
|
||||
stored in the pattern buffer, so changing this does not affect
|
||||
already-compiled regexps. */
|
||||
extern reg_syntax_t re_syntax_options;
|
||||
|
||||
/* Define combinations of the above bits for the standard possibilities.
|
||||
(The [[[ comments delimit what gets put into the Texinfo file, so
|
||||
don't delete them!) */
|
||||
/* [[[begin syntaxes]]] */
|
||||
#define RE_SYNTAX_EMACS 0
|
||||
|
||||
#define RE_SYNTAX_AWK \
|
||||
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
|
||||
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
||||
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
|
||||
| RE_UNMATCHED_RIGHT_PAREN_ORD)
|
||||
|
||||
#define RE_SYNTAX_POSIX_AWK \
|
||||
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
|
||||
|
||||
#define RE_SYNTAX_GREP \
|
||||
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
|
||||
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
|
||||
| RE_NEWLINE_ALT)
|
||||
|
||||
#define RE_SYNTAX_EGREP \
|
||||
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
|
||||
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
|
||||
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \
|
||||
| RE_NO_BK_VBAR)
|
||||
|
||||
#define RE_SYNTAX_POSIX_EGREP \
|
||||
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
|
||||
|
||||
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
|
||||
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
|
||||
|
||||
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
|
||||
|
||||
/* Syntax bits common to both basic and extended POSIX regex syntax. */
|
||||
#define _RE_SYNTAX_POSIX_COMMON \
|
||||
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
|
||||
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
|
||||
|
||||
#define RE_SYNTAX_POSIX_BASIC \
|
||||
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
|
||||
|
||||
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
||||
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
||||
isn't minimal, since other operators, such as \`, aren't disabled. */
|
||||
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
|
||||
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
|
||||
|
||||
#define RE_SYNTAX_POSIX_EXTENDED \
|
||||
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
||||
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
|
||||
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \
|
||||
| RE_UNMATCHED_RIGHT_PAREN_ORD)
|
||||
|
||||
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
|
||||
replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
|
||||
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
|
||||
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
||||
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
|
||||
| RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
||||
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
||||
/* [[[end syntaxes]]] */
|
||||
|
||||
/* Maximum number of duplicates an interval can allow. Some systems
|
||||
(erroneously) define this in other header files, but we want our
|
||||
value, so remove any previous define. */
|
||||
#ifdef RE_DUP_MAX
|
||||
#undef RE_DUP_MAX
|
||||
#endif
|
||||
#define RE_DUP_MAX ((1 << 15) - 1)
|
||||
|
||||
|
||||
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
|
||||
|
||||
/* If this bit is set, then use extended regular expression syntax.
|
||||
If not set, then use basic regular expression syntax. */
|
||||
#define REG_EXTENDED 1
|
||||
|
||||
/* If this bit is set, then ignore case when matching.
|
||||
If not set, then case is significant. */
|
||||
#define REG_ICASE (REG_EXTENDED << 1)
|
||||
|
||||
/* If this bit is set, then anchors do not match at newline
|
||||
characters in the string.
|
||||
If not set, then anchors do match at newlines. */
|
||||
#define REG_NEWLINE (REG_ICASE << 1)
|
||||
|
||||
/* If this bit is set, then report only success or fail in regexec.
|
||||
If not set, then returns differ between not matching and errors. */
|
||||
#define REG_NOSUB (REG_NEWLINE << 1)
|
||||
|
||||
|
||||
/* POSIX `eflags' bits (i.e., information for regexec). */
|
||||
|
||||
/* If this bit is set, then the beginning-of-line operator doesn't match
|
||||
the beginning of the string (presumably because it's not the
|
||||
beginning of a line).
|
||||
If not set, then the beginning-of-line operator does match the
|
||||
beginning of the string. */
|
||||
#define REG_NOTBOL 1
|
||||
|
||||
/* Like REG_NOTBOL, except for the end-of-line. */
|
||||
#define REG_NOTEOL (1 << 1)
|
||||
|
||||
|
||||
/* If any error codes are removed, changed, or added, update the
|
||||
`re_error_msg' table in regex.c. */
|
||||
typedef enum
|
||||
{
|
||||
REG_NOERROR = 0, /* Success. */
|
||||
REG_NOMATCH, /* Didn't find a match (for regexec). */
|
||||
|
||||
/* POSIX regcomp return error codes. (In the order listed in the
|
||||
standard.) */
|
||||
REG_BADPAT, /* Invalid pattern. */
|
||||
REG_ECOLLATE, /* Not implemented. */
|
||||
REG_ECTYPE, /* Invalid character class name. */
|
||||
REG_EESCAPE, /* Trailing backslash. */
|
||||
REG_ESUBREG, /* Invalid back reference. */
|
||||
REG_EBRACK, /* Unmatched left bracket. */
|
||||
REG_EPAREN, /* Parenthesis imbalance. */
|
||||
REG_EBRACE, /* Unmatched \{. */
|
||||
REG_BADBR, /* Invalid contents of \{\}. */
|
||||
REG_ERANGE, /* Invalid range end. */
|
||||
REG_ESPACE, /* Ran out of memory. */
|
||||
REG_BADRPT, /* No preceding re for repetition op. */
|
||||
|
||||
/* Error codes we've added. */
|
||||
REG_EEND, /* Premature end. */
|
||||
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
|
||||
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
|
||||
} reg_errcode_t;
|
||||
|
||||
/* This data structure represents a compiled pattern. Before calling
|
||||
the pattern compiler, the fields `buffer', `allocated', `fastmap',
|
||||
`translate', and `no_sub' can be set. After the pattern has been
|
||||
compiled, the `re_nsub' field is available. All other fields are
|
||||
private to the regex routines. */
|
||||
|
||||
struct re_pattern_buffer
|
||||
{
|
||||
/* [[[begin pattern_buffer]]] */
|
||||
/* Space that holds the compiled pattern. It is declared as
|
||||
`unsigned char *' because its elements are
|
||||
sometimes used as array indexes. */
|
||||
unsigned char *buffer;
|
||||
|
||||
/* Number of bytes to which `buffer' points. */
|
||||
unsigned long allocated;
|
||||
|
||||
/* Number of bytes actually used in `buffer'. */
|
||||
unsigned long used;
|
||||
|
||||
/* Syntax setting with which the pattern was compiled. */
|
||||
reg_syntax_t syntax;
|
||||
|
||||
/* Pointer to a fastmap, if any, otherwise zero. re_search uses
|
||||
the fastmap, if there is one, to skip over impossible
|
||||
starting points for matches. */
|
||||
char *fastmap;
|
||||
|
||||
/* Either a translate table to apply to all characters before
|
||||
comparing them, or zero for no translation. The translation
|
||||
is applied to a pattern when it is compiled and to a string
|
||||
when it is matched. */
|
||||
char *translate;
|
||||
|
||||
/* Number of subexpressions found by the compiler. */
|
||||
size_t re_nsub;
|
||||
|
||||
/* Zero if this pattern cannot match the empty string, one else.
|
||||
Well, in truth it's used only in `re_search_2', to see
|
||||
whether or not we should use the fastmap, so we don't set
|
||||
this absolutely perfectly; see `re_compile_fastmap' (the
|
||||
`duplicate' case). */
|
||||
unsigned can_be_null : 1;
|
||||
|
||||
/* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
||||
for `max (RE_NREGS, re_nsub + 1)' groups.
|
||||
If REGS_REALLOCATE, reallocate space if necessary.
|
||||
If REGS_FIXED, use what's there. */
|
||||
#define REGS_UNALLOCATED 0
|
||||
#define REGS_REALLOCATE 1
|
||||
#define REGS_FIXED 2
|
||||
unsigned regs_allocated : 2;
|
||||
|
||||
/* Set to zero when `regex_compile' compiles a pattern; set to one
|
||||
by `re_compile_fastmap' if it updates the fastmap. */
|
||||
unsigned fastmap_accurate : 1;
|
||||
|
||||
/* If set, `re_match_2' does not return information about
|
||||
subexpressions. */
|
||||
unsigned no_sub : 1;
|
||||
|
||||
/* If set, a beginning-of-line anchor doesn't match at the
|
||||
beginning of the string. */
|
||||
unsigned not_bol : 1;
|
||||
|
||||
/* Similarly for an end-of-line anchor. */
|
||||
unsigned not_eol : 1;
|
||||
|
||||
/* If true, an anchor at a newline matches. */
|
||||
unsigned newline_anchor : 1;
|
||||
|
||||
/* [[[end pattern_buffer]]] */
|
||||
};
|
||||
|
||||
typedef struct re_pattern_buffer regex_t;
|
||||
|
||||
|
||||
/* search.c (search_buffer) in Emacs needs this one opcode value. It is
|
||||
defined both in `regex.c' and here. */
|
||||
#define RE_EXACTN_VALUE 1
|
||||
|
||||
/* Type for byte offsets within the string. POSIX mandates this. */
|
||||
typedef int regoff_t;
|
||||
|
||||
|
||||
/* This is the structure we store register match data in. See
|
||||
regex.texinfo for a full description of what registers match. */
|
||||
struct re_registers
|
||||
{
|
||||
unsigned num_regs;
|
||||
regoff_t *start;
|
||||
regoff_t *end;
|
||||
};
|
||||
|
||||
|
||||
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
|
||||
`re_match_2' returns information about at least this many registers
|
||||
the first time a `regs' structure is passed. */
|
||||
#ifndef RE_NREGS
|
||||
#define RE_NREGS 30
|
||||
#endif
|
||||
|
||||
|
||||
/* POSIX specification for registers. Aside from the different names than
|
||||
`re_registers', POSIX uses an array of structures, instead of a
|
||||
structure of arrays. */
|
||||
typedef struct
|
||||
{
|
||||
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
|
||||
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
|
||||
} regmatch_t;
|
||||
|
||||
/* Declarations for routines. */
|
||||
|
||||
/* To avoid duplicating every routine declaration -- once with a
|
||||
prototype (if we are ANSI), and once without (if we aren't) -- we
|
||||
use the following macro to declare argument types. This
|
||||
unfortunately clutters up the declarations a bit, but I think it's
|
||||
worth it. */
|
||||
|
||||
#if __STDC__
|
||||
|
||||
#define _RE_ARGS(args) args
|
||||
|
||||
#else /* not __STDC__ */
|
||||
|
||||
#define _RE_ARGS(args) ()
|
||||
|
||||
#endif /* not __STDC__ */
|
||||
|
||||
/* Sets the current default syntax to SYNTAX, and return the old syntax.
|
||||
You can also simply assign to the `re_syntax_options' variable. */
|
||||
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
|
||||
|
||||
/* Compile the regular expression PATTERN, with length LENGTH
|
||||
and syntax given by the global `re_syntax_options', into the buffer
|
||||
BUFFER. Return NULL if successful, and an error string if not. */
|
||||
extern const char *re_compile_pattern
|
||||
_RE_ARGS ((const char *pattern, int length,
|
||||
struct re_pattern_buffer *buffer));
|
||||
|
||||
|
||||
/* Compile a fastmap for the compiled pattern in BUFFER; used to
|
||||
accelerate searches. Return 0 if successful and -2 if was an
|
||||
internal error. */
|
||||
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
|
||||
|
||||
|
||||
/* Search in the string STRING (with length LENGTH) for the pattern
|
||||
compiled into BUFFER. Start searching at position START, for RANGE
|
||||
characters. Return the starting position of the match, -1 for no
|
||||
match, or -2 for an internal error. Also return register
|
||||
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
||||
extern int re_search
|
||||
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
||||
int length, int start, int range, struct re_registers *regs));
|
||||
|
||||
|
||||
/* Like `re_search', but search in the concatenation of STRING1 and
|
||||
STRING2. Also, stop searching at index START + STOP. */
|
||||
extern int re_search_2
|
||||
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
||||
int length1, const char *string2, int length2,
|
||||
int start, int range, struct re_registers *regs, int stop));
|
||||
|
||||
|
||||
/* Like `re_search', but return how many characters in STRING the regexp
|
||||
in BUFFER matched, starting at position START. */
|
||||
extern int re_match
|
||||
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
||||
int length, int start, struct re_registers *regs));
|
||||
|
||||
|
||||
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
||||
extern int re_match_2
|
||||
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
||||
int length1, const char *string2, int length2,
|
||||
int start, struct re_registers *regs, int stop));
|
||||
|
||||
|
||||
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
||||
ENDS. Subsequent matches using BUFFER and REGS will use this memory
|
||||
for recording register information. STARTS and ENDS must be
|
||||
allocated with malloc, and must each be at least `NUM_REGS * sizeof
|
||||
(regoff_t)' bytes long.
|
||||
|
||||
If NUM_REGS == 0, then subsequent matches should allocate their own
|
||||
register data.
|
||||
|
||||
Unless this function is called, the first search or match using
|
||||
PATTERN_BUFFER will allocate its own register data, without
|
||||
freeing the old data. */
|
||||
extern void re_set_registers
|
||||
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
|
||||
unsigned num_regs, regoff_t *starts, regoff_t *ends));
|
||||
|
||||
/* 4.2 bsd compatibility. */
|
||||
extern char *re_comp _RE_ARGS ((const char *));
|
||||
extern int re_exec _RE_ARGS ((const char *));
|
||||
|
||||
/* POSIX compatibility. */
|
||||
extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
|
||||
extern int regexec
|
||||
_RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
|
||||
regmatch_t pmatch[], int eflags));
|
||||
extern size_t regerror
|
||||
_RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
|
||||
size_t errbuf_size));
|
||||
extern void regfree _RE_ARGS ((regex_t *preg));
|
||||
|
||||
/* LyX added. */
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* not __REGEXP_LIBRARY_H__ */
|
||||
|
||||
/*
|
||||
Local variables:
|
||||
make-backup-files: t
|
||||
version-control: t
|
||||
trim-versions-without-asking: nil
|
||||
End:
|
||||
*/
|
4949
src/support/regex.c
4949
src/support/regex.c
File diff suppressed because it is too large
Load Diff
@ -12,18 +12,21 @@
|
||||
#include "lyxfunc.h"
|
||||
|
||||
#include "support/FileInfo.h"
|
||||
#include "support/LRegex.h"
|
||||
#include "support/LSubstring.h"
|
||||
#include "support/path.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/systemcall.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
using std::endl;
|
||||
using std::ifstream;
|
||||
using std::getline;
|
||||
using boost::regex;
|
||||
using boost::regex_match;
|
||||
using boost::smatch;
|
||||
|
||||
int VCS::doVCCommand(string const & cmd, string const & path)
|
||||
{
|
||||
@ -240,18 +243,18 @@ void CVS::scanMaster()
|
||||
string tmpf = "/" + OnlyFilename(file_) + "/";
|
||||
lyxerr[Debug::LYXVC] << "\tlooking for `" << tmpf << "'" << endl;
|
||||
string line;
|
||||
LRegex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
|
||||
regex reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
|
||||
while (getline(ifs, line)) {
|
||||
lyxerr[Debug::LYXVC] << "\t line: " << line << endl;
|
||||
if (contains(line, tmpf)) {
|
||||
// Ok extract the fields.
|
||||
LRegex::SubMatches const & sm = reg.exec(line);
|
||||
smatch sm;
|
||||
regex_match(line, sm, reg);
|
||||
|
||||
//sm[0]; // whole matched string
|
||||
//sm[1]; // filename
|
||||
version_ = LSubstring(line, sm[2].first,
|
||||
sm[2].second);
|
||||
string file_date = LSubstring(line, sm[3].first,
|
||||
sm[3].second);
|
||||
version_ = sm[2];
|
||||
string file_date = sm[3];
|
||||
//sm[4]; // options
|
||||
//sm[5]; // tag or tagdate
|
||||
FileInfo fi(file_);
|
||||
|
Loading…
Reference in New Issue
Block a user