forked from boostorg/regex
Initial boost-regex++ release
[SVN r7845]
This commit is contained in:
64
demo/c_compiler_checks/posix_api_compiler_check.c
Normal file
64
demo/c_compiler_checks/posix_api_compiler_check.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE posix_api_compiler_check.c
|
||||
* VERSION 3.01
|
||||
* DESCRIPTION: Verify that POSIX API calls compile: note this is a compile
|
||||
* time check only.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <boost/regex.h>
|
||||
|
||||
const char* expression = "^";
|
||||
const char* text = "\n ";
|
||||
regmatch_t matches[1];
|
||||
int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
|
||||
REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS |
|
||||
REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
regex_t re;
|
||||
int result;
|
||||
result = regcomp(&re, expression, REG_AWK);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
return result;
|
||||
}
|
||||
assert(re.re_nsub == 0);
|
||||
matches[0].rm_so = 0;
|
||||
matches[0].rm_eo = strlen(text);
|
||||
result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
printf(buf);
|
||||
regfree(&re);
|
||||
return result;
|
||||
}
|
||||
assert(matches[0].rm_so == matches[0].rm_eo == 1);
|
||||
regfree(&re);
|
||||
return 0;
|
||||
}
|
67
demo/c_compiler_checks/wide_posix_api_compiler_check.c
Normal file
67
demo/c_compiler_checks/wide_posix_api_compiler_check.c
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE wide_posix_api_compiler_check.c
|
||||
* VERSION 3.01
|
||||
* DESCRIPTION: Verify that POSIX API calls compile: note this is a compile
|
||||
* time check only.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
#define UNICODE
|
||||
#include <boost/regex.h>
|
||||
|
||||
const wchar_t* expression = L"^";
|
||||
const wchar_t* text = L"\n ";
|
||||
regmatch_t matches[1];
|
||||
int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
|
||||
REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS |
|
||||
REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
regex_t re;
|
||||
int result;
|
||||
result = regcomp(&re, expression, REG_AWK);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
wchar_t buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
wprintf(buf);
|
||||
return result;
|
||||
}
|
||||
assert(re.re_nsub == 0);
|
||||
matches[0].rm_so = 0;
|
||||
matches[0].rm_eo = wcslen(text);
|
||||
result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
|
||||
if(result > REG_NOERROR)
|
||||
{
|
||||
wchar_t buf[256];
|
||||
regerror(result, &re, buf, sizeof(buf));
|
||||
wprintf(buf);
|
||||
regfree(&re);
|
||||
return result;
|
||||
}
|
||||
assert(matches[0].rm_so == matches[0].rm_eo == 1);
|
||||
regfree(&re);
|
||||
return 0;
|
||||
}
|
||||
|
49
demo/jgrep/bc55.mak
Normal file
49
demo/jgrep/bc55.mak
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
# very basic makefile for jgrep.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
LIBPATH=..\..\lib\bcb5
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
COMPOPTS= -O2 -tWM- -DSTRICT; -I$(BCROOT)\include;../../../../; -D_NO_VCL
|
||||
|
||||
|
||||
|
||||
jgrep.exe : jgrep.obj main.obj
|
||||
$(BCC32) $(COMPOPTS) -e$@ -L$(LIBPATH) main.obj jgrep.obj
|
||||
|
||||
jgrep.obj : jgrep.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ jgrep.cpp
|
||||
|
|
||||
|
||||
main.obj : main.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ main.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
49
demo/jgrep/bcb4.mak
Normal file
49
demo/jgrep/bcb4.mak
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
# very basic makefile for jgrep.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
LIBPATH="..\..\lib\bcb4"
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
COMPOPTS= -O2 -tWM- -DSTRICT; -I$(BCROOT)\include;../../../../; -D_NO_VCL
|
||||
|
||||
|
||||
|
||||
jgrep.exe : jgrep.obj main.obj
|
||||
$(BCC32) @&&|
|
||||
$(COMPOPTS) -e$@ -L$(LIBPATH) main.obj jgrep.obj
|
||||
|
|
||||
|
||||
jgrep.obj : jgrep.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ jgrep.cpp
|
||||
|
|
||||
|
||||
main.obj : main.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ main.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
47
demo/jgrep/bcb5.mak
Normal file
47
demo/jgrep/bcb5.mak
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
# very basic makefile for jgrep.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
LIBPATH=../../lib/bcb5
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
COMPOPTS= -O2 -tWM- -DSTRICT; -I$(BCROOT)\include;../../../../; -D_NO_VCL
|
||||
|
||||
|
||||
|
||||
jgrep.exe : jgrep.obj main.obj
|
||||
$(BCC32) $(COMPOPTS) -e$@ -L..\..\lib\bcb5 main.obj jgrep.obj
|
||||
|
||||
jgrep.obj : jgrep.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ jgrep.cpp
|
||||
|
|
||||
|
||||
main.obj : main.cpp
|
||||
$(BCC32) -c @&&|
|
||||
$(COMPOPTS) -o$@ main.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
demo/jgrep/gcc.mak
Normal file
27
demo/jgrep/gcc.mak
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
# very basic makefile for jgrep
|
||||
#
|
||||
# GNU compiler g++
|
||||
#
|
||||
CXX= -O2 -I../../../../ -I./
|
||||
|
||||
jgrep : jgrep.cpp main.cpp
|
||||
g++ -ojgrep $(CXX) jgrep.cpp main.cpp -L../../lib/gcc -lregex++
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
126
demo/jgrep/jgrep.cpp
Normal file
126
demo/jgrep/jgrep.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* FILE jgrep.cpp
|
||||
* VERSION 3.01
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <boost/regex.hpp>
|
||||
#ifdef JM_OLD_IOSTREAM
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
#endif
|
||||
#pragma hrdstop
|
||||
|
||||
#include <boost/re_detail/fileiter.hpp>
|
||||
|
||||
#include "jgrep.h"
|
||||
|
||||
|
||||
//
|
||||
// class ogrep_predicate
|
||||
// outputs the results of regex_grep to screen:
|
||||
template <class iterator, class Allocator >
|
||||
class ogrep_predicate
|
||||
{
|
||||
unsigned int& lines;
|
||||
const char* filename;
|
||||
unsigned int last_line;
|
||||
iterator end_of_storage;
|
||||
public:
|
||||
ogrep_predicate(unsigned int& i, const char* p, iterator e) : lines(i), filename(p), last_line(-1), end_of_storage(e) {}
|
||||
ogrep_predicate(const ogrep_predicate& o) : lines(o.lines), filename(o.filename), last_line(o.last_line), end_of_storage(o.end_of_storage) {}
|
||||
bool operator () (const boost::match_results<iterator, Allocator>& i);
|
||||
};
|
||||
|
||||
// ideally we'd ignor the allocator type and use a template member function
|
||||
// to deel with the allocator type passed to regex_grep, unfortunately most
|
||||
// compilers don't support this feature yet, so we'll have to be sure that
|
||||
// the allocator passed to instances of this class match that used in our
|
||||
// regular expression classes.
|
||||
|
||||
template <class iterator, class Allocator>
|
||||
bool ogrep_predicate<iterator, Allocator>::operator()(const boost::match_results<iterator, Allocator>& i)
|
||||
{
|
||||
if(last_line == (unsigned int)-1)
|
||||
cout << "File " << filename << ":" << endl;
|
||||
if(last_line != i.line())
|
||||
{
|
||||
++lines;
|
||||
last_line = i.line();
|
||||
if(count_only == 0)
|
||||
{
|
||||
if(show_lines)
|
||||
cout << i.line() << "\t";
|
||||
iterator ptr = i.line_start();
|
||||
while((ptr != end_of_storage) && (*ptr != '\n'))++ptr;
|
||||
iterator pos = i.line_start();
|
||||
while(pos != ptr)
|
||||
{
|
||||
cout.put(*pos);
|
||||
++pos;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void process_grep(const char* file)
|
||||
{
|
||||
using namespace boost;
|
||||
mapfile f(file);
|
||||
unsigned int count = 0;
|
||||
ogrep_predicate<mapfile::iterator, allocator_type> oi(count, file, f.end());
|
||||
if(files_only)
|
||||
{
|
||||
bool ok;
|
||||
boost::match_results<mapfile::iterator, allocator_type> m;
|
||||
ok = regex_search(f.begin(), f.end(), m, e, match_not_dot_newline | match_not_dot_null);
|
||||
if(ok)
|
||||
cout << "File " << file << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
regex_grep(oi, f.begin(), f.end(), e, match_not_dot_newline | match_not_dot_null);
|
||||
if(count)
|
||||
{
|
||||
if(verbose || count_only)
|
||||
{
|
||||
cout << count << " lines match" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(verbose)
|
||||
{
|
||||
cout << "File " << file << "(" << f.size() << "bytes):" << endl << "0 lines match" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
53
demo/jgrep/jgrep.h
Normal file
53
demo/jgrep/jgrep.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* FILE jgrep.h
|
||||
* VERSION 3.01
|
||||
*/
|
||||
|
||||
#ifndef _JGREP_H
|
||||
#define _JGREP_H
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// case sensitive reg_expression determines our allocator type:
|
||||
typedef boost::reg_expression<char> re_type;
|
||||
typedef re_type::allocator_type allocator_type;
|
||||
|
||||
// now declare static (global) data, including an allocator
|
||||
// instance which we'll pass to all instances that require an allocator.
|
||||
|
||||
extern allocator_type a;
|
||||
|
||||
extern re_type e;
|
||||
|
||||
// flags for output:
|
||||
|
||||
extern bool use_case;
|
||||
extern bool show_lines;
|
||||
extern bool count_only;
|
||||
extern bool files_only;
|
||||
extern bool recurse;
|
||||
extern bool regularexs;
|
||||
extern bool words_only;
|
||||
extern bool verbose;
|
||||
|
||||
void process_grep(const char* file);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
284
demo/jgrep/main.cpp
Normal file
284
demo/jgrep/main.cpp
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* FILE main.cpp
|
||||
* VERSION 3.01
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <boost/regex.hpp>
|
||||
#ifdef JM_OLD_IOSTREAM
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
#endif
|
||||
#pragma hrdstop
|
||||
|
||||
#include <boost/re_detail/fileiter.hpp>
|
||||
#include "jgrep.h"
|
||||
|
||||
#ifndef JM_ALGO_INCLUDED
|
||||
// HP and SGI STL's use <algo.h> instead
|
||||
// this will have been pulled in by <jm_cfg.h>
|
||||
// for std::distance
|
||||
#include <algorithm>
|
||||
#endif
|
||||
|
||||
allocator_type a;
|
||||
|
||||
re_type e(a);
|
||||
//rei_type ei(a);
|
||||
|
||||
// flags for output:
|
||||
|
||||
bool use_case = true;
|
||||
bool show_lines = false;
|
||||
bool count_only = false;
|
||||
bool files_only = false;
|
||||
bool recurse = false;
|
||||
bool regularexs = true;
|
||||
bool words_only = false;
|
||||
bool verbose = false;
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
cout <<
|
||||
"jgrep version 0.95\n"
|
||||
"usage: jgrep [-options] expression file [files...]\n"
|
||||
"\n"
|
||||
"options can be one of the following:\n"
|
||||
"\n"
|
||||
"-c prints a count of the number of matching lines only\n"
|
||||
"-d recurses through subdirectories for matching files\n"
|
||||
"-i causes case to be ignored when matching\n"
|
||||
"-l lists the files which contain a match only\n"
|
||||
"-n displays the line numbers of matches\n"
|
||||
"-r- causes the expression to be interpreted as a literal string and not\n"
|
||||
" as a regular expression\n"
|
||||
"-w searches for matches that are whole words only\n"
|
||||
"-z verbose mode\n"
|
||||
"\n"
|
||||
"expression: a regular expression, or a literal string if -r- is specified\n"
|
||||
"\n"
|
||||
"files: one or more files to search, the names can contain the wildcard\n"
|
||||
" characters ? and *\n" << endl;
|
||||
|
||||
}
|
||||
|
||||
void parse_switch(const char* flag)
|
||||
{
|
||||
++flag;
|
||||
while(*flag)
|
||||
{
|
||||
switch(*flag)
|
||||
{
|
||||
case '-':
|
||||
switch(*(flag-1))
|
||||
{
|
||||
case 'c':
|
||||
count_only = false;
|
||||
break;
|
||||
case 'd':
|
||||
recurse = false;
|
||||
break;
|
||||
case 'i':
|
||||
use_case = false;
|
||||
break;
|
||||
case 'l':
|
||||
files_only = false;
|
||||
break;
|
||||
case 'n':
|
||||
show_lines = false;
|
||||
break;
|
||||
case 'r':
|
||||
regularexs = false;
|
||||
break;
|
||||
case 'w':
|
||||
words_only = false;
|
||||
break;
|
||||
case 'z':
|
||||
verbose = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Undefined option -";
|
||||
cout.put(*flag);
|
||||
cout << endl;
|
||||
}
|
||||
// turn off prev character:
|
||||
break;
|
||||
case 'c':
|
||||
count_only = true;
|
||||
break;
|
||||
case 'd':
|
||||
recurse = true;
|
||||
break;
|
||||
case 'i':
|
||||
use_case = false;
|
||||
break;
|
||||
case 'l':
|
||||
files_only = true;
|
||||
break;
|
||||
case 'n':
|
||||
show_lines = true;
|
||||
break;
|
||||
case 'r':
|
||||
regularexs = true;
|
||||
break;
|
||||
case 'w':
|
||||
words_only = true;
|
||||
break;
|
||||
case 'z':
|
||||
verbose = true;
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
exit(0);
|
||||
case '+':
|
||||
break;
|
||||
default:
|
||||
cout << "Undefined option -";
|
||||
cout.put(*flag);
|
||||
cout << endl;
|
||||
}
|
||||
++flag;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleFile(const char* wild)
|
||||
{
|
||||
using namespace boost;
|
||||
jm_trace("Handling file " << wild);
|
||||
file_iterator end;
|
||||
file_iterator start(wild);
|
||||
|
||||
if(recurse)
|
||||
{
|
||||
// go through sub directories:
|
||||
char buf[MAX_PATH];
|
||||
std::strcpy(buf, start.root());
|
||||
int rootlen = strlen(buf);
|
||||
if(*buf == 0)
|
||||
{
|
||||
std::strcpy(buf, ".");
|
||||
std::strcat(buf, directory_iterator::separator());
|
||||
std::strcat(buf, "*");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::strcat(buf, directory_iterator::separator());
|
||||
std::strcat(buf, "*");
|
||||
}
|
||||
jm_trace("Enumerating directories: " << buf);
|
||||
directory_iterator dstart(buf);
|
||||
directory_iterator dend;
|
||||
|
||||
// now get the file mask bit of "wild":
|
||||
const char* ptr = wild + rootlen;
|
||||
if(*ptr) ++ptr;
|
||||
jm_trace("File mask part is: " << ptr);
|
||||
|
||||
while(dstart != dend)
|
||||
{
|
||||
std::sprintf(buf, "%s%s%s", dstart.path(), directory_iterator::separator(), ptr);
|
||||
HandleFile(buf);
|
||||
++dstart;
|
||||
}
|
||||
}
|
||||
std::for_each(start, end, process_grep);
|
||||
}
|
||||
|
||||
int done = 0;
|
||||
|
||||
void HandleArg(const char* arg)
|
||||
{
|
||||
using namespace boost;
|
||||
jm_trace("Handling argument: " << arg);
|
||||
if(*arg == '-')
|
||||
{
|
||||
parse_switch(arg);
|
||||
return;
|
||||
}
|
||||
if(done == 0)
|
||||
{
|
||||
// parse regular expression
|
||||
if(regularexs)
|
||||
{
|
||||
if(words_only == 0)
|
||||
{
|
||||
e.set_expression(arg, use_case ? regbase::normal : regbase::normal | regbase::icase);
|
||||
//ei.set_expression(arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
char* buf = new char[std::strlen(arg) + 8];
|
||||
std::sprintf(buf, "\\<%s\\>", arg);
|
||||
e.set_expression(buf, use_case ? regbase::normal : regbase::normal | regbase::icase);
|
||||
//ei.set_expression(buf);
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we need to convert text to literal:
|
||||
int len2 = std::strlen(arg);
|
||||
int len = len2 * 5 + 6;
|
||||
char buf[8];
|
||||
char* buf2 = new char[len];
|
||||
*buf2 = 0;
|
||||
if(words_only)
|
||||
std::strcpy(buf2, "\\<");
|
||||
for(int j = 0; j < len2; ++j)
|
||||
{
|
||||
std::sprintf(buf, "\\0%o", int(arg[j]));
|
||||
std::strcat(buf2, buf);
|
||||
}
|
||||
if(words_only)
|
||||
std::strcat(buf2, "\\>");
|
||||
e.set_expression(buf2, use_case ? regbase::normal : regbase::normal | regbase::icase);
|
||||
//ei.set_expression(buf2);
|
||||
delete[] buf2;
|
||||
}
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
// if we get to here we have one or more file names to process:
|
||||
++done;
|
||||
HandleFile(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
for(int i = 1; i < argc; ++i)
|
||||
HandleArg(argv[i]);
|
||||
if(done < 2)
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
41
demo/jgrep/makefile.in
Normal file
41
demo/jgrep/makefile.in
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
# very basic makefile for jgrep
|
||||
#
|
||||
|
||||
CXX=@CXX@
|
||||
CXXFLAGS=@CXXFLAGS@
|
||||
LIBS=@LIBS@
|
||||
EXE=@ac_exe_ext@
|
||||
OBJ=@ac_obj_ext@
|
||||
|
||||
LIBDEP=../../lib/libregex++.a ../../../../boost/re_detail/regex_options.hpp ../../../../boost/re_detail/regex_config.hpp
|
||||
|
||||
jgrep$(EXE) : jgrep$(OBJ) main$(OBJ)
|
||||
$(CXX) -o jgrep$(EXE) jgrep$(OBJ) main$(OBJ) -L../../lib -lregex++ $(LIBS)
|
||||
|
||||
jgrep$(OBJ) : jgrep.cpp jgrep.h $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ jgrep.cpp
|
||||
|
||||
main$(OBJ) : main.cpp jgrep.h $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ main.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
20
demo/jgrep/sunpro.mak
Normal file
20
demo/jgrep/sunpro.mak
Normal file
@ -0,0 +1,20 @@
|
||||
# Makefile for timer application
|
||||
#
|
||||
# for SUN workshop 5.0 C++ compiler
|
||||
#
|
||||
|
||||
CXX=CC
|
||||
CPP_FLAGS = -O -I../../../../ -I./
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c -o $@ $(CPP_FLAGS) $<
|
||||
|
||||
jgrep : jgrep.o main.o
|
||||
$(CXX) -o $@ $(CPP_FLAGS) jgrep.o main.o -L../../lib -lregex++
|
||||
|
||||
clean:
|
||||
rm -rf SunWS_cache
|
||||
rm -f jgrep.o jgrep main.o
|
||||
|
||||
|
||||
|
16
demo/jgrep/vc6-stlport.mak
Normal file
16
demo/jgrep/vc6-stlport.mak
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
#
|
||||
# very simple makefile for Visual C++ 6 + STLPort 4
|
||||
#
|
||||
|
||||
jgrep.exe: main.cpp jgrep.cpp jgrep.h
|
||||
cl -GX -GR -O2 -MT -I..\..\..\..\ jgrep.cpp main.cpp /link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
15
demo/jgrep/vc6.mak
Normal file
15
demo/jgrep/vc6.mak
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#
|
||||
# very simple makefile for Visual C++ 6
|
||||
#
|
||||
|
||||
jgrep.exe: main.cpp jgrep.cpp jgrep.h
|
||||
cl -GX -GR -O2 -I..\..\..\..\ jgrep.cpp main.cpp /link /LIBPATH:..\..\lib\vc6 user32.lib
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
127
demo/regress/bc55.mak
Normal file
127
demo/regress/bc55.mak
Normal file
@ -0,0 +1,127 @@
|
||||
|
||||
# very basic makefile for regress
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bcb install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
TLINK32 = $(BCROOT)\bin\ILink32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
CFLAGS= -O2 -tWC -DSTRICT; -w-inl -w-aus -w-csu -w-eff -w-rch -I$(BCROOT)\include;..\..\..\..\; -L..\..\lib\bcb5
|
||||
|
||||
all :: r1.exe r2.exe r3.exe r4.exe r5.exe r6.exe r1m.exe r2m.exe r3m.exe r4m.exe r5m.exe r6m.exe r1l.exe r2l.exe r3l.exe r4l.exe r5l.exe r6l.exe r1lm.exe r2lm.exe r3lm.exe r4lm.exe r5lm.exe r6lm.exe
|
||||
echo testing static single threaded version....
|
||||
r1 tests.txt test1252.txt
|
||||
r2 tests.txt
|
||||
r3 tests.txt
|
||||
r4 tests.txt test1252.txt
|
||||
r5 tests.txt
|
||||
r6 tests.txt
|
||||
echo testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
r2m tests.txt
|
||||
r3m tests.txt
|
||||
r4m tests.txt test1252.txt
|
||||
r5m tests.txt
|
||||
r6m tests.txt
|
||||
echo testing dll single threaded version....
|
||||
r1l tests.txt test1252.txt
|
||||
r2l tests.txt
|
||||
r3l tests.txt
|
||||
r4l tests.txt test1252.txt
|
||||
r5l tests.txt
|
||||
r6l tests.txt
|
||||
echo testing dll multi-threaded version....
|
||||
r1lm tests.txt test1252.txt
|
||||
r2lm tests.txt
|
||||
r3lm tests.txt
|
||||
r4lm tests.txt test1252.txt
|
||||
r5lm tests.txt
|
||||
r6lm tests.txt
|
||||
|
||||
|
||||
r1.exe : r1.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r1.cpp
|
||||
|
||||
r2.exe : r2.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r2.cpp
|
||||
|
||||
r3.exe : r3.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r3.cpp
|
||||
|
||||
r4.exe : r4.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r4.cpp
|
||||
|
||||
r5.exe : r5.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r5.cpp
|
||||
|
||||
r6.exe : r6.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r6.cpp
|
||||
|
||||
|
||||
r1m.exe : r1.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er1m.exe r1.cpp
|
||||
|
||||
r2m.exe : r2.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er2m.exe r2.cpp
|
||||
|
||||
r3m.exe : r3.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er3m.exe r3.cpp
|
||||
|
||||
r4m.exe : r4.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er4m.exe r4.cpp
|
||||
|
||||
r5m.exe : r5.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er5m.exe r5.cpp
|
||||
|
||||
r6m.exe : r6.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er6m.exe r6.cpp
|
||||
|
||||
|
||||
r1l.exe : r1.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er1l.exe r1.cpp
|
||||
|
||||
r2l.exe : r2.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er2l.exe r2.cpp
|
||||
|
||||
r3l.exe : r3.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er3l.exe r3.cpp
|
||||
|
||||
r4l.exe : r4.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er4l.exe r4.cpp
|
||||
|
||||
r5l.exe : r5.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er5l.exe r5.cpp
|
||||
|
||||
r6l.exe : r6.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er6l.exe r6.cpp
|
||||
|
||||
|
||||
r1lm.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er1lm.exe r1.cpp
|
||||
|
||||
r2lm.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er2lm.exe r2.cpp
|
||||
|
||||
r3lm.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er3lm.exe r3.cpp
|
||||
|
||||
r4lm.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er4lm.exe r4.cpp
|
||||
|
||||
r5lm.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er5lm.exe r5.cpp
|
||||
|
||||
r6lm.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er6lm.exe r6.cpp
|
||||
|
||||
|
||||
|
||||
|
179
demo/regress/bcb4.mak
Normal file
179
demo/regress/bcb4.mak
Normal file
@ -0,0 +1,179 @@
|
||||
|
||||
# very basic makefile for regress
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bcb install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
TLINK32 = $(BCROOT)\bin\ILink32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
CFLAGS= -O2 -tWC -DSTRICT; -w-inl -w-aus -w-csu -w-eff -w-rch -I$(BCROOT)\include;..\..\..\..\; -L..\..\lib\bcb4
|
||||
|
||||
all :: r1.exe r2.exe r3.exe r4.exe r5.exe r6.exe r1m.exe r2m.exe r3m.exe r4m.exe r5m.exe r6m.exe r1v.exe r2v.exe r3v.exe r4v.exe r5v.exe r6v.exe r1l.exe r2l.exe r3l.exe r4l.exe r5l.exe r6l.exe r1lm.exe r2lm.exe r3lm.exe r4lm.exe r5lm.exe r6lm.exe r1lv.exe r2lv.exe r3lv.exe r4lv.exe r5lv.exe r6lv.exe
|
||||
echo testing static single threaded version....
|
||||
r1 tests.txt test1252.txt
|
||||
r2 tests.txt
|
||||
r3 tests.txt
|
||||
r4 tests.txt test1252.txt
|
||||
r5 tests.txt
|
||||
r6 tests.txt
|
||||
echo testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
r2m tests.txt
|
||||
r3m tests.txt
|
||||
r4m tests.txt test1252.txt
|
||||
r5m tests.txt
|
||||
r6m tests.txt
|
||||
echo testing static VCL version....
|
||||
r1v tests.txt test1252.txt
|
||||
r2v tests.txt
|
||||
r3v tests.txt
|
||||
r4v tests.txt test1252.txt
|
||||
r5v tests.txt
|
||||
r6v tests.txt
|
||||
echo testing dll single threaded version....
|
||||
r1l tests.txt test1252.txt
|
||||
r2l tests.txt
|
||||
r3l tests.txt
|
||||
r4l tests.txt test1252.txt
|
||||
r5l tests.txt
|
||||
r6l tests.txt
|
||||
echo testing dll multi-threaded version....
|
||||
r1lm tests.txt test1252.txt
|
||||
r2lm tests.txt
|
||||
r3lm tests.txt
|
||||
r4lm tests.txt test1252.txt
|
||||
r5lm tests.txt
|
||||
r6lm tests.txt
|
||||
echo testing dll VCL version....
|
||||
r1lv tests.txt test1252.txt
|
||||
r2lv tests.txt
|
||||
r3lv tests.txt
|
||||
r4lv tests.txt test1252.txt
|
||||
r5lv tests.txt
|
||||
r6lv tests.txt
|
||||
|
||||
|
||||
r1.exe : r1.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r1.cpp
|
||||
|
||||
r2.exe : r2.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r2.cpp
|
||||
|
||||
r3.exe : r3.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r3.cpp
|
||||
|
||||
r4.exe : r4.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r4.cpp
|
||||
|
||||
r5.exe : r5.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r5.cpp
|
||||
|
||||
r6.exe : r6.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r6.cpp
|
||||
|
||||
|
||||
r1m.exe : r1.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er1m.exe r1.cpp
|
||||
|
||||
r2m.exe : r2.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er2m.exe r2.cpp
|
||||
|
||||
r3m.exe : r3.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er3m.exe r3.cpp
|
||||
|
||||
r4m.exe : r4.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er4m.exe r4.cpp
|
||||
|
||||
r5m.exe : r5.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er5m.exe r5.cpp
|
||||
|
||||
r6m.exe : r6.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er6m.exe r6.cpp
|
||||
|
||||
|
||||
r1v.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er1v.exe r1.cpp
|
||||
|
||||
r2v.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er2v.exe r2.cpp
|
||||
|
||||
r3v.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er3v.exe r3.cpp
|
||||
|
||||
r4v.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er4v.exe r4.cpp
|
||||
|
||||
r5v.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er5v.exe r5.cpp
|
||||
|
||||
r6v.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er6v.exe r6.cpp
|
||||
|
||||
|
||||
r1l.exe : r1.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er1l.exe r1.cpp
|
||||
|
||||
r2l.exe : r2.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er2l.exe r2.cpp
|
||||
|
||||
r3l.exe : r3.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er3l.exe r3.cpp
|
||||
|
||||
r4l.exe : r4.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er4l.exe r4.cpp
|
||||
|
||||
r5l.exe : r5.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er5l.exe r5.cpp
|
||||
|
||||
r6l.exe : r6.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er6l.exe r6.cpp
|
||||
|
||||
|
||||
r1lm.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er1lm.exe r1.cpp
|
||||
|
||||
r2lm.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er2lm.exe r2.cpp
|
||||
|
||||
r3lm.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er3lm.exe r3.cpp
|
||||
|
||||
r4lm.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er4lm.exe r4.cpp
|
||||
|
||||
r5lm.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er5lm.exe r5.cpp
|
||||
|
||||
r6lm.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er6lm.exe r6.cpp
|
||||
|
||||
|
||||
r1lv.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er1lv.exe r1.cpp
|
||||
|
||||
r2lv.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er2lv.exe r2.cpp
|
||||
|
||||
r3lv.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er3lv.exe r3.cpp
|
||||
|
||||
r4lv.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er4lv.exe r4.cpp
|
||||
|
||||
r5lv.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er5lv.exe r5.cpp
|
||||
|
||||
r6lv.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er6lv.exe r6.cpp
|
||||
|
||||
|
||||
|
||||
|
179
demo/regress/bcb5.mak
Normal file
179
demo/regress/bcb5.mak
Normal file
@ -0,0 +1,179 @@
|
||||
|
||||
# very basic makefile for regress
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bcb install
|
||||
#
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
TLINK32 = $(BCROOT)\bin\ILink32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
LINKOPTS= -ap -Tpe -x
|
||||
CFLAGS= -O2 -tWC -DSTRICT; -w-inl -w-aus -w-csu -w-eff -w-rch -I$(BCROOT)\include;..\..\..\..\; -L..\..\lib\bcb5
|
||||
|
||||
all :: r1.exe r2.exe r3.exe r4.exe r5.exe r6.exe r1m.exe r2m.exe r3m.exe r4m.exe r5m.exe r6m.exe r1v.exe r2v.exe r3v.exe r4v.exe r5v.exe r6v.exe r1l.exe r2l.exe r3l.exe r4l.exe r5l.exe r6l.exe r1lm.exe r2lm.exe r3lm.exe r4lm.exe r5lm.exe r6lm.exe r1lv.exe r2lv.exe r3lv.exe r4lv.exe r5lv.exe r6lv.exe
|
||||
echo testing static single threaded version....
|
||||
r1 tests.txt test1252.txt
|
||||
r2 tests.txt
|
||||
r3 tests.txt
|
||||
r4 tests.txt test1252.txt
|
||||
r5 tests.txt
|
||||
r6 tests.txt
|
||||
echo testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
r2m tests.txt
|
||||
r3m tests.txt
|
||||
r4m tests.txt test1252.txt
|
||||
r5m tests.txt
|
||||
r6m tests.txt
|
||||
echo testing static VCL version....
|
||||
r1v tests.txt test1252.txt
|
||||
r2v tests.txt
|
||||
r3v tests.txt
|
||||
r4v tests.txt test1252.txt
|
||||
r5v tests.txt
|
||||
r6v tests.txt
|
||||
echo testing dll single threaded version....
|
||||
r1l tests.txt test1252.txt
|
||||
r2l tests.txt
|
||||
r3l tests.txt
|
||||
r4l tests.txt test1252.txt
|
||||
r5l tests.txt
|
||||
r6l tests.txt
|
||||
echo testing dll multi-threaded version....
|
||||
r1lm tests.txt test1252.txt
|
||||
r2lm tests.txt
|
||||
r3lm tests.txt
|
||||
r4lm tests.txt test1252.txt
|
||||
r5lm tests.txt
|
||||
r6lm tests.txt
|
||||
echo testing dll VCL version....
|
||||
r1lv tests.txt test1252.txt
|
||||
r2lv tests.txt
|
||||
r3lv tests.txt
|
||||
r4lv tests.txt test1252.txt
|
||||
r5lv tests.txt
|
||||
r6lv tests.txt
|
||||
|
||||
|
||||
r1.exe : r1.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r1.cpp
|
||||
|
||||
r2.exe : r2.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r2.cpp
|
||||
|
||||
r3.exe : r3.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r3.cpp
|
||||
|
||||
r4.exe : r4.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r4.cpp
|
||||
|
||||
r5.exe : r5.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r5.cpp
|
||||
|
||||
r6.exe : r6.cpp
|
||||
$(BCC32) -tWM- -D_NO_VCL $(CFLAGS) r6.cpp
|
||||
|
||||
|
||||
r1m.exe : r1.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er1m.exe r1.cpp
|
||||
|
||||
r2m.exe : r2.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er2m.exe r2.cpp
|
||||
|
||||
r3m.exe : r3.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er3m.exe r3.cpp
|
||||
|
||||
r4m.exe : r4.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er4m.exe r4.cpp
|
||||
|
||||
r5m.exe : r5.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er5m.exe r5.cpp
|
||||
|
||||
r6m.exe : r6.cpp
|
||||
$(BCC32) -tWM -D_NO_VCL $(CFLAGS) -er6m.exe r6.cpp
|
||||
|
||||
|
||||
r1v.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er1v.exe r1.cpp
|
||||
|
||||
r2v.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er2v.exe r2.cpp
|
||||
|
||||
r3v.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er3v.exe r3.cpp
|
||||
|
||||
r4v.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er4v.exe r4.cpp
|
||||
|
||||
r5v.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er5v.exe r5.cpp
|
||||
|
||||
r6v.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWV $(CFLAGS) -er6v.exe r6.cpp
|
||||
|
||||
|
||||
r1l.exe : r1.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er1l.exe r1.cpp
|
||||
|
||||
r2l.exe : r2.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er2l.exe r2.cpp
|
||||
|
||||
r3l.exe : r3.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er3l.exe r3.cpp
|
||||
|
||||
r4l.exe : r4.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er4l.exe r4.cpp
|
||||
|
||||
r5l.exe : r5.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er5l.exe r5.cpp
|
||||
|
||||
r6l.exe : r6.cpp
|
||||
$(BCC32) -tWM- -tWR -D_NO_VCL $(CFLAGS) -er6l.exe r6.cpp
|
||||
|
||||
|
||||
r1lm.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er1lm.exe r1.cpp
|
||||
|
||||
r2lm.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er2lm.exe r2.cpp
|
||||
|
||||
r3lm.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er3lm.exe r3.cpp
|
||||
|
||||
r4lm.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er4lm.exe r4.cpp
|
||||
|
||||
r5lm.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er5lm.exe r5.cpp
|
||||
|
||||
r6lm.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWR -D_NO_VCL $(CFLAGS) -er6lm.exe r6.cpp
|
||||
|
||||
|
||||
r1lv.exe : r1.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er1lv.exe r1.cpp
|
||||
|
||||
r2lv.exe : r2.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er2lv.exe r2.cpp
|
||||
|
||||
r3lv.exe : r3.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er3lv.exe r3.cpp
|
||||
|
||||
r4lv.exe : r4.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er4lv.exe r4.cpp
|
||||
|
||||
r5lv.exe : r5.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er5lv.exe r5.cpp
|
||||
|
||||
r6lv.exe : r6.cpp
|
||||
$(BCC32) -tWM -tWR -tWV -tWC $(CFLAGS) -er6lv.exe r6.cpp
|
||||
|
||||
|
||||
|
||||
|
50
demo/regress/egcs.mak
Normal file
50
demo/regress/egcs.mak
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
# very basic makefile for regress.exe
|
||||
#
|
||||
# egcs compiler GCC
|
||||
#
|
||||
CXX= g++ -O2 -pedantic -Wall -I../../../../ -I./
|
||||
|
||||
total : r2.exe
|
||||
r2 tests.txt
|
||||
r5 tests.txt
|
||||
|
||||
r2.exe : r2.cpp
|
||||
$(CXX) -or2.exe r2.cpp -L../../lib -lregex++
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
50
demo/regress/gcc.mak
Normal file
50
demo/regress/gcc.mak
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
# very basic makefile for regression tests
|
||||
#
|
||||
# g++ 2.95 and greater
|
||||
#
|
||||
CXX= g++ -O2 -pedantic -Wall -I../../../../ -I./ -L../../lib/gcc
|
||||
|
||||
total : r2
|
||||
./r2 tests.txt
|
||||
|
||||
r2 : r2.cpp
|
||||
$(CXX) -o r2 r2.cpp -lregex++
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
78
demo/regress/makefile.in
Normal file
78
demo/regress/makefile.in
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
# very basic makefile for regression tests
|
||||
#
|
||||
CXX=@CXX@
|
||||
CXXFLAGS=@CXXFLAGS@
|
||||
LIBS=@LIBS@ -L../../lib -lregex++
|
||||
EXE=@ac_exe_ext@
|
||||
OBJ=@ac_obj_ext@
|
||||
|
||||
total : @ac_regress@
|
||||
|
||||
LIBDEP=../../lib/libregex++.a ../../../../boost/re_detail/regex_options.hpp ../../../../boost/re_detail/regex_config.hpp
|
||||
|
||||
r1$(EXE) :: r1$(OBJ)
|
||||
$(CXX) -o r1$(EXE) r1$(OBJ) $(LIBS)
|
||||
./r1 tests.txt test1252.txt
|
||||
|
||||
r2$(EXE) :: r2$(OBJ)
|
||||
$(CXX) -o r2$(EXE) r2$(OBJ) $(LIBS)
|
||||
./r2 tests.txt
|
||||
|
||||
r3$(EXE) :: r3$(OBJ)
|
||||
$(CXX) -o r3$(EXE) r3$(OBJ) $(LIBS)
|
||||
./r3 tests.txt
|
||||
|
||||
r4$(EXE) :: r4$(OBJ)
|
||||
$(CXX) -o r4$(EXE) r4$(OBJ) $(LIBS)
|
||||
./r4 tests.txt test1252.txt
|
||||
|
||||
r5$(EXE) :: r5$(OBJ)
|
||||
$(CXX) -o r5$(EXE) r5$(OBJ) $(LIBS)
|
||||
./r5 tests.txt
|
||||
|
||||
r6$(EXE) :: r6$(OBJ)
|
||||
$(CXX) -o r6$(EXE) r6$(OBJ) $(LIBS)
|
||||
./r6 tests.txt
|
||||
|
||||
r1$(OBJ) : parse.cpp regress.cpp tests.cpp r1.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -DSTRICT -I../../../../ -I./ r1.cpp
|
||||
|
||||
r2$(OBJ) : parse.cpp regress.cpp tests.cpp r2.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ r2.cpp
|
||||
|
||||
r3$(OBJ) : parse.cpp regress.cpp tests.cpp r3.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ r3.cpp
|
||||
|
||||
r4$(OBJ) : parse.cpp regress.cpp tests.cpp r4.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -DSTRICT -I../../../../ -I./ r4.cpp
|
||||
|
||||
r5$(OBJ) : parse.cpp regress.cpp tests.cpp r5.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ r5.cpp
|
||||
|
||||
r6$(OBJ) : parse.cpp regress.cpp tests.cpp r6.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -I../../../../ -I./ r6.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
342
demo/regress/out.txt
Normal file
342
demo/regress/out.txt
Normal file
@ -0,0 +1,342 @@
|
||||
|
||||
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
|
||||
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
|
||||
|
||||
cl /MT /D_MT -o r1m.exe -O2 -GX -GR -I..\..\..\.. r1.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r1.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r1.exe
|
||||
/out:r1m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r1.obj
|
||||
cl /MT /D_MT -O2 -GX -GR -I..\..\..\.. -o r2m.exe r2.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r2.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r2.exe
|
||||
/out:r2m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r2.obj
|
||||
cl /MT /D_MT -O2 -GX -GR -I..\..\..\.. -o r3m.exe r3.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r3.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r3.exe
|
||||
/out:r3m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r3.obj
|
||||
cl /MT /D_MT -O2 -GX -GR -I..\..\..\.. -o r4m.exe r4.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r4.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r4.exe
|
||||
/out:r4m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r4.obj
|
||||
cl /MT /D_MT -O2 -GX -GR -I..\..\..\.. -o r5m.exe r5.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r5.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r5.exe
|
||||
/out:r5m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r5.obj
|
||||
cl /MT /D_MT -O2 -GX -GR -I..\..\..\.. -o r6m.exe r6.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r6.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r6.exe
|
||||
/out:r6m.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r6.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r1l.exe r1.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r1.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r1.exe
|
||||
/out:r1l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r1.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r2l.exe r2.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r2.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r2.exe
|
||||
/out:r2l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r2.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r3l.exe r3.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r3.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r3.exe
|
||||
/out:r3l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r3.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r4l.exe r4.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r4.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r4.exe
|
||||
/out:r4l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r4.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r5l.exe r5.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r5.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r5.exe
|
||||
/out:r5l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r5.obj
|
||||
cl /MD /D_MT /D_DLL -O2 -GX -GR -I..\..\..\.. -o r6l.exe r6.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r6.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r6.exe
|
||||
/out:r6l.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r6.obj
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r1md.exe r1.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r1.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r1.exe
|
||||
/out:r1md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r1.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r2md.exe r2.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r2.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r2.exe
|
||||
/out:r2md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r2.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r3md.exe r3.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r3.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r3.exe
|
||||
/out:r3md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r3.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r4md.exe r4.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r4.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r4.exe
|
||||
/out:r4md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r4.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r5md.exe r5.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r5.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r5.exe
|
||||
/out:r5md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r5.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MTd /D_MT /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r6md.exe r6.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r6.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r6.exe
|
||||
/out:r6md.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r6.obj
|
||||
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r1lmd.exe r1.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r1.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r1.exe
|
||||
/out:r1lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r1.obj
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r2lmd.exe r2.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r2.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r2.exe
|
||||
/out:r2lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r2.obj
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r3lmd.exe r3.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r3.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r3.exe
|
||||
/out:r3lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r3.obj
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r4lmd.exe r4.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r4.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r4.exe
|
||||
/out:r4lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r4.obj
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r5lmd.exe r5.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r5.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r5.exe
|
||||
/out:r5lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r5.obj
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG -O2 -GX -GR -I..\..\..\.. -o r6lmd.exe r6.cpp -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
Microsoft (R) 32-bit C/C++ Standard Compiler Version 12.00.8168 for 80x86
|
||||
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
|
||||
|
||||
r6.cpp
|
||||
Microsoft (R) Incremental Linker Version 6.00.8447
|
||||
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
|
||||
|
||||
/out:r6.exe
|
||||
/out:r6lmd.exe
|
||||
/LIBPATH:..\..\lib\vc6-stlport
|
||||
user32.lib
|
||||
r6.obj
|
||||
echo testing static multi-threaded version....
|
||||
testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
858 lines, 625 tests completed in file tests.txt
|
||||
33 lines, 10 tests completed in file test1252.txt
|
||||
r2m tests.txt
|
||||
858 lines, 625 tests completed in file tests.txt
|
||||
r3m tests.txt
|
||||
Error in line 259 of file tests.txt
|
||||
Expression: [[:print:]]+
|
||||
Search text:
|
||||
a b
|
||||
|
||||
Flags: REG_EXTENDED | basic | escape_in_lists | char_classes | intervals | bk_refs | normal | basic | extended
|
||||
regex++ API result mismatch in sub-expression 0, found (0,5) expected (1,4)
|
||||
regex++ API result mismatch in sub-expression 0, found (0,5) expected (1,4)
|
||||
regex++ API result mismatch in sub-expression 0, found (0,5) expected (1,4)
|
||||
858 lines, 625 tests completed in file tests.txt
|
||||
NMAKE : fatal error U1077: 'd:\boost\regexpp\libs\regex\demo\regress\r3m.exe' : return code '0x1'
|
||||
Stop.
|
326
demo/regress/parse.cpp
Normal file
326
demo/regress/parse.cpp
Normal file
@ -0,0 +1,326 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* FILE parse.cpp
|
||||
* VERSION 3.01
|
||||
*
|
||||
* Input parsing functions for regress.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include "regress.h"
|
||||
|
||||
#ifndef BOOST_RE_ALGO_INCLUDED
|
||||
#include <algorithm>
|
||||
#endif
|
||||
|
||||
using namespace boost;
|
||||
|
||||
//
|
||||
// start by defining all our flag types:
|
||||
|
||||
flag_info flag_data[] = {
|
||||
{ BOOST_RE_STR("REG_BASIC"), 9, REG_BASIC, 0 },
|
||||
{ BOOST_RE_STR("REG_EXTENDED"), 12, REG_EXTENDED, 0 },
|
||||
{ BOOST_RE_STR("REG_ICASE"), 9, REG_ICASE, 0 },
|
||||
{ BOOST_RE_STR("REG_NOSUB"), 9, REG_NOSUB, 0 },
|
||||
{ BOOST_RE_STR("REG_NEWLINE"), 11, REG_NEWLINE, 0 },
|
||||
{ BOOST_RE_STR("REG_NEWLINE"), 11, REG_NEWLINE, 0 },
|
||||
{ BOOST_RE_STR("REG_NOSPEC"), 10, REG_NOSPEC, 0 },
|
||||
|
||||
{ BOOST_RE_STR("REG_NOTBOL"), 10, REG_NOTBOL, 1 },
|
||||
{ BOOST_RE_STR("REG_NOTEOL"), 10, REG_NOTEOL, 1 },
|
||||
{ BOOST_RE_STR("REG_STARTEND"), 12, REG_STARTEND, 1 },
|
||||
|
||||
{ BOOST_RE_STR("basic"), 5, regbase::basic, 2 },
|
||||
{ BOOST_RE_STR("escape_in_lists"), 15, regbase::escape_in_lists, 2 },
|
||||
{ BOOST_RE_STR("char_classes"), 12, regbase::char_classes, 2 },
|
||||
{ BOOST_RE_STR("intervals"), 9, regbase::intervals, 2 },
|
||||
{ BOOST_RE_STR("limited_ops"), 11, regbase::limited_ops, 2 },
|
||||
{ BOOST_RE_STR("newline_alt"), 11, regbase::newline_alt, 2 },
|
||||
{ BOOST_RE_STR("bk_plus_qm"), 10, regbase::bk_plus_qm, 2 },
|
||||
{ BOOST_RE_STR("bk_braces"), 9, regbase::bk_braces, 2 },
|
||||
{ BOOST_RE_STR("bk_parens"), 9, regbase::bk_parens, 2 },
|
||||
{ BOOST_RE_STR("bk_refs"), 7, regbase::bk_refs, 2 },
|
||||
{ BOOST_RE_STR("bk_vbar"), 7, regbase::bk_vbar, 2 },
|
||||
{ BOOST_RE_STR("use_except"), 10, regbase::use_except, 2 },
|
||||
{ BOOST_RE_STR("literal"), 7, regbase::literal, 2 },
|
||||
{ BOOST_RE_STR("normal"), 6, regbase::normal, 2 },
|
||||
{ BOOST_RE_STR("basic"), 5, regbase::basic, 2 },
|
||||
{ BOOST_RE_STR("extended"), 8, regbase::extended, 2 },
|
||||
|
||||
{ BOOST_RE_STR("match_default"), 13, match_default, 3 },
|
||||
{ BOOST_RE_STR("match_not_bol"), 13, match_not_bol, 3 },
|
||||
{ BOOST_RE_STR("match_not_eol"), 13, match_not_eol, 3 },
|
||||
{ BOOST_RE_STR("match_not_bob"), 13, match_not_bob, 3 },
|
||||
{ BOOST_RE_STR("match_not_eob"), 13, match_not_eob, 3 },
|
||||
{ BOOST_RE_STR("match_not_bow"), 13, match_not_bow, 3 },
|
||||
{ BOOST_RE_STR("match_not_eow"), 13, match_not_eow, 3 },
|
||||
{ BOOST_RE_STR("match_not_dot_newline"), 21, match_not_dot_newline, 3 },
|
||||
{ BOOST_RE_STR("match_not_dot_null"), 18, match_not_dot_null, 3 },
|
||||
{ BOOST_RE_STR("match_prev_avail"), 16, match_prev_avail, 3 },
|
||||
{ BOOST_RE_STR("match_any"), 9, match_any, 3 },
|
||||
{ BOOST_RE_STR("match_not_null"), 14, match_not_null, 3 },
|
||||
{ BOOST_RE_STR("match_continuous"), 16, match_continuous, 3 },
|
||||
|
||||
{ BOOST_RE_STR("format_sed"), 10, format_sed, 3 },
|
||||
{ BOOST_RE_STR("format_perl"), 11, format_perl, 3 },
|
||||
{ BOOST_RE_STR("format_no_copy"), 14, format_no_copy, 3 },
|
||||
|
||||
{ BOOST_RE_STR("REG_NO_POSIX_TEST"), 17, REG_NO_POSIX_TEST, 4 },
|
||||
{ BOOST_RE_STR("REG_UNICODE_ONLY"), 16, REG_UNICODE_ONLY, 4 },
|
||||
{ BOOST_RE_STR("REG_GREP"), 8, REG_GREP, 4 },
|
||||
{ BOOST_RE_STR("REG_MERGE"), 9, REG_MERGE, 4 },
|
||||
{ BOOST_RE_STR("REG_MERGE_COPY"), 14, REG_MERGE_COPY, 4 },
|
||||
|
||||
{ BOOST_RE_STR(""), 0, 0, 0 },
|
||||
};
|
||||
|
||||
// basically we create a simple token parser
|
||||
// using regular expressions
|
||||
|
||||
const char_t* expression_text = BOOST_RE_STR("(;.*)|") // comment
|
||||
BOOST_RE_STR("(^[[:blank:]]*-)|") // -
|
||||
BOOST_RE_STR("([^\"[:space:]][^[:space:]]*)|") // token
|
||||
BOOST_RE_STR("(\"(([^\"]|\\\\\")*)\")") // "token"
|
||||
;
|
||||
|
||||
typedef reg_expression<char_t> re_parse_t;
|
||||
typedef re_parse_t::allocator_type parse_alloc;
|
||||
typedef match_results<string_type::const_iterator, parse_alloc> parse_grep;
|
||||
typedef string_type::const_iterator parse_iterator;
|
||||
|
||||
re_parse_t parse_expression(expression_text, regbase::normal);
|
||||
|
||||
//
|
||||
// now define our grep predicate function object:
|
||||
class parse_function
|
||||
{
|
||||
int mode;
|
||||
public:
|
||||
parse_function() : mode(0) {}
|
||||
parse_function(const parse_function& o) : mode(o.mode) {}
|
||||
bool operator()(const parse_grep& i);
|
||||
};
|
||||
|
||||
bool parse_function::operator()(const parse_grep& g)
|
||||
{
|
||||
parse_iterator i, j;
|
||||
// determine what caused the match:
|
||||
if(g[1].matched)
|
||||
{
|
||||
// we have a comment:
|
||||
return true;
|
||||
}
|
||||
else if(g[2].matched)
|
||||
{
|
||||
// we have the start of a line of flags
|
||||
mode = -1;
|
||||
for(int i = 0; i < 5; ++i)
|
||||
flags[i] = 0;
|
||||
return true;
|
||||
}
|
||||
else if(g[3].matched)
|
||||
{
|
||||
// token:
|
||||
i = g[3].first;
|
||||
j = g[3].second;
|
||||
}
|
||||
else
|
||||
{
|
||||
// token delimited by ""
|
||||
i = g[5].first;
|
||||
j = g[5].second;
|
||||
}
|
||||
|
||||
// now we need to switch depending upon what mode we are in:
|
||||
switch(mode)
|
||||
{
|
||||
case -1:
|
||||
{
|
||||
// parse the flag:
|
||||
unsigned int id = 0;
|
||||
while(flag_data[id].len != 0)
|
||||
{
|
||||
if(static_cast<unsigned int>(j - i) != flag_data[id].len)
|
||||
{
|
||||
++id;
|
||||
continue;
|
||||
}
|
||||
if(std::equal(i, j, flag_data[id].name) == true)
|
||||
{
|
||||
flags[flag_data[id].id] |= flag_data[id].value;
|
||||
return true;
|
||||
}
|
||||
++id;
|
||||
}
|
||||
cout << "Warning: Unknown flag: ";
|
||||
string_type t(i, j);
|
||||
cout << t.c_str();
|
||||
cout << endl;
|
||||
return true;
|
||||
}
|
||||
case 0:
|
||||
// set the expression text:
|
||||
expression = string_type(i, j);
|
||||
do_test = true;
|
||||
break;
|
||||
case 1:
|
||||
// set the text to match:
|
||||
search_text = string_type(i, j);
|
||||
jm_trace("Initial search text: " << search_text);
|
||||
expand_escapes(search_text);
|
||||
jm_trace("Search text after escapes expanded: " << search_text);
|
||||
break;
|
||||
case 2:
|
||||
// maybe set format string:
|
||||
if(flags[4] & REG_MERGE)
|
||||
{
|
||||
format_string = string_type(i, j);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
matches[mode - 2] = to_int(i, j);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
// maybe set format result:
|
||||
if(flags[4] & REG_MERGE)
|
||||
{
|
||||
merge_string = string_type(i, j);
|
||||
expand_escapes(merge_string);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
matches[mode - 2] = to_int(i, j);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
jm_assert(mode >= 2);
|
||||
// set the relevent int value:
|
||||
matches[mode - 2] = to_int(i, j);
|
||||
}
|
||||
++mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
void parse_input_line(const string_type& s)
|
||||
{
|
||||
// set matches back to starting values:
|
||||
for(int i = 0; i < MAX_MATCHES; ++i)
|
||||
{
|
||||
matches[i] = -2;
|
||||
}
|
||||
parse_function op;
|
||||
do_test = false;
|
||||
regex_grep(op, s.begin(), s.end(), parse_expression);
|
||||
jm_trace("expression: " << expression);
|
||||
jm_trace("search string: " << search_text);
|
||||
}
|
||||
|
||||
int to_int(string_type::const_iterator i, string_type::const_iterator j)
|
||||
{
|
||||
int val = 0;
|
||||
bool neg = false;
|
||||
if((i != j) && (*i == BOOST_RE_STR('-')))
|
||||
{
|
||||
neg = true;
|
||||
++i;
|
||||
}
|
||||
while (i != j)
|
||||
{
|
||||
val *= 10;
|
||||
val += *i - BOOST_RE_STR('0');
|
||||
++i;
|
||||
}
|
||||
if(neg)
|
||||
val *= -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
void expand_escapes(string_type& s)
|
||||
{
|
||||
for(unsigned int i = 0; i < s.size(); ++i)
|
||||
{
|
||||
if(s[i] == BOOST_RE_STR('\\'))
|
||||
{
|
||||
switch(s[i+1])
|
||||
{
|
||||
case BOOST_RE_STR('a'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\a');
|
||||
break;
|
||||
case BOOST_RE_STR('b'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\b');
|
||||
break;
|
||||
case BOOST_RE_STR('f'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\f');
|
||||
break;
|
||||
case BOOST_RE_STR('n'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\n');
|
||||
break;
|
||||
case BOOST_RE_STR('r'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\r');
|
||||
break;
|
||||
case BOOST_RE_STR('t'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\t');
|
||||
break;
|
||||
case BOOST_RE_STR('v'):
|
||||
s.erase(s.begin() + i);
|
||||
s[i] = BOOST_RE_STR('\v');
|
||||
break;
|
||||
default:
|
||||
if( (s[i + 1] >= BOOST_RE_STR('0')) && (s[i + 1] <= BOOST_RE_STR('9')) )
|
||||
{
|
||||
int val = 0;
|
||||
unsigned int pos = i;
|
||||
++i;
|
||||
while( (s[i] >= BOOST_RE_STR('0')) && (s[i] <= BOOST_RE_STR('9')) && (i < s.size()))
|
||||
{
|
||||
val *= 10;
|
||||
val += s[i] - BOOST_RE_STR('0');
|
||||
++i;
|
||||
}
|
||||
s.erase(s.begin() + pos, s.begin() + i);
|
||||
if(0 == val)
|
||||
{
|
||||
s.insert(s.begin()+pos, ' ');
|
||||
s[pos] = 0;
|
||||
}
|
||||
else
|
||||
s.insert(s.begin() + pos, val);
|
||||
i = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.erase(s.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
24
demo/regress/r1.cpp
Normal file
24
demo/regress/r1.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// narrow char's, locale Win32
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_W32
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
24
demo/regress/r1lm.cpp
Normal file
24
demo/regress/r1lm.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// narrow char's, locale Win32
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_W32
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
28
demo/regress/r2.cpp
Normal file
28
demo/regress/r2.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// narrow char's, locale C, force no Win32
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_C
|
||||
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
26
demo/regress/r3.cpp
Normal file
26
demo/regress/r3.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// narrow char's, locale CPP
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_CPP
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
26
demo/regress/r4.cpp
Normal file
26
demo/regress/r4.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// wide char's, locale Win32
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_W32
|
||||
#define TEST_UNICODE
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
demo/regress/r5.cpp
Normal file
27
demo/regress/r5.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// wide char's, locale C
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_C
|
||||
#define TEST_UNICODE
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
27
demo/regress/r6.cpp
Normal file
27
demo/regress/r6.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
//
|
||||
// master include file for different regression builds...
|
||||
//
|
||||
// r1.cpp
|
||||
// wide char's, locale CPP
|
||||
|
||||
#define BOOST_RE_TEST_LOCALE_CPP
|
||||
#define TEST_UNICODE
|
||||
|
||||
#include "parse.cpp"
|
||||
#include "regress.cpp"
|
||||
#include "tests.cpp"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
246
demo/regress/regress.cpp
Normal file
246
demo/regress/regress.cpp
Normal file
@ -0,0 +1,246 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* FILE regress.cpp
|
||||
* VERSION 3.01
|
||||
*
|
||||
* main() and associated code for regress.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <boost/regex.hpp>
|
||||
#ifdef BOOST_RE_OLD_IOSTREAM
|
||||
#include <fstream.h>
|
||||
#else
|
||||
#include <fstream>
|
||||
using std::ifstream;
|
||||
using std::ofstream;
|
||||
//using std::cin;
|
||||
//using std::cout;
|
||||
using std::endl;
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hrdstop
|
||||
#endif
|
||||
|
||||
#include "regress.h"
|
||||
|
||||
|
||||
//
|
||||
// declare all our globals here:
|
||||
//
|
||||
|
||||
string_type expression;
|
||||
string_type search_text;
|
||||
string_type format_string;
|
||||
string_type merge_string;
|
||||
int matches[MAX_MATCHES];
|
||||
|
||||
char file[MAX_PATH];
|
||||
int line;
|
||||
bool do_test = false;
|
||||
unsigned int flags[5];
|
||||
unsigned error_count = 0;
|
||||
|
||||
void usage()
|
||||
{
|
||||
cout <<
|
||||
|
||||
"Usage: regress filename [filename2...]\n"
|
||||
"see tests.txt for an example test script\n"
|
||||
"and the script format.\n";
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if(argc < 2)
|
||||
usage();
|
||||
int i;
|
||||
for(i = 1; i < argc; ++i)
|
||||
{
|
||||
reset_error();
|
||||
ifstream is(argv[i]);
|
||||
if(is.good() == false)
|
||||
{
|
||||
cout << "Error unable to open file: " << argv[i] << endl << endl;
|
||||
continue;
|
||||
}
|
||||
std::strcpy(file, argv[i]);
|
||||
line = 0;
|
||||
unsigned int tests = 0;
|
||||
while(is.good())
|
||||
{
|
||||
string_type s;
|
||||
get_line(is, s);
|
||||
++line;
|
||||
jm_trace("Reading test script line " << line << " " << s);
|
||||
parse_input_line(s);
|
||||
if(do_test)
|
||||
{
|
||||
run_tests();
|
||||
++tests;
|
||||
}
|
||||
}
|
||||
cout << line << " lines, " << tests << " tests completed in file " << argv[i] << endl;
|
||||
}
|
||||
return error_count;
|
||||
}
|
||||
|
||||
#ifdef TEST_UNICODE
|
||||
|
||||
ostream& operator << (ostream& os, const wchar_t* s)
|
||||
{
|
||||
while(*s)
|
||||
{
|
||||
os.put((char)*s);
|
||||
++s;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& os, const std::wstring& s)
|
||||
{
|
||||
os << s.c_str();
|
||||
return os;
|
||||
}
|
||||
|
||||
istream& get_line(istream& is, nstring_type& s, char delim)
|
||||
{
|
||||
char c = (char)is.get();
|
||||
s.erase(s.begin(), s.end());
|
||||
while((c != delim) && (c != EOF))
|
||||
{
|
||||
s.append(1, c);
|
||||
c = (char)is.get();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
istream& get_line(istream& is, string_type& s, char delim)
|
||||
{
|
||||
nstring_type t;
|
||||
get_line(is, t, delim);
|
||||
s.erase(s.begin(), s.end());
|
||||
const char* i, *j;
|
||||
i = t.c_str();
|
||||
j = t.c_str() + t.size();
|
||||
wchar_t* buf = new wchar_t[MB_CUR_MAX + 1];
|
||||
int cchars;
|
||||
while(i != j)
|
||||
{
|
||||
cchars = mbtowc(buf, i, j - i);
|
||||
if(cchars == -1)
|
||||
break;
|
||||
if(cchars == 0)
|
||||
break;
|
||||
s.insert(s.end(), buf, buf + cchars);
|
||||
i += cchars;
|
||||
}
|
||||
delete[] buf;
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
istream& get_line(istream& is, string_type& s, char delim)
|
||||
{
|
||||
char c = (char)is.get();
|
||||
s.erase(s.begin(), s.end());
|
||||
while((c != delim) && (c != EOF))
|
||||
{
|
||||
s.append(1, c);
|
||||
c = (char)is.get();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
jm_debug_alloc::jm_debug_alloc()
|
||||
{
|
||||
blocks = new int;
|
||||
count = new int;
|
||||
*blocks = 0;
|
||||
*count = 1;
|
||||
guard = this;
|
||||
}
|
||||
|
||||
jm_debug_alloc::jm_debug_alloc(const jm_debug_alloc& d)
|
||||
{
|
||||
blocks = d.blocks;
|
||||
count = d.count;
|
||||
++(*count);
|
||||
guard = this;
|
||||
}
|
||||
jm_debug_alloc& jm_debug_alloc::operator=(const jm_debug_alloc& d)
|
||||
{
|
||||
free();
|
||||
blocks = d.blocks;
|
||||
count = d.count;
|
||||
++(*count);
|
||||
return *this;
|
||||
}
|
||||
|
||||
jm_debug_alloc::~jm_debug_alloc()
|
||||
{
|
||||
if(guard != this)
|
||||
{
|
||||
cout << "Error: attempt to destroy object already destroyed" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
free();
|
||||
guard = 0;
|
||||
}
|
||||
}
|
||||
void jm_debug_alloc::free()
|
||||
{
|
||||
if(--(*count) == 0)
|
||||
{
|
||||
if(*blocks)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: " << *blocks << " blocks not freed by allocator" << endl;
|
||||
}
|
||||
delete count;
|
||||
delete blocks;
|
||||
}
|
||||
}
|
||||
|
||||
jm_debug_alloc::pointer jm_debug_alloc::allocate(size_type n, void* hint)
|
||||
{
|
||||
pointer p = new char[n + maxi(sizeof(size_type), boost::re_detail::padding_size)];
|
||||
*(size_type*)p = n;
|
||||
++(*blocks);
|
||||
return p + maxi(sizeof(size_type), boost::re_detail::padding_size);
|
||||
}
|
||||
void jm_debug_alloc::deallocate(pointer p, size_type n)
|
||||
{
|
||||
p -= maxi(sizeof(size_type), boost::re_detail::padding_size);
|
||||
if(*(size_type*)p != n)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: size mismatch in allocate/deallocate calls" << endl;
|
||||
}
|
||||
--(*blocks);
|
||||
delete[] p;
|
||||
}
|
||||
|
325
demo/regress/regress.h
Normal file
325
demo/regress/regress.h
Normal file
@ -0,0 +1,325 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* FILE regress.h
|
||||
* VERSION 3.01
|
||||
*
|
||||
* Function and data declarations for regress.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _REGRESS_H
|
||||
#define _REGRESS_H
|
||||
|
||||
#include <boost/re_detail/regex_config.hpp>
|
||||
|
||||
#ifdef BOOST_RE_OLD_IOSTREAM
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cin;
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
using std::endl;
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
|
||||
#ifdef TEST_UNICODE
|
||||
#ifdef __GNUC__
|
||||
#define char_t wchar_t
|
||||
#else
|
||||
typedef wchar_t char_t;
|
||||
#endif
|
||||
#define NO_POSIX_TEST
|
||||
typedef std::basic_string<char_t> string_type;
|
||||
typedef std::basic_string<char> nstring_type;
|
||||
inline istream& get_line(istream& is, nstring_type& s, char delim = '\n');
|
||||
istream& get_line(istream& is, string_type& s, char delim = L'\n');
|
||||
#define BOOST_RE_STR(x) L##x
|
||||
ostream& operator << (ostream& os, const string_type& s);
|
||||
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#define char_t char
|
||||
#else
|
||||
typedef char char_t;
|
||||
#endif
|
||||
typedef std::basic_string<char_t> string_type;
|
||||
inline istream& get_line(istream& is, string_type& s, char delim = '\n');
|
||||
#define BOOST_RE_STR(x) x
|
||||
|
||||
#endif
|
||||
|
||||
ostream& operator << (ostream& os, const wchar_t* s);
|
||||
void parse_input_line(const string_type& s);
|
||||
void expand_escapes(string_type& s);
|
||||
void run_tests();
|
||||
void begin_error();
|
||||
void reset_error();
|
||||
int to_int(string_type::const_iterator i, string_type::const_iterator j);
|
||||
|
||||
#define MAX_MATCHES 30
|
||||
extern string_type expression;
|
||||
extern string_type search_text;
|
||||
extern string_type format_string;
|
||||
extern string_type merge_string;
|
||||
extern int matches[MAX_MATCHES];
|
||||
|
||||
#ifndef MAX_PATH
|
||||
#define MAX_PATH 260
|
||||
#endif
|
||||
|
||||
extern char file[MAX_PATH];
|
||||
extern int line;
|
||||
extern bool do_test;
|
||||
extern unsigned int flags[5];
|
||||
extern unsigned error_count;
|
||||
|
||||
struct flag_info
|
||||
{
|
||||
const char_t* name; // printable flag name
|
||||
unsigned int len; // length of name
|
||||
unsigned int value; // value of the flag
|
||||
unsigned int id; // index to assign value to
|
||||
};
|
||||
|
||||
extern flag_info flag_data[];
|
||||
|
||||
//
|
||||
// class jm_debug_alloc
|
||||
// NB this is a byte based allocator
|
||||
//
|
||||
class jm_debug_alloc
|
||||
{
|
||||
private:
|
||||
int* blocks, *count;
|
||||
jm_debug_alloc* guard;
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef char* pointer;
|
||||
typedef const char* const_pointer;
|
||||
typedef char& reference;
|
||||
typedef const char& const_reference;
|
||||
typedef char value_type;
|
||||
|
||||
|
||||
#ifndef BOOST_RE_NO_MEMBER_TEMPLATES
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef boost::re_detail::re_alloc_binder<U, jm_debug_alloc> other;
|
||||
};
|
||||
#endif
|
||||
|
||||
jm_debug_alloc();
|
||||
|
||||
jm_debug_alloc(const jm_debug_alloc& d);
|
||||
jm_debug_alloc& operator=(const jm_debug_alloc& d);
|
||||
|
||||
~jm_debug_alloc();
|
||||
void free();
|
||||
static pointer address(reference x)
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
static const_pointer address(const_reference x)
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
unsigned maxi(unsigned i, unsigned j)
|
||||
{
|
||||
return i < j ? j : i;
|
||||
}
|
||||
pointer allocate(size_type n, void* hint = 0);
|
||||
void deallocate(pointer p, size_type n);
|
||||
|
||||
static size_type max_size()
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
static void construct(pointer , const char& )
|
||||
{
|
||||
}
|
||||
|
||||
static void destroy(pointer )
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#if __BORLANDC__ < 0x520
|
||||
|
||||
#define BOOST_RE_BORLAND_FIX
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//
|
||||
// class debug_iterator
|
||||
//
|
||||
template <class T>
|
||||
struct debug_iterator : public BOOST_RE_RA_ITERATOR(T, ptrdiff_t)
|
||||
{
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef char_t value_type;
|
||||
typedef char_t* pointer;
|
||||
typedef char_t& reference;
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef debug_iterator self;
|
||||
typedef size_t size_type;
|
||||
|
||||
T cur;
|
||||
T first;
|
||||
T last;
|
||||
|
||||
debug_iterator(T c, T f, T l)
|
||||
: cur(c), first(f), last(l) {}
|
||||
debug_iterator() : cur(), first(), last() {}
|
||||
debug_iterator(const debug_iterator& x)
|
||||
: cur(x.cur), first(x.first), last(x.last) {}
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
if(cur == last)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: attempt to dereference iterator past range" << endl;
|
||||
}
|
||||
return *cur;
|
||||
}
|
||||
|
||||
operator T()const { return cur; }
|
||||
|
||||
difference_type operator-(const self& x) const {
|
||||
return (difference_type)(cur - x.cur);
|
||||
}
|
||||
|
||||
self& operator++()
|
||||
{
|
||||
if(cur == last)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: attempt to increment iterator past range" << endl;
|
||||
return *this;
|
||||
}
|
||||
++cur;
|
||||
return *this;
|
||||
}
|
||||
self operator++(int)
|
||||
{
|
||||
self tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self& operator--()
|
||||
{
|
||||
if(cur == first)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: attempt to decrement iterator past range" << endl;
|
||||
return *this;
|
||||
}
|
||||
--cur;
|
||||
return *this;
|
||||
}
|
||||
self operator--(int)
|
||||
{
|
||||
self tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
self& operator+=(difference_type n)
|
||||
{
|
||||
if((last - cur) < n)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: attempt to increment iterator past range" << endl;
|
||||
return *this;
|
||||
}
|
||||
cur += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
self operator+(difference_type n) const
|
||||
{
|
||||
self tmp = *this;
|
||||
return tmp += n;
|
||||
}
|
||||
|
||||
self& operator-=(difference_type n) { return *this += -n; }
|
||||
|
||||
self operator-(difference_type n) const
|
||||
{
|
||||
self tmp = *this;
|
||||
return tmp -= n;
|
||||
}
|
||||
|
||||
reference operator[](difference_type n) const { return *(cur + n); }
|
||||
|
||||
bool operator==(const self& x) const { return cur == x.cur; }
|
||||
bool operator!=(const self& x) const { return !(*this == x); }
|
||||
bool operator<(const self& x) const {
|
||||
return (cur < x.cur);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__SGI_STL_PORT) && (__SGI_STL_PORT >= 0x400)
|
||||
namespace std{
|
||||
template <class T>
|
||||
inline random_access_iterator_tag __STL_CALL
|
||||
__iterator_category(const debug_iterator<T>&) {
|
||||
return random_access_iterator_tag();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_RE_TEST_LOCALE_W32
|
||||
typedef boost::reg_expression<char_t, boost::w32_regex_traits<char_t>, jm_debug_alloc> re_type;
|
||||
#elif defined(BOOST_RE_TEST_LOCALE_CPP)
|
||||
typedef boost::reg_expression<char_t, boost::cpp_regex_traits<char_t>, jm_debug_alloc> re_type;
|
||||
#else
|
||||
typedef boost::reg_expression<char_t, boost::c_regex_traits<char_t>, jm_debug_alloc> re_type;
|
||||
#endif
|
||||
|
||||
#define REG_NO_POSIX_TEST 1
|
||||
#define REG_UNICODE_ONLY 2
|
||||
#define REG_GREP 4
|
||||
#define REG_MERGE 8
|
||||
#define REG_MERGE_COPY 16
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
28
demo/regress/sunpro.mak
Normal file
28
demo/regress/sunpro.mak
Normal file
@ -0,0 +1,28 @@
|
||||
# Makefile for timer application
|
||||
#
|
||||
# for SUN workshop 5.0 C++ compiler
|
||||
#
|
||||
|
||||
CXX=CC
|
||||
CPP_FLAGS = -O -I../../../../ -I./
|
||||
|
||||
all: r2 r5
|
||||
r2 tests.txt
|
||||
r5 tests.txt
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c -o $@ $(CPP_FLAGS) $<
|
||||
|
||||
r2 : r2.o
|
||||
$(CXX) -o $@ $(CPP_FLAGS) r2.o -L../../lib -lregex++
|
||||
|
||||
r5 : r5.o
|
||||
$(CXX) -o $@ $(CPP_FLAGS) r5.o -L../../lib -lregex++
|
||||
|
||||
clean:
|
||||
rm -rf SunWS_cache
|
||||
rm -f r2.o r2 r5 r5.o
|
||||
|
||||
|
||||
|
||||
|
32
demo/regress/test1252.txt
Normal file
32
demo/regress/test1252.txt
Normal file
@ -0,0 +1,32 @@
|
||||
;
|
||||
; This file tests code page 1252 - US / Western European code page.
|
||||
;
|
||||
; See tests.txt for a desciption of the scipt format.
|
||||
;
|
||||
|
||||
- match_default extended REG_EXTENDED
|
||||
|
||||
; start by testing character classes:
|
||||
[[:lower:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 32
|
||||
[[:upper:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 31
|
||||
[[:punct:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 31
|
||||
[[:print:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 94
|
||||
[[:graph:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 94
|
||||
[a-z]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 31
|
||||
[a-z]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 31
|
||||
[[:word:]]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 61
|
||||
;and equivalence classes:
|
||||
[[=a=]]+ aA<61><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 14
|
||||
|
||||
; and then test case mapping:
|
||||
- match_default extended REG_EXTENDED REG_ICASE
|
||||
;[A-Z]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 31
|
||||
;[a-z]+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 31
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 30
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
729
demo/regress/tests.cpp
Normal file
729
demo/regress/tests.cpp
Normal file
@ -0,0 +1,729 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* FILE tests.cpp
|
||||
* VERSION 3.01
|
||||
*
|
||||
* the actual tests conducted by regress.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include "regress.h"
|
||||
|
||||
using namespace boost;
|
||||
|
||||
template <class M1, class M2>
|
||||
bool compare_result(const M1& sm, const M2& m)
|
||||
{
|
||||
if(sm.size() != m.size())
|
||||
return false;
|
||||
if(sm.line() != m.line())
|
||||
return false;
|
||||
for(unsigned int i = 0; i < sm.size(); ++i)
|
||||
{
|
||||
if(sm.position(i) != m.position(i))
|
||||
return false;
|
||||
if(sm.length(i) != m.length(i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class M1>
|
||||
bool compare_result(const M1& sm, const M1& m)
|
||||
{
|
||||
return sm == m;
|
||||
}
|
||||
|
||||
|
||||
template <class C, class T, class A>
|
||||
void cpp_eh_tests(const reg_expression<C, T, A>& )
|
||||
{
|
||||
#ifndef __GNUC__
|
||||
bool thrown = false;
|
||||
// try set_expression form first:
|
||||
try
|
||||
{
|
||||
A a;
|
||||
reg_expression<C, T, A> e(a);
|
||||
e.set_expression(expression.c_str(), flags[2] | regbase::use_except);
|
||||
}
|
||||
catch(const boost::bad_expression&)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch(...){}
|
||||
if(!thrown)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: expected exception not thrown" << endl;
|
||||
}
|
||||
|
||||
// now try constructor form:
|
||||
thrown = false;
|
||||
try
|
||||
{
|
||||
A a;
|
||||
reg_expression<C, T, A> e(expression.c_str(), flags[2] | regbase::use_except, a);
|
||||
}
|
||||
catch(const boost::bad_expression&)
|
||||
{
|
||||
thrown = true;
|
||||
}
|
||||
catch(...){}
|
||||
if(!thrown)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Error: expected exception not thrown" << endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class iterator>
|
||||
iterator find_last_line(iterator start, iterator end)
|
||||
{
|
||||
iterator result = start;
|
||||
while(start != end)
|
||||
{
|
||||
if(*start == '\n')
|
||||
{
|
||||
++start;
|
||||
result = start;
|
||||
}
|
||||
else
|
||||
++start;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class iterator>
|
||||
unsigned int count_lines(iterator start, iterator end)
|
||||
{
|
||||
unsigned int result = 0;
|
||||
while(start != end)
|
||||
{
|
||||
if(*start == '\n')
|
||||
++result;
|
||||
++start;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class iterator, class Alloc>
|
||||
class grep_test_predicate
|
||||
{
|
||||
int match_id;
|
||||
iterator base, term;
|
||||
public:
|
||||
grep_test_predicate(iterator i, iterator j) : base(i), term(j) { match_id = 0; }
|
||||
~grep_test_predicate(){}
|
||||
bool operator()(const boost::match_results< iterator, Alloc >& m);
|
||||
};
|
||||
|
||||
template <class iterator, class Alloc>
|
||||
bool grep_test_predicate<iterator, Alloc>::operator()(const boost::match_results< iterator, Alloc >& m)
|
||||
{
|
||||
int start, end;
|
||||
start = m[0].first - base;
|
||||
end = m[0].second - base;
|
||||
if((matches[match_id] != start) || (matches[match_id + 1] != end))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep match error: found [" << start << "," << end << "] expected [" << matches[match_id] << "," << matches[match_id+1] << "]" << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// check $`:
|
||||
start = m[-1].first - base;
|
||||
end = m[-1].second - base;
|
||||
if(match_id &&
|
||||
( (end != matches[match_id]) || (start != matches[match_id - 1]) )
|
||||
)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep error in $`: found [" << start << "," << end << "] expected [" << matches[match_id-1] << "," << matches[match_id] << "]" << endl;
|
||||
}
|
||||
else if((!match_id) && ((start != 0) || (end != matches[0])))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep error in $`: found [" << start << "," << end << "] expected [" << 0 << "," << matches[0] << "]" << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// check $':
|
||||
start = m[-2].first - base;
|
||||
end = m[-2].second - base;
|
||||
if((start != matches[match_id + 1]) || (end != (term-base)))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep error in $': found [" << start << "," << end << "] expected [" << matches[match_id + 1] << "," << (term-base) << "]" << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// now check line()
|
||||
start = m.line();
|
||||
end = count_lines(base, iterator(m[0].first)) + 1;
|
||||
if(start != end)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep error in line(): found " << start << " expected " << end << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// now check line_start()
|
||||
start = m.line_start() - base;
|
||||
end = find_last_line(base, iterator(m[0].first)) - base;
|
||||
if(start != end)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ grep error in line_start(): found " << start << " expected " << end << endl;
|
||||
}
|
||||
|
||||
match_id += 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class C, class T, class A>
|
||||
void cpp_tests(const reg_expression<C, T, A>& e, bool recurse = true)
|
||||
{
|
||||
typedef A allocator_type;
|
||||
if(flags[4] & REG_MERGE)
|
||||
{
|
||||
//
|
||||
// test merge code:
|
||||
//
|
||||
string_type s;
|
||||
s = regex_merge(search_text, e, format_string.c_str(), flags[3]);
|
||||
if(s != merge_string)
|
||||
{
|
||||
begin_error();
|
||||
cout << "merge result mismatch: found \"" << s.c_str() << "\" expected \"" << merge_string.c_str() << "\"" << endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(recurse)
|
||||
{
|
||||
// copy and assign test:
|
||||
reg_expression<C, T, A> e2(e);
|
||||
cpp_tests(e2, false);
|
||||
e2 = e;
|
||||
cpp_tests(e2, false);
|
||||
}
|
||||
|
||||
if(e.error_code())
|
||||
{
|
||||
// verify that we don't expect expression to compile
|
||||
if(search_text != BOOST_RE_STR("!"))
|
||||
{
|
||||
begin_error();
|
||||
cout << "Expression did not compile using regex++ API" << endl;
|
||||
}
|
||||
else if(recurse)
|
||||
cpp_eh_tests(e);
|
||||
}
|
||||
else if(flags[4] & REG_GREP)
|
||||
{
|
||||
// try to do grep:
|
||||
debug_iterator<string_type::iterator> x(search_text.begin(), search_text.begin(), search_text.end());
|
||||
debug_iterator<string_type::iterator> y(search_text.end(), search_text.begin(), search_text.end());
|
||||
grep_test_predicate<debug_iterator<string_type::iterator>, allocator_type> oi(x, y);
|
||||
regex_grep(oi, x, y, e, flags[3]);
|
||||
#if !defined(BOOST_RE_NO_PARTIAL_FUNC_SPEC) && !defined(BOOST_RE_NO_STRING_H) && !defined(BOOST_RE_NO_STRING_DEF_ARGS)
|
||||
if(!recurse)
|
||||
{
|
||||
std::basic_string<char_t> s(search_text.begin(), search_text.end());
|
||||
grep_test_predicate<std::basic_string<char_t>::const_iterator, reg_expression<C, T, A>::allocator_type> oi2(s.begin(), s.end());
|
||||
regex_grep(oi2, s, e, flags[3]);
|
||||
grep_test_predicate<const char_t*, reg_expression<C, T, A>::allocator_type> oi3(s.c_str(), s.c_str()+s.size());
|
||||
regex_grep(oi3, s.c_str(), e, flags[3]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to find match
|
||||
match_results< debug_iterator<string_type::iterator>, reg_expression<C, T, A>::allocator_type> m;
|
||||
debug_iterator<string_type::iterator> x(search_text.begin(), search_text.begin(), search_text.end());
|
||||
debug_iterator<string_type::iterator> y(search_text.end(), search_text.begin(), search_text.end());
|
||||
if(regex_search(x, y, m, e, flags[3]))
|
||||
{
|
||||
// match found compare what matched with what we expect:
|
||||
int j = 0;
|
||||
for(unsigned int i = 0; i < m.size(); ++i, j += 2)
|
||||
{
|
||||
if(m[i].matched == false)
|
||||
{
|
||||
if(matches[j] != -1)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in sub-expression " << i <<
|
||||
", found (" << (m[i].first - x) << "," <<
|
||||
(m[i].second - x) << ") expected (" <<
|
||||
matches[j] << "," << matches[j+1] << ")" << endl;
|
||||
}
|
||||
}
|
||||
else if(((m[i].first - x) != matches[j]) || ((m[i].second - x) != matches[j+1]))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in sub-expression " << i <<
|
||||
", found (" << (m[i].first - x) << "," <<
|
||||
(m[i].second - x) << ") expected (" <<
|
||||
matches[j] << "," << matches[j+1] << ")" << endl;
|
||||
}
|
||||
}
|
||||
//
|
||||
// now check $` and $':
|
||||
//
|
||||
if((m[-1].first != x) || (m[-1].second != m[0].first))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in $` (match -1), found (" <<
|
||||
(m[-1].first - x) << "," << (m[-1].second - x) << ") expected (0" <<
|
||||
"," << matches[0] << ")" << endl;
|
||||
}
|
||||
if((m[-2].first != m[0].second) || (m[-2].second != y))
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in $' (match -2), found (" <<
|
||||
(m[-2].first - x) << "," << (m[-2].second - x) << ") expected (" <<
|
||||
matches[1] << "," << (y-x) << ")" << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// now try alternative forms of regex_search if available:
|
||||
#if !defined(BOOST_RE_NO_PARTIAL_FUNC_SPEC) && !defined(BOOST_RE_NO_STRING_H) && !defined(BOOST_RE_NO_STRING_DEF_ARGS)
|
||||
if(!recurse)
|
||||
{
|
||||
std::basic_string<char_t> s(search_text.begin(), search_text.end());
|
||||
match_results<std::basic_string<char_t>::const_iterator> sm;
|
||||
if(regex_search(s, sm, e, flags[3]))
|
||||
{
|
||||
if(compare_result(sm, m) == false)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_search(const std::string&, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_search(const std::string&, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
if(s.find(char_t(0)) == std::basic_string<char_t>::npos)
|
||||
{
|
||||
match_results<const char_t*> ssm;
|
||||
if(regex_search(search_text.c_str(), ssm, e, flags[3]))
|
||||
{
|
||||
if(compare_result(ssm, m) == false)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_search(const char_t*, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_search(const char_t*, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if((false == recurse) && (matches[0] == 0) && (matches[1] == search_text.size()))
|
||||
{
|
||||
//
|
||||
// match expected on whole string, so all versions
|
||||
// of regex_match should also succeed:
|
||||
//
|
||||
match_results< debug_iterator<string_type::iterator>, reg_expression<C, T, A>::allocator_type> m1;
|
||||
debug_iterator<string_type::iterator> x1(search_text.begin(), search_text.begin(), search_text.end());
|
||||
debug_iterator<string_type::iterator> y1(search_text.end(), search_text.begin(), search_text.end());
|
||||
if(regex_match(x1, y1, m1, e, flags[3]))
|
||||
{
|
||||
if(compare_result(m1, m) == false)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(iterator, iterator, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(iterator, iterator, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
std::basic_string<char_t> s(search_text.begin(), search_text.end());
|
||||
match_results<std::basic_string<char_t>::const_iterator> sm;
|
||||
if(regex_match(s, sm, e, flags[3]))
|
||||
{
|
||||
if(compare_result(sm, m) == false)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(const std::string&, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(const std::string&, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
if(s.find(char_t(0)) == std::basic_string<char_t>::npos)
|
||||
{
|
||||
match_results<const char_t*> ssm;
|
||||
if(regex_match(search_text.c_str(), ssm, e, flags[3]))
|
||||
{
|
||||
if(compare_result(ssm, m) == false)
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(const char_t*, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_error();
|
||||
cout << "regex++ API result mismatch in regex_match(const char_t*, match_results&, const reg_expression&, int)" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// match not found
|
||||
if(matches[0] != -1)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Match expected but not found using regex++ API" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(TEST_UNICODE)
|
||||
|
||||
unsigned int hl_match_id;
|
||||
|
||||
bool hl_grep_test_proc(const RegEx& e)
|
||||
{
|
||||
int start, end;
|
||||
start = e.Position(0);
|
||||
end = start + e.Length();
|
||||
if((matches[hl_match_id] != start) || (matches[hl_match_id + 1] != end))
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep match error: found [" << start << "," << end << "] expected [" << matches[hl_match_id] << "," << matches[hl_match_id+1] << "]" << endl;
|
||||
}
|
||||
|
||||
//
|
||||
// check $`:
|
||||
start = e.Position(-1);
|
||||
end = start + e.Length(-1);
|
||||
if(start == -1)
|
||||
{
|
||||
if(hl_match_id &&
|
||||
( matches[hl_match_id] != matches[hl_match_id - 1] )
|
||||
)
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << matches[hl_match_id-1] << "," << matches[hl_match_id] << "]" << endl;
|
||||
}
|
||||
else if((!hl_match_id) && (0 != matches[0]))
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << 0 << "," << matches[0] << "]" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hl_match_id &&
|
||||
( (end != matches[hl_match_id]) || (start != matches[hl_match_id - 1]) )
|
||||
)
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << matches[hl_match_id-1] << "," << matches[hl_match_id] << "]" << endl;
|
||||
}
|
||||
else if((!hl_match_id) && ((start != 0) || (end != matches[0])))
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $`: found [" << start << "," << end << "] expected [" << 0 << "," << matches[0] << "]" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check $':
|
||||
start = e.Position(-2);
|
||||
end = start + e.Length(-2);
|
||||
if(start == -1)
|
||||
{
|
||||
if(matches[hl_match_id + 1] != search_text.size())
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $': found [" << start << "," << end << "] expected [" << matches[hl_match_id + 1] << "," << (search_text.size()) << "]" << endl;
|
||||
}
|
||||
}
|
||||
else if((start != matches[hl_match_id + 1]) || (end != search_text.size()))
|
||||
{
|
||||
begin_error();
|
||||
cout << "class RegEx grep error in $': found [" << start << "," << end << "] expected [" << matches[hl_match_id + 1] << "," << (search_text.size()) << "]" << endl;
|
||||
}
|
||||
|
||||
hl_match_id += 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
void cpp_hl_tests(RegEx& e, bool recurse = true)
|
||||
{
|
||||
if(flags[4] & REG_MERGE)
|
||||
return;
|
||||
|
||||
if(recurse)
|
||||
{
|
||||
// copy and assign test:
|
||||
RegEx e2(e);
|
||||
cpp_hl_tests(e2, false);
|
||||
e2 = e;
|
||||
cpp_hl_tests(e2, false);
|
||||
}
|
||||
|
||||
if(flags[4] & REG_GREP)
|
||||
{
|
||||
// try to do grep:
|
||||
hl_match_id = 0;
|
||||
GrepCallback cb = hl_grep_test_proc;
|
||||
e.Grep(cb, search_text.c_str(), flags[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(e.Search(search_text.c_str(), flags[3]))
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
while(matches[j] != -2)
|
||||
{
|
||||
if( (matches[j] != e.Position(i)) || (matches[j+1] - matches[j] != e.Length(i)) )
|
||||
{
|
||||
begin_error();
|
||||
cout << "RegEx::Search error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl;
|
||||
}
|
||||
++i;
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(matches[0] != -1)
|
||||
{
|
||||
begin_error();
|
||||
cout << "match expected but not found with RexEx::Search" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
if((matches[0] == 0) && (e.Match(search_text.c_str(), flags[3])))
|
||||
{
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
while(matches[j] != -2)
|
||||
{
|
||||
if( (matches[j] != e.Position(i)) || (matches[j+1] - matches[j] != e.Length(i)) )
|
||||
{
|
||||
begin_error();
|
||||
cout << "RegEx::Match error in subexpression " << i << ": found [" << e.Position(i) << "," << (e.Position(i) + e.Length(i)) << "] expected [" << matches[j] << "," << matches[j+1] << "]" << endl;
|
||||
}
|
||||
++i;
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class iterator>
|
||||
bool has_nulls(iterator i, iterator j)
|
||||
{
|
||||
while(i != j)
|
||||
{
|
||||
if(*i == 0)
|
||||
return true;
|
||||
++i;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef TEST_UNICODE
|
||||
#undef regcomp
|
||||
#undef regerror
|
||||
#undef regexec
|
||||
#undef regfree
|
||||
#undef regex_t
|
||||
#define regcomp regcompW
|
||||
#define regerror regerrorW
|
||||
#define regexec regexecW
|
||||
#define regfree regfreeW
|
||||
#define regex_t regex_tW
|
||||
#endif
|
||||
|
||||
|
||||
void run_tests()
|
||||
{
|
||||
#ifndef TEST_UNICODE
|
||||
if(flags[4] & REG_UNICODE_ONLY)
|
||||
return;
|
||||
#endif
|
||||
#ifndef NO_CPP_TEST
|
||||
try
|
||||
{
|
||||
unsigned int f = flags[2] & ~regbase::use_except;
|
||||
if(flags[0] & REG_ICASE)
|
||||
f |= regbase::icase;
|
||||
re_type e(expression.c_str(), f);
|
||||
cpp_tests(e, true);
|
||||
}
|
||||
#ifndef BOOST_RE_NO_EXCEPTION_H
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
//
|
||||
// this is only an error if the expression is expected to be valid:
|
||||
if(search_text != BOOST_RE_STR("!"))
|
||||
{
|
||||
begin_error();
|
||||
cout << "Unexpected exception thrown from C++ library: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
catch(...)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Unexpected exception thrown from C++ library" << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(TEST_UNICODE)
|
||||
try
|
||||
{
|
||||
if((flags[2] == regbase::normal) && (has_nulls(search_text.begin(), search_text.end()) == false))
|
||||
{
|
||||
RegEx e;
|
||||
e.SetExpression(expression.c_str(), flags[0] & REG_ICASE);
|
||||
cpp_hl_tests(e, true);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
if(search_text != BOOST_RE_STR("!"))
|
||||
{
|
||||
begin_error();
|
||||
cout << "Expression did not compile with class RegEx" << endl;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Unexpected exception thrown from RegEx::SetExpression" << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(flags[4] & (REG_NO_POSIX_TEST | REG_GREP | REG_MERGE | REG_MERGE_COPY))
|
||||
return;
|
||||
regex_t posix_expression;
|
||||
regmatch_t m[MAX_MATCHES];
|
||||
if(regcomp(&posix_expression, expression.c_str(), flags[0]) == 0)
|
||||
{
|
||||
if(flags[1] & REG_STARTEND)
|
||||
{
|
||||
m[0].rm_so = 0;
|
||||
m[0].rm_eo = search_text.size();
|
||||
}
|
||||
if(regexec(&posix_expression, search_text.c_str(), MAX_MATCHES, m, flags[1]))
|
||||
{
|
||||
// match not found
|
||||
if(matches[0] != -1)
|
||||
{
|
||||
begin_error();
|
||||
cout << "Match expected but not found using POSIX API" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// match found compare what matched with what we expect:
|
||||
int j = 0;
|
||||
for(unsigned int i = 0; i <= posix_expression.re_nsub; ++i, j += 2)
|
||||
{
|
||||
if((m[i].rm_so != matches[j]) || (m[i].rm_eo != matches[j+1]))
|
||||
{
|
||||
begin_error();
|
||||
cout << "POSIX API result mismatch in sub-expression " << i << ", found (" << m[i].rm_so << "," << m[i].rm_eo <<
|
||||
") expected (" << matches[j] << "," << matches[j+1] << ")" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
regfree(&posix_expression);
|
||||
}
|
||||
else
|
||||
{
|
||||
// expression did not compile
|
||||
if(search_text != BOOST_RE_STR("!"))
|
||||
{
|
||||
begin_error();
|
||||
cout << "Expression did not compile using POSIX API" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// error reporting:
|
||||
int last_line = 0;
|
||||
|
||||
void begin_error()
|
||||
{
|
||||
if(line != last_line)
|
||||
{
|
||||
cout << "Error in line " << line << " of file " << file << endl;
|
||||
cout << "Expression: " << expression.c_str() << endl;
|
||||
cout << "Search text: " << search_text.c_str() << endl;
|
||||
cout << "Flags: ";
|
||||
bool started = false;
|
||||
unsigned int id = 0;
|
||||
while(flag_data[id].len != 0)
|
||||
{
|
||||
if(flags[flag_data[id].id] & flag_data[id].value)
|
||||
{
|
||||
if(started)
|
||||
cout << " | ";
|
||||
cout << flag_data[id].name;
|
||||
started = true;
|
||||
}
|
||||
++id;
|
||||
}
|
||||
cout << endl;
|
||||
last_line = line;
|
||||
++error_count;
|
||||
}
|
||||
}
|
||||
|
||||
void reset_error()
|
||||
{
|
||||
last_line = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
857
demo/regress/tests.txt
Normal file
857
demo/regress/tests.txt
Normal file
@ -0,0 +1,857 @@
|
||||
;
|
||||
;
|
||||
; this file contains a script of tests to run through regress.exe
|
||||
;
|
||||
; comments start with a semicolon and proceed to the end of the line
|
||||
;
|
||||
; changes to regular expression compile flags start with a "-" as the first
|
||||
; non-whitespace character and consist of a list of the printable names
|
||||
; of the flags, for example "match_default"
|
||||
;
|
||||
; Other lines contain a test to perform using the current flag status
|
||||
; the first token contains the expression to compile, the second the string
|
||||
; to match it against. If the second string is "!" then the expression should
|
||||
; not compile, that is the first string is an invalid regular expression.
|
||||
; This is then followed by a list of integers that specify what should match,
|
||||
; each pair represents the starting and ending positions of a subexpression
|
||||
; starting with the zeroth subexpression (the whole match).
|
||||
; A value of -1 indicates that the subexpression should not take part in the
|
||||
; match at all, if the first value is -1 then no part of the expression should
|
||||
; match the string.
|
||||
;
|
||||
|
||||
- match_default normal REG_EXTENDED
|
||||
|
||||
;
|
||||
; try some really simple literals:
|
||||
a a 0 1
|
||||
Z Z 0 1
|
||||
Z aaa -1 -1
|
||||
Z xxxxZZxxx 4 5
|
||||
|
||||
; and some simple brackets:
|
||||
(a) zzzaazz 3 4 3 4
|
||||
() zzz 0 0 0 0
|
||||
() "" 0 0 0 0
|
||||
( !
|
||||
) !
|
||||
(aa !
|
||||
aa) !
|
||||
a b -1 -1
|
||||
\(\) () 0 2
|
||||
\(a\) (a) 0 3
|
||||
\() !
|
||||
(\) !
|
||||
; now try escaped brackets:
|
||||
- match_default bk_parens REG_BASIC
|
||||
\(a\) zzzaazz 3 4 3 4
|
||||
\(\) zzz 0 0 0 0
|
||||
\(\) "" 0 0 0 0
|
||||
\( !
|
||||
\) !
|
||||
\(aa !
|
||||
aa\) !
|
||||
() () 0 2
|
||||
(a) (a) 0 3
|
||||
(\) !
|
||||
\() !
|
||||
|
||||
; now move on to "." wildcards
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
. a 0 1
|
||||
. \n 0 1
|
||||
. \r 0 1
|
||||
. \0 0 1
|
||||
- match_default normal match_not_dot_newline REG_EXTENDED REG_STARTEND REG_NEWLINE
|
||||
. a 0 1
|
||||
. \n -1 -1
|
||||
. \r -1 -1
|
||||
. \0 0 1
|
||||
- match_default normal match_not_dot_null match_not_dot_newline REG_EXTENDED REG_STARTEND REG_NEWLINE
|
||||
. \n -1 -1
|
||||
. \r -1 -1
|
||||
; this *WILL* produce an error from the POSIX API functions:
|
||||
- match_default normal match_not_dot_null match_not_dot_newline REG_EXTENDED REG_STARTEND REG_NEWLINE REG_NO_POSIX_TEST
|
||||
. \0 -1 -1
|
||||
|
||||
|
||||
;
|
||||
; now move on to the repetion ops,
|
||||
; starting with operator *
|
||||
- match_default normal REG_EXTENDED
|
||||
a* b 0 0
|
||||
ab* a 0 1
|
||||
ab* ab 0 2
|
||||
ab* sssabbbbbbsss 3 10
|
||||
ab*c* a 0 1
|
||||
ab*c* abbb 0 4
|
||||
ab*c* accc 0 4
|
||||
ab*c* abbcc 0 5
|
||||
*a !
|
||||
\<* !
|
||||
\>* !
|
||||
\n* \n\n 0 2
|
||||
\** ** 0 2
|
||||
\* * 0 1
|
||||
|
||||
; now try operator +
|
||||
ab+ a -1 -1
|
||||
ab+ ab 0 2
|
||||
ab+ sssabbbbbbsss 3 10
|
||||
ab+c+ a -1 -1
|
||||
ab+c+ abbb -1 -1
|
||||
ab+c+ accc -1 -1
|
||||
ab+c+ abbcc 0 5
|
||||
+a !
|
||||
\<+ !
|
||||
\>+ !
|
||||
\n+ \n\n 0 2
|
||||
\+ + 0 1
|
||||
\+ ++ 0 1
|
||||
\++ ++ 0 2
|
||||
- match_default normal bk_plus_qm REG_EXTENDED REG_NO_POSIX_TEST
|
||||
+ + 0 1
|
||||
\+ !
|
||||
a\+ aa 0 2
|
||||
|
||||
; now try operator ?
|
||||
- match_default normal REG_EXTENDED
|
||||
a? b 0 0
|
||||
ab? a 0 1
|
||||
ab? ab 0 2
|
||||
ab? sssabbbbbbsss 3 5
|
||||
ab?c? a 0 1
|
||||
ab?c? abbb 0 2
|
||||
ab?c? accc 0 2
|
||||
ab?c? abcc 0 3
|
||||
?a !
|
||||
\<? !
|
||||
\>? !
|
||||
\n? \n\n 0 1
|
||||
\? ? 0 1
|
||||
\? ?? 0 1
|
||||
\?? ?? 0 1
|
||||
- match_default normal bk_plus_qm REG_EXTENDED REG_NO_POSIX_TEST
|
||||
? ? 0 1
|
||||
\? !
|
||||
a\? aa 0 1
|
||||
a\? b 0 0
|
||||
|
||||
- match_default normal limited_ops
|
||||
a? a? 0 2
|
||||
a+ a+ 0 2
|
||||
a\? a? 0 2
|
||||
a\+ a+ 0 2
|
||||
|
||||
; now try operator {}
|
||||
- match_default normal REG_EXTENDED
|
||||
a{2} a -1 -1
|
||||
a{2} aa 0 2
|
||||
a{2} aaa 0 2
|
||||
a{2,} a -1 -1
|
||||
a{2,} aa 0 2
|
||||
a{2,} aaaaa 0 5
|
||||
a{2,4} a -1 -1
|
||||
a{2,4} aa 0 2
|
||||
a{2,4} aaa 0 3
|
||||
a{2,4} aaaa 0 4
|
||||
a{2,4} aaaaa 0 4
|
||||
; spaces are now allowed inside {}
|
||||
"a{ 2 , 4 }" aaaaa 0 4
|
||||
a{} !
|
||||
"a{ }" !
|
||||
a{2 !
|
||||
a} !
|
||||
\{\} {} 0 2
|
||||
|
||||
- match_default normal bk_braces
|
||||
a\{2\} a -1 -1
|
||||
a\{2\} aa 0 2
|
||||
a\{2\} aaa 0 2
|
||||
a\{2,\} a -1 -1
|
||||
a\{2,\} aa 0 2
|
||||
a\{2,\} aaaaa 0 5
|
||||
a\{2,4\} a -1 -1
|
||||
a\{2,4\} aa 0 2
|
||||
a\{2,4\} aaa 0 3
|
||||
a\{2,4\} aaaa 0 4
|
||||
a\{2,4\} aaaaa 0 4
|
||||
"a\{ 2 , 4 \}" aaaaa 0 4
|
||||
{} {} 0 2
|
||||
|
||||
; now test the alternation operator |
|
||||
- match_default normal REG_EXTENDED
|
||||
a|b a 0 1
|
||||
a|b b 0 1
|
||||
a(b|c) ab 0 2 1 2
|
||||
a(b|c) ac 0 2 1 2
|
||||
a(b|c) ad -1 -1 -1 -1
|
||||
|c !
|
||||
c| !
|
||||
(|) !
|
||||
(a|) !
|
||||
(|a) !
|
||||
a\| a| 0 2
|
||||
- match_default normal limited_ops
|
||||
a| a| 0 2
|
||||
a\| a| 0 2
|
||||
| | 0 1
|
||||
- match_default normal bk_vbar REG_NO_POSIX_TEST
|
||||
a| a| 0 2
|
||||
a\|b a 0 1
|
||||
a\|b b 0 1
|
||||
|
||||
; now test the set operator []
|
||||
- match_default normal REG_EXTENDED
|
||||
; try some literals first
|
||||
[abc] a 0 1
|
||||
[abc] b 0 1
|
||||
[abc] c 0 1
|
||||
[abc] d -1 -1
|
||||
[^bcd] a 0 1
|
||||
[^bcd] b -1 -1
|
||||
[^bcd] d -1 -1
|
||||
[^bcd] e 0 1
|
||||
a[b]c abc 0 3
|
||||
a[ab]c abc 0 3
|
||||
a[^ab]c adc 0 3
|
||||
a[]b]c a]c 0 3
|
||||
a[[b]c a[c 0 3
|
||||
a[-b]c a-c 0 3
|
||||
a[^]b]c adc 0 3
|
||||
a[^-b]c adc 0 3
|
||||
a[b-]c a-c 0 3
|
||||
a[b !
|
||||
a[] !
|
||||
|
||||
; then some ranges
|
||||
[b-e] a -1 -1
|
||||
[b-e] b 0 1
|
||||
[b-e] e 0 1
|
||||
[b-e] f -1 -1
|
||||
[^b-e] a 0 1
|
||||
[^b-e] b -1 -1
|
||||
[^b-e] e -1 -1
|
||||
[^b-e] f 0 1
|
||||
a[1-3]c a2c 0 3
|
||||
a[3-1]c !
|
||||
a[1-3-5]c !
|
||||
a[1- !
|
||||
|
||||
; and some classes
|
||||
a[[:alpha:]]c abc 0 3
|
||||
a[[:unknown:]]c !
|
||||
a[[: !
|
||||
a[[:alpha !
|
||||
a[[:alpha:] !
|
||||
a[[:alpha,:] !
|
||||
a[[:]:]]b !
|
||||
a[[:-:]]b !
|
||||
a[[:alph:]] !
|
||||
a[[:alphabet:]] !
|
||||
[[:alnum:]]+ -%@a0X- 3 6
|
||||
[[:alpha:]]+ -%@aX0- 3 5
|
||||
[[:blank:]]+ "a \tb" 1 4
|
||||
[[:cntrl:]]+ a\n\tb 1 3
|
||||
[[:digit:]]+ a019b 1 4
|
||||
[[:graph:]]+ " a%b " 1 4
|
||||
[[:lower:]]+ AabC 1 3
|
||||
[[:print:]]+ "\na b\n" 1 4
|
||||
[[:punct:]]+ " %-&\t" 1 4
|
||||
[[:space:]]+ "a \n\t\rb" 1 5
|
||||
[[:upper:]]+ aBCd 1 3
|
||||
[[:xdigit:]]+ p0f3Cx 1 5
|
||||
|
||||
; now test flag settings:
|
||||
- escape_in_lists REG_NO_POSIX_TEST
|
||||
[\n] \n 0 1
|
||||
- REG_NO_POSIX_TEST
|
||||
[\n] \n -1 -1
|
||||
[\n] \\ 0 1
|
||||
[[:class:] : 0 1
|
||||
[[:class:] [ 0 1
|
||||
[[:class:] c 0 1
|
||||
|
||||
; line anchors
|
||||
- match_default normal REG_EXTENDED
|
||||
^ab ab 0 2
|
||||
^ab xxabxx -1 -1
|
||||
^ab xx\nabzz 3 5
|
||||
ab$ ab 0 2
|
||||
ab$ abxx -1 -1
|
||||
ab$ ab\nzz 0 2
|
||||
- match_default match_not_bol match_not_eol normal REG_EXTENDED REG_NOTBOL REG_NOTEOL
|
||||
^ab ab -1 -1
|
||||
^ab xxabxx -1 -1
|
||||
^ab xx\nabzz 3 5
|
||||
ab$ ab -1 -1
|
||||
ab$ abxx -1 -1
|
||||
ab$ ab\nzz 0 2
|
||||
|
||||
; back references
|
||||
- match_default normal REG_EXTENDED
|
||||
a(b)\2c !
|
||||
a(b\1)c !
|
||||
a(b*)c\1d abbcbbd 0 7 1 3
|
||||
a(b*)c\1d abbcbd -1 -1
|
||||
a(b*)c\1d abbcbbbd -1 -1
|
||||
^(.)\1 abc -1 -1
|
||||
a([bc])\1d abcdabbd 4 8 5 6
|
||||
; strictly speaking this is at best ambiguous, at worst wrong, this is what most
|
||||
; re implimentations will match though.
|
||||
a(([bc])\2)*d abbccd 0 6 3 5 3 4
|
||||
|
||||
a(([bc])\2)*d abbcbd -1 -1
|
||||
a((b)*\2)*d abbbd 0 5 1 4 2 3
|
||||
(ab*)[ab]*\1 ababaaa 0 7 0 1
|
||||
(a)\1bcd aabcd 0 5 0 1
|
||||
(a)\1bc*d aabcd 0 5 0 1
|
||||
(a)\1bc*d aabd 0 4 0 1
|
||||
(a)\1bc*d aabcccd 0 7 0 1
|
||||
(a)\1bc*[ce]d aabcccd 0 7 0 1
|
||||
^(a)\1b(c)*cd$ aabcccd 0 7 0 1 4 5
|
||||
|
||||
;
|
||||
; characters by code:
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
\0101 A 0 1
|
||||
\00 \0 0 1
|
||||
\0 \0 0 1
|
||||
\0172 z 0 1
|
||||
|
||||
;
|
||||
; word operators:
|
||||
\w a 0 1
|
||||
\w z 0 1
|
||||
\w A 0 1
|
||||
\w Z 0 1
|
||||
\w _ 0 1
|
||||
\w } -1 -1
|
||||
\w ` -1 -1
|
||||
\w [ -1 -1
|
||||
\w @ -1 -1
|
||||
; non-word:
|
||||
\W a -1 -1
|
||||
\W z -1 -1
|
||||
\W A -1 -1
|
||||
\W Z -1 -1
|
||||
\W _ -1 -1
|
||||
\W } 0 1
|
||||
\W ` 0 1
|
||||
\W [ 0 1
|
||||
\W @ 0 1
|
||||
; word start:
|
||||
\<abcd " abcd" 2 6
|
||||
\<ab cab -1 -1
|
||||
\<ab "\nab" 1 3
|
||||
\<tag ::tag 2 5
|
||||
;word end:
|
||||
abc\> abc 0 3
|
||||
abc\> abcd -1 -1
|
||||
abc\> abc\n 0 3
|
||||
abc\> abc:: 0 3
|
||||
; word boundary:
|
||||
\babcd " abcd" 2 6
|
||||
\bab cab -1 -1
|
||||
\bab "\nab" 1 3
|
||||
\btag ::tag 2 5
|
||||
abc\b abc 0 3
|
||||
abc\b abcd -1 -1
|
||||
abc\b abc\n 0 3
|
||||
abc\b abc:: 0 3
|
||||
; within word:
|
||||
\B ab 1 1
|
||||
a\Bb ab 0 2
|
||||
a\B ab 0 1
|
||||
a\B a -1 -1
|
||||
a\B "a " -1 -1
|
||||
|
||||
;
|
||||
; buffer operators:
|
||||
\`abc abc 0 3
|
||||
\`abc \nabc -1 -1
|
||||
\`abc " abc" -1 -1
|
||||
abc\' abc 0 3
|
||||
abc\' abc\n -1 -1
|
||||
abc\' "abc " -1 -1
|
||||
|
||||
;
|
||||
; extra escape sequences:
|
||||
\a \a 0 1
|
||||
\f \f 0 1
|
||||
\n \n 0 1
|
||||
\r \r 0 1
|
||||
\t \t 0 1
|
||||
\v \v 0 1
|
||||
|
||||
|
||||
;
|
||||
; now follows various complex expressions designed to try and bust the matcher:
|
||||
a(((b)))c abc 0 3 1 2 1 2 1 2
|
||||
a(b|(c))d abd 0 3 1 2 -1 -1
|
||||
a(b|(c))d acd 0 3 1 2 1 2
|
||||
a(b*|c)d abbd 0 4 1 3
|
||||
; just gotta have one DFA-buster, of course
|
||||
a[ab]{20} aaaaabaaaabaaaabaaaab 0 21
|
||||
; and an inline expansion in case somebody gets tricky
|
||||
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] aaaaabaaaabaaaabaaaab 0 21
|
||||
; and in case somebody just slips in an NFA...
|
||||
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) aaaaabaaaabaaaabaaaabweeknights 0 31 21 24 24 31
|
||||
; one really big one
|
||||
1234567890123456789012345678901234567890123456789012345678901234567890 a1234567890123456789012345678901234567890123456789012345678901234567890b 1 71
|
||||
; fish for problems as brackets go past 8
|
||||
[ab][cd][ef][gh][ij][kl][mn] xacegikmoq 1 8
|
||||
[ab][cd][ef][gh][ij][kl][mn][op] xacegikmoq 1 9
|
||||
[ab][cd][ef][gh][ij][kl][mn][op][qr] xacegikmoqy 1 10
|
||||
[ab][cd][ef][gh][ij][kl][mn][op][q] xacegikmoqy 1 10
|
||||
; and as parenthesis go past 9:
|
||||
(a)(b)(c)(d)(e)(f)(g)(h) zabcdefghi 1 9 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9
|
||||
(a)(b)(c)(d)(e)(f)(g)(h)(i) zabcdefghij 1 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
|
||||
(a)(b)(c)(d)(e)(f)(g)(h)(i)(j) zabcdefghijk 1 11 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11
|
||||
(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k) zabcdefghijkl 1 12 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12
|
||||
(a)d|(b)c abc 1 3 -1 -1 1 2
|
||||
"_+((www)|(ftp)|(mailto)):_*" "_wwwnocolon _mailto:" 12 20 13 19 -1 -1 -1 -1 13 19
|
||||
|
||||
; subtleties of matching
|
||||
a(b)?c\1d acd 0 3 -1 -1
|
||||
a(b?c)+d accd 0 4 2 3
|
||||
(wee|week)(knights|night) weeknights 0 10 0 3 3 10
|
||||
.* abc 0 3
|
||||
a(b|(c))d abd 0 3 1 2 -1 -1
|
||||
a(b|(c))d acd 0 3 1 2 1 2
|
||||
a(b*|c|e)d abbd 0 4 1 3
|
||||
a(b*|c|e)d acd 0 3 1 2
|
||||
a(b*|c|e)d ad 0 2 1 1
|
||||
a(b?)c abc 0 3 1 2
|
||||
a(b?)c ac 0 2 1 1
|
||||
a(b+)c abc 0 3 1 2
|
||||
a(b+)c abbbc 0 5 1 4
|
||||
a(b*)c ac 0 2 1 1
|
||||
(a|ab)(bc([de]+)f|cde) abcdef 0 6 0 1 1 6 3 5
|
||||
a([bc]?)c abc 0 3 1 2
|
||||
a([bc]?)c ac 0 2 1 1
|
||||
a([bc]+)c abc 0 3 1 2
|
||||
a([bc]+)c abcc 0 4 1 3
|
||||
a([bc]+)bc abcbc 0 5 1 3
|
||||
a(bb+|b)b abb 0 3 1 2
|
||||
a(bbb+|bb+|b)b abb 0 3 1 2
|
||||
a(bbb+|bb+|b)b abbb 0 4 1 3
|
||||
a(bbb+|bb+|b)bb abbb 0 4 1 2
|
||||
(.*).* abcdef 0 6 0 6
|
||||
(a*)* bc 0 0 0 0
|
||||
|
||||
; do we get the right subexpression when it is used more than once?
|
||||
a(b|c)*d ad 0 2 -1 -1
|
||||
a(b|c)*d abcd 0 4 2 3
|
||||
a(b|c)+d abd 0 3 1 2
|
||||
a(b|c)+d abcd 0 4 2 3
|
||||
a(b|c?)+d ad 0 2 1 1
|
||||
a(b|c?)+d abcd 0 4 2 3
|
||||
a(b|c){0,0}d ad 0 2 -1 -1
|
||||
a(b|c){0,1}d ad 0 2 -1 -1
|
||||
a(b|c){0,1}d abd 0 3 1 2
|
||||
a(b|c){0,2}d ad 0 2 -1 -1
|
||||
a(b|c){0,2}d abcd 0 4 2 3
|
||||
a(b|c){0,}d ad 0 2 -1 -1
|
||||
a(b|c){0,}d abcd 0 4 2 3
|
||||
a(b|c){1,1}d abd 0 3 1 2
|
||||
a(b|c){1,2}d abd 0 3 1 2
|
||||
a(b|c){1,2}d abcd 0 4 2 3
|
||||
a(b|c){1,}d abd 0 3 1 2
|
||||
a(b|c){1,}d abcd 0 4 2 3
|
||||
a(b|c){2,2}d acbd 0 4 2 3
|
||||
a(b|c){2,2}d abcd 0 4 2 3
|
||||
a(b|c){2,4}d abcd 0 4 2 3
|
||||
a(b|c){2,4}d abcbd 0 5 3 4
|
||||
a(b|c){2,4}d abcbcd 0 6 4 5
|
||||
a(b|c){2,}d abcd 0 4 2 3
|
||||
a(b|c){2,}d abcbd 0 5 3 4
|
||||
a(b+|((c)*))+d abd 0 3 1 2 -1 -1 -1 -1
|
||||
a(b+|((c)*))+d abcd 0 4 2 3 2 3 2 3
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_NOSPEC literal
|
||||
\**?/{} \\**?/{} 0 7
|
||||
|
||||
- match_default normal REG_EXTENDED REG_NO_POSIX_TEST ; we disable POSIX testing because it can't handle escapes in sets
|
||||
; try to match C++ syntax elements:
|
||||
; line comment:
|
||||
//[^\n]* "++i //here is a line comment\n" 4 28
|
||||
; block comment:
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/* here is a block comment */" 0 29 26 27
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/**/" 0 4 -1 -1
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/***/" 0 5 -1 -1
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/****/" 0 6 -1 -1
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/*****/" 0 7 -1 -1
|
||||
/\*([^*]|\*+[^*/])*\*+/ "/*****/*/" 0 7 -1 -1
|
||||
; preprossor directives:
|
||||
^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* "#define some_symbol" 0 19 -1 -1
|
||||
^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* "#define some_symbol(x) #x" 0 25 -1 -1
|
||||
^[[:blank:]]*#([^\n]*\\[[:space:]]+)*[^\n]* "#define some_symbol(x) \\ \r\n foo();\\\r\n printf(#x);" 0 53 28 42
|
||||
; literals:
|
||||
((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? 0xFF 0 4 0 4 0 4 -1 -1 -1 -1 -1 -1 -1 -1
|
||||
((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? 35 0 2 0 2 -1 -1 0 2 -1 -1 -1 -1 -1 -1
|
||||
((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? 0xFFu 0 5 0 4 0 4 -1 -1 -1 -1 -1 -1 -1 -1
|
||||
((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? 0xFFL 0 5 0 4 0 4 -1 -1 4 5 -1 -1 -1 -1
|
||||
((0x[[:xdigit:]]+)|([[:digit:]]+))u?((int(8|16|32|64))|L)? 0xFFFFFFFFFFFFFFFFuint64 0 24 0 18 0 18 -1 -1 19 24 19 24 22 24
|
||||
; strings:
|
||||
'([^\\']|\\.)*' '\\x3A' 0 6 4 5
|
||||
'([^\\']|\\.)*' '\\'' 0 4 1 3
|
||||
'([^\\']|\\.)*' '\\n' 0 4 1 3
|
||||
|
||||
; now try and test some unicode specific characters:
|
||||
- match_default normal REG_EXTENDED REG_UNICODE_ONLY
|
||||
[[:unicode:]]+ a\0300\0400z 1 3
|
||||
|
||||
; finally try some case insensitive matches:
|
||||
- match_default normal REG_EXTENDED REG_ICASE
|
||||
; upper and lower have no meaning here so they fail, however these
|
||||
; may compile with other libraries...
|
||||
;[[:lower:]] !
|
||||
;[[:upper:]] !
|
||||
0123456789@abcdefghijklmnopqrstuvwxyz\[\\\]\^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ\{\|\} 0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]\^_`abcdefghijklmnopqrstuvwxyz\{\|\} 0 72
|
||||
|
||||
; known and suspected bugs:
|
||||
- match_default normal REG_EXTENDED
|
||||
\( ( 0 1
|
||||
\) ) 0 1
|
||||
\$ $ 0 1
|
||||
\^ ^ 0 1
|
||||
\. . 0 1
|
||||
\* * 0 1
|
||||
\+ + 0 1
|
||||
\? ? 0 1
|
||||
\[ [ 0 1
|
||||
\] ] 0 1
|
||||
\| | 0 1
|
||||
\\ \\ 0 1
|
||||
# # 0 1
|
||||
\# # 0 1
|
||||
a- a- 0 2
|
||||
\- - 0 1
|
||||
\{ { 0 1
|
||||
\} } 0 1
|
||||
0 0 0 1
|
||||
1 1 0 1
|
||||
9 9 0 1
|
||||
b b 0 1
|
||||
B B 0 1
|
||||
< < 0 1
|
||||
> > 0 1
|
||||
w w 0 1
|
||||
W W 0 1
|
||||
` ` 0 1
|
||||
' ' 0 1
|
||||
\n \n 0 1
|
||||
, , 0 1
|
||||
a a 0 1
|
||||
f f 0 1
|
||||
n n 0 1
|
||||
r r 0 1
|
||||
t t 0 1
|
||||
v v 0 1
|
||||
c c 0 1
|
||||
x x 0 1
|
||||
: : 0 1
|
||||
(\.[[:alnum:]]+){2} "w.a.b " 1 5 3 5
|
||||
|
||||
- match_default normal REG_EXTENDED REG_ICASE
|
||||
a A 0 1
|
||||
A a 0 1
|
||||
[abc]+ abcABC 0 6
|
||||
[ABC]+ abcABC 0 6
|
||||
[a-z]+ abcABC 0 6
|
||||
[A-Z]+ abzANZ 0 6
|
||||
[a-Z]+ abzABZ 0 6
|
||||
[A-z]+ abzABZ 0 6
|
||||
[[:lower:]]+ abyzABYZ 0 8
|
||||
[[:upper:]]+ abzABZ 0 6
|
||||
[[:word:]]+ abcZZZ 0 6
|
||||
[[:alpha:]]+ abyzABYZ 0 8
|
||||
[[:alnum:]]+ 09abyzABYZ 0 10
|
||||
|
||||
; updated tests for version 2:
|
||||
- match_default normal REG_EXTENDED
|
||||
\x41 A 0 1
|
||||
\xff \255 0 1
|
||||
\xFF \255 0 1
|
||||
- match_default normal REG_EXTENDED REG_NO_POSIX_TEST
|
||||
\c@ \0 0 1
|
||||
- match_default normal REG_EXTENDED
|
||||
\cA \1 0 1
|
||||
\cz \58 0 1
|
||||
\c= !
|
||||
\c? !
|
||||
=: =: 0 2
|
||||
|
||||
; word start:
|
||||
[[:<:]]abcd " abcd" 2 6
|
||||
[[:<:]]ab cab -1 -1
|
||||
[[:<:]]ab "\nab" 1 3
|
||||
[[:<:]]tag ::tag 2 5
|
||||
;word end:
|
||||
abc[[:>:]] abc 0 3
|
||||
abc[[:>:]] abcd -1 -1
|
||||
abc[[:>:]] abc\n 0 3
|
||||
abc[[:>:]] abc:: 0 3
|
||||
|
||||
; collating elements and rewritten set code:
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
[[.zero.]] 0 0 1
|
||||
[[.one.]] 1 0 1
|
||||
[[.two.]] 2 0 1
|
||||
[[.three.]] 3 0 1
|
||||
[[.a.]] baa 1 2
|
||||
[[.right-curly-bracket.]] } 0 1
|
||||
[[.NUL.]] \0 0 1
|
||||
[[:<:]z] !
|
||||
[a[:>:]] !
|
||||
[[=a=]] a 0 1
|
||||
[[=right-curly-bracket=]] } 0 1
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_ICASE
|
||||
[[.A.]] A 0 1
|
||||
[[.A.]] a 0 1
|
||||
[[.A.]-b]+ AaBb 0 4
|
||||
[A-[.b.]]+ AaBb 0 4
|
||||
[[.a.]-B]+ AaBb 0 4
|
||||
[a-[.B.]]+ AaBb 0 4
|
||||
- match_default normal REG_EXTENDED REG_NO_POSIX_TEST
|
||||
[\x61] a 0 1
|
||||
[\x61-c]+ abcd 0 3
|
||||
[a-\x63]+ abcd 0 3
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
[[.a.]-c]+ abcd 0 3
|
||||
[a-[.c.]]+ abcd 0 3
|
||||
[[:alpha:]-a] !
|
||||
[a-[:alpha:]] !
|
||||
|
||||
; try mutli-character ligatures:
|
||||
[[.ae.]] ae 0 2
|
||||
[[.ae.]] aE -1 -1
|
||||
[[.AE.]] AE 0 2
|
||||
[[.Ae.]] Ae 0 2
|
||||
[[.ae.]-b] a -1 -1
|
||||
[[.ae.]-b] b 0 1
|
||||
[[.ae.]-b] ae 0 2
|
||||
[a-[.ae.]] a 0 1
|
||||
[a-[.ae.]] b -1 -1
|
||||
[a-[.ae.]] ae 0 2
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_ICASE
|
||||
[[.ae.]] AE 0 2
|
||||
[[.ae.]] Ae 0 2
|
||||
[[.AE.]] Ae 0 2
|
||||
[[.Ae.]] aE 0 2
|
||||
[[.AE.]-B] a -1 -1
|
||||
[[.Ae.]-b] b 0 1
|
||||
[[.Ae.]-b] B 0 1
|
||||
[[.ae.]-b] AE 0 2
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
;extended perl style escape sequences:
|
||||
\e \27 0 1
|
||||
\x1b \27 0 1
|
||||
\x{1b} \27 0 1
|
||||
\x{} !
|
||||
\x{ !
|
||||
\x} !
|
||||
\x !
|
||||
\x{yy !
|
||||
\x{1b !
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_NO_POSIX_TEST
|
||||
\l+ ABabcAB 2 5
|
||||
[\l]+ ABabcAB 2 5
|
||||
[a-\l] !
|
||||
[\l-a] !
|
||||
[\L] !
|
||||
\L+ abABCab 2 5
|
||||
\u+ abABCab 2 5
|
||||
[\u]+ abABCab 2 5
|
||||
[\U] !
|
||||
\U+ ABabcAB 2 5
|
||||
\d+ ab012ab 2 5
|
||||
[\d]+ ab012ab 2 5
|
||||
[\D] !
|
||||
\D+ 01abc01 2 5
|
||||
\s+ "ab ab" 2 5
|
||||
[\s]+ "ab ab" 2 5
|
||||
[\S] !
|
||||
\S+ " abc " 2 5
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
\Qabc !
|
||||
\Qabc\E abcd 0 3
|
||||
\Qabc\Ed abcde 0 4
|
||||
\Q+*?\\E +*?\\ 0 4
|
||||
|
||||
\C+ abcde 0 5
|
||||
\X+ abcde 0 5
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_UNICODE_ONLY
|
||||
\X+ a\768\769 0 3
|
||||
\X+ \2309\2307 0 2 ;DEVANAGARI script
|
||||
\X+ \2489\2494 0 2 ;BENGALI script
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND
|
||||
\Aabc abc 0 3
|
||||
\Aabc aabc -1 -1
|
||||
abc\z abc 0 3
|
||||
abc\z abcd -1 -1
|
||||
abc\Z abc\n\n 0 3
|
||||
abc\Z abc 0 3
|
||||
|
||||
|
||||
\Gabc abc 0 3
|
||||
\Gabc dabcd -1 -1
|
||||
a\Gbc abc -1 -1
|
||||
a\Aab abc -1 -1
|
||||
|
||||
;
|
||||
; now test grep,
|
||||
; basically check all our restart types - line, word, etc
|
||||
; checking each one for null and non-null matches.
|
||||
;
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_GREP
|
||||
a " a a a aa" 1 2 3 4 5 6 7 8 8 9
|
||||
a+b+ "aabaabbb ab" 0 3 3 8 9 11
|
||||
a(b*|c|e)d adabbdacd 0 2 2 6 6 9
|
||||
a "\na\na\na\naa" 1 2 3 4 5 6 7 8 8 9
|
||||
|
||||
^ " \n\n \n\n\n" 0 0 4 4 5 5 8 8 9 9 10 10
|
||||
^ab "ab \nab ab\n" 0 2 5 7
|
||||
^[^\n]*\n " \n \n\n \n" 0 4 4 7 7 8 8 11
|
||||
\<abc "abcabc abc\n\nabc" 0 3 7 10 12 15
|
||||
\< " ab a aaa " 2 2 5 5 7 7
|
||||
\<\w+\W+ " aa aa a " 1 5 5 9 9 11
|
||||
|
||||
\Aabc "abc abc" 0 3
|
||||
\G\w+\W+ "abc abc a cbbb " 0 5 5 9 9 11 11 18
|
||||
\Ga+b+ "aaababb abb" 0 4 4 7
|
||||
|
||||
abc abc 0 3
|
||||
abc " abc abcabc " 1 4 5 8 8 11
|
||||
\n\n " \n\n\n \n \n\n\n\n " 1 3 18 20 20 22
|
||||
|
||||
$ " \n\n \n\n\n" 3 3 4 4 7 7 8 8 9 9 10 10
|
||||
\b " abb a abbb " 2 2 5 5 6 6 7 7 8 8 12 12
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_GREP REG_ICASE
|
||||
A " a a a aa" 1 2 3 4 5 6 7 8 8 9
|
||||
A+B+ "aabaabbb ab" 0 3 3 8 9 11
|
||||
A(B*|c|e)D adabbdacd 0 2 2 6 6 9
|
||||
A "\na\na\na\naa" 1 2 3 4 5 6 7 8 8 9
|
||||
|
||||
^aB "Ab \nab Ab\n" 0 2 5 7
|
||||
\<abc "Abcabc aBc\n\nabc" 0 3 7 10 12 15
|
||||
|
||||
ABC abc 0 3
|
||||
abc " ABC ABCABC " 1 4 5 8 8 11
|
||||
|
||||
|
||||
;
|
||||
; now test merge,
|
||||
;
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_MERGE format_no_copy
|
||||
; start by testing subs:
|
||||
a+ "...aaa,,," $` "..."
|
||||
a+ "...aaa,,," $' ",,,"
|
||||
a+ "...aaa,,," $& "aaa"
|
||||
a+ "...aaa,,," $0 aaa
|
||||
a+ "...aaa,,," $1 ""
|
||||
a+ "...aaa,,," $15 ""
|
||||
(a+)b+ "...aaabbb,,," $1 aaa
|
||||
|
||||
; and now escapes:
|
||||
a+ "...aaa,,," $x "$x"
|
||||
a+ "...aaa,,," \a "\a"
|
||||
a+ "...aaa,,," \f "\f"
|
||||
a+ "...aaa,,," \n "\n"
|
||||
a+ "...aaa,,," \r "\r"
|
||||
a+ "...aaa,,," \t "\t"
|
||||
a+ "...aaa,,," \v "\v"
|
||||
|
||||
a+ "...aaa,,," \x21 "!"
|
||||
a+ "...aaa,,," \x{21} "!"
|
||||
a+ "...aaa,,," \c@ \0
|
||||
a+ "...aaa,,," \e \27
|
||||
a+ "...aaa,,," \0101 A
|
||||
a+ "...aaa,,," (\0101) A
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_MERGE format_sed format_no_copy
|
||||
(a+)(b+) ...aabb,, \0 aabb
|
||||
(a+)(b+) ...aabb,, \1 aa
|
||||
(a+)(b+) ...aabb,, \2 bb
|
||||
(a+)(b+) ...aabb,, & aabb
|
||||
(a+)(b+) ...aabb,, $ $
|
||||
(a+)(b+) ...aabb,, $1 $1
|
||||
(a+)(b+) ...aabb,, ()?: ()?:
|
||||
(a+)(b+) ...aabb,, \\ \\
|
||||
(a+)(b+) ...aabb,, \& &
|
||||
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_MERGE format_perl format_no_copy
|
||||
(a+)(b+) ...aabb,, $0 aabb
|
||||
(a+)(b+) ...aabb,, $1 aa
|
||||
(a+)(b+) ...aabb,, $2 bb
|
||||
(a+)(b+) ...aabb,, $& aabb
|
||||
(a+)(b+) ...aabb,, & &
|
||||
(a+)(b+) ...aabb,, \0 \0
|
||||
(a+)(b+) ...aabb,, ()?: ()?:
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_MERGE
|
||||
; move to copying unmatched data:
|
||||
a+ "...aaa,,," bbb "...bbb,,,"
|
||||
a+(b+) "...aaabb,,," $1 "...bb,,,"
|
||||
a+(b+) "...aaabb,,,ab*abbb?" $1 "...bb,,,b*bbb?"
|
||||
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" (?1A)(?2B) "...AB,,,AB*AB?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" ?1A:B "...AB,,,AB*AB?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" (?1A:B)C "...ACBC,,,ACBC*ACBC?"
|
||||
(a+)|(b+) "...aaabb,,,ab*abbb?" ?1:B "...B,,,B*B?"
|
||||
|
||||
;
|
||||
; changes to newline handling with 2.11:
|
||||
;
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_GREP
|
||||
|
||||
^. " \n \r\n " 0 1 3 4 7 8
|
||||
.$ " \n \r\n " 1 2 4 5 8 9
|
||||
|
||||
- match_default normal REG_EXTENDED REG_STARTEND REG_GREP REG_UNICODE_ONLY
|
||||
^. " \8232 \8233 " 0 1 3 4 5 6
|
||||
.$ " \8232 \8233 " 1 2 3 4 6 7
|
||||
|
||||
;
|
||||
; non-greedy repeats added 21/04/00
|
||||
- match_default normal REG_EXTENDED
|
||||
a** !
|
||||
a*? aa 0 0
|
||||
a?? aa 0 0
|
||||
a++ !
|
||||
a+? aa 0 1
|
||||
a{1,3}{1} !
|
||||
a{1,3}? aaa 0 1
|
||||
\w+?w ...ccccccwcccccw 3 10
|
||||
\W+\w+?w ...ccccccwcccccw 0 10
|
||||
abc|\w+? abd 0 1
|
||||
abc|\w+? abcd 0 3
|
||||
<\s*tag[^>]*>(.*?)<\s*/tag\s*> " <tag>here is some text</tag> <tag></tag>" 1 29 6 23
|
||||
<\s*tag[^>]*>(.*?)<\s*/tag\s*> " < tag attr=\"something\">here is some text< /tag > <tag></tag>" 1 49 24 41
|
||||
|
||||
;
|
||||
; non-marking parenthesis added 25/04/00
|
||||
- match_default normal REG_EXTENDED
|
||||
(?:abc)+ xxabcabcxx 2 8
|
||||
(?:a+)(b+) xaaabbbx 1 7 4 7
|
||||
(a+)(?:b+) xaaabbba 1 7 1 4
|
||||
(?:(a+)b+) xaaabbba 1 7 1 4
|
||||
(?:a+(b+)) xaaabbba 1 7 4 7
|
||||
a+(?#b+)b+ xaaabbba 1 7
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
125
demo/regress/vc6-stlport.mak
Normal file
125
demo/regress/vc6-stlport.mak
Normal file
@ -0,0 +1,125 @@
|
||||
|
||||
# very basic makefile for regression tests
|
||||
#
|
||||
# Visual C++ 6 + full stlport 4.x
|
||||
#
|
||||
# we don't test single threaded builds as stlport doesn't support these...
|
||||
#
|
||||
CFLAGS= -O2 -GX -GR -I..\..\..\..\
|
||||
|
||||
LFLAGS= -link /LIBPATH:..\..\lib\vc6-stlport user32.lib
|
||||
|
||||
all :: r1m.exe r2m.exe r3m.exe r4m.exe r5m.exe r6m.exe r1l.exe r2l.exe r3l.exe r4l.exe r5l.exe r6l.exe r1md.exe r2md.exe r3md.exe r4md.exe r5md.exe r6md.exe r1lmd.exe r2lmd.exe r3lmd.exe r4lmd.exe r5lmd.exe r6lmd.exe
|
||||
echo testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
r2m tests.txt
|
||||
r3m tests.txt
|
||||
r4m tests.txt test1252.txt
|
||||
r5m tests.txt
|
||||
r6m tests.txt
|
||||
echo testing DLL version....
|
||||
r1l tests.txt test1252.txt
|
||||
r2l tests.txt
|
||||
r3l tests.txt
|
||||
r4l tests.txt test1252.txt
|
||||
r5l tests.txt
|
||||
r6l tests.txt
|
||||
echo testing static multi-threaded debug version....
|
||||
r1md tests.txt test1252.txt
|
||||
r2md tests.txt
|
||||
r3md tests.txt
|
||||
r4md tests.txt test1252.txt
|
||||
r5md tests.txt
|
||||
r6md tests.txt
|
||||
echo testing dll debug version....
|
||||
r1lmd tests.txt test1252.txt
|
||||
r2lmd tests.txt
|
||||
r3lmd tests.txt
|
||||
r4lmd tests.txt test1252.txt
|
||||
r5lmd tests.txt
|
||||
r6lmd tests.txt
|
||||
|
||||
|
||||
r1m.exe : r1.cpp
|
||||
cl /MT /D_MT -o r1m.exe $(CFLAGS) r1.cpp $(LFLAGS)
|
||||
|
||||
r2m.exe : r2.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r2m.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3m.exe : r3.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r3m.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4m.exe : r4.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r4m.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5m.exe : r5.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r5m.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6m.exe : r6.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r6m.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1l.exe : r1.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r1l.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2l.exe : r2.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r2l.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3l.exe : r3.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r3l.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4l.exe : r4.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r4l.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5l.exe : r5.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r5l.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6l.exe : r6.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r6l.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1md.exe : r1.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r1md.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2md.exe : r2.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r2md.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3md.exe : r3.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r3md.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4md.exe : r4.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r4md.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5md.exe : r5.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r5md.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6md.exe : r6.cpp
|
||||
cl /MTd /D_MT /D_DEBUG $(CFLAGS) -o r6md.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1lmd.exe : r1.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r1lmd.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2lmd.exe : r2.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r2lmd.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3lmd.exe : r3.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r3lmd.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4lmd.exe : r4.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r4lmd.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5lmd.exe : r5.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r5lmd.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6lmd.exe : r6.cpp
|
||||
cl /MDd /D_MT /D_DLL /D_DEBUG $(CFLAGS) -o r6lmd.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
173
demo/regress/vc6.mak
Normal file
173
demo/regress/vc6.mak
Normal file
@ -0,0 +1,173 @@
|
||||
|
||||
# very basic makefile for regression tests
|
||||
#
|
||||
# Visual C++ 6
|
||||
#
|
||||
CFLAGS= -O2 -GX -GR -I..\..\..\..\
|
||||
|
||||
LFLAGS= -link /LIBPATH:..\..\lib\vc6 user32.lib
|
||||
|
||||
all :: r1.exe r2.exe r3.exe r4.exe r5.exe r6.exe r1m.exe r2m.exe r3m.exe r4m.exe r5m.exe r6m.exe r1l.exe r2l.exe r3l.exe r4l.exe r5l.exe r6l.exe r1d.exe r2d.exe r3d.exe r4d.exe r5d.exe r6d.exe r1md.exe r2md.exe r3md.exe r4md.exe r5md.exe r6md.exe r1lmd.exe r2lmd.exe r3lmd.exe r4lmd.exe r5lmd.exe r6lmd.exe
|
||||
echo testing static single threaded version....
|
||||
r1 tests.txt test1252.txt
|
||||
r2 tests.txt
|
||||
r3 tests.txt
|
||||
r4 tests.txt test1252.txt
|
||||
r5 tests.txt
|
||||
r6 tests.txt
|
||||
echo testing static multi-threaded version....
|
||||
r1m tests.txt test1252.txt
|
||||
r2m tests.txt
|
||||
r3m tests.txt
|
||||
r4m tests.txt test1252.txt
|
||||
r5m tests.txt
|
||||
r6m tests.txt
|
||||
echo testing DLL version....
|
||||
r1l tests.txt test1252.txt
|
||||
r2l tests.txt
|
||||
r3l tests.txt
|
||||
r4l tests.txt test1252.txt
|
||||
r5l tests.txt
|
||||
r6l tests.txt
|
||||
echo testing static single threaded debug version....
|
||||
r1d tests.txt test1252.txt
|
||||
r2d tests.txt
|
||||
r3d tests.txt
|
||||
r4d tests.txt test1252.txt
|
||||
r5d tests.txt
|
||||
r6d tests.txt
|
||||
echo testing static multi-threaded debug version....
|
||||
r1md tests.txt test1252.txt
|
||||
r2md tests.txt
|
||||
r3md tests.txt
|
||||
r4md tests.txt test1252.txt
|
||||
r5md tests.txt
|
||||
r6md tests.txt
|
||||
echo testing dll debug version....
|
||||
r1lmd tests.txt test1252.txt
|
||||
r2lmd tests.txt
|
||||
r3lmd tests.txt
|
||||
r4lmd tests.txt test1252.txt
|
||||
r5lmd tests.txt
|
||||
r6lmd tests.txt
|
||||
|
||||
|
||||
r1.exe : r1.cpp
|
||||
cl /ML $(CFLAGS) r1.cpp $(LFLAGS)
|
||||
|
||||
r2.exe : r2.cpp
|
||||
cl /ML $(CFLAGS) r2.cpp $(LFLAGS)
|
||||
|
||||
r3.exe : r3.cpp
|
||||
cl /ML $(CFLAGS) r3.cpp $(LFLAGS)
|
||||
|
||||
r4.exe : r4.cpp
|
||||
cl /ML $(CFLAGS) r4.cpp $(LFLAGS)
|
||||
|
||||
r5.exe : r5.cpp
|
||||
cl /ML $(CFLAGS) r5.cpp $(LFLAGS)
|
||||
|
||||
r6.exe : r6.cpp
|
||||
cl /ML $(CFLAGS) r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1m.exe : r1.cpp
|
||||
cl /MT /D_MT -o r1m.exe $(CFLAGS) r1.cpp $(LFLAGS)
|
||||
|
||||
r2m.exe : r2.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r2m.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3m.exe : r3.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r3m.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4m.exe : r4.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r4m.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5m.exe : r5.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r5m.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6m.exe : r6.cpp
|
||||
cl /MT /D_MT $(CFLAGS) -o r6m.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1l.exe : r1.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r1l.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2l.exe : r2.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r2l.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3l.exe : r3.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r3l.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4l.exe : r4.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r4l.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5l.exe : r5.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r5l.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6l.exe : r6.cpp
|
||||
cl /MD /D_MT /D_DLL $(CFLAGS) -o r6l.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1d.exe : r1.cpp
|
||||
cl /MLd $(CFLAGS) -o r1d.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2d.exe : r2.cpp
|
||||
cl /MLd $(CFLAGS) -o r2d.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3d.exe : r3.cpp
|
||||
cl /MLd $(CFLAGS) -o r3d.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4d.exe : r4.cpp
|
||||
cl /MLd $(CFLAGS) -o r4d.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5d.exe : r5.cpp
|
||||
cl /MLd $(CFLAGS) -o r5d.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6d.exe : r6.cpp
|
||||
cl /MLd $(CFLAGS) -o r6d.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1md.exe : r1.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r1md.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2md.exe : r2.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r2md.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3md.exe : r3.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r3md.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4md.exe : r4.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r4md.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5md.exe : r5.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r5md.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6md.exe : r6.cpp
|
||||
cl /MTd /D_MT $(CFLAGS) -o r6md.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
r1lmd.exe : r1.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r1lmd.exe r1.cpp $(LFLAGS)
|
||||
|
||||
r2lmd.exe : r2.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r2lmd.exe r2.cpp $(LFLAGS)
|
||||
|
||||
r3lmd.exe : r3.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r3lmd.exe r3.cpp $(LFLAGS)
|
||||
|
||||
r4lmd.exe : r4.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r4lmd.exe r4.cpp $(LFLAGS)
|
||||
|
||||
r5lmd.exe : r5.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r5lmd.exe r5.cpp $(LFLAGS)
|
||||
|
||||
r6lmd.exe : r6.cpp
|
||||
cl /MDd /D_MT /D_DLL $(CFLAGS) -o r6lmd.exe r6.cpp $(LFLAGS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
99
demo/snippets/snip1.cpp
Normal file
99
demo/snippets/snip1.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip1.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: ftp based regex_match example.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <boost/regex.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
regex expression("^([0-9]+)(\\-| |$)(.*)$");
|
||||
|
||||
// process_ftp:
|
||||
// on success returns the ftp response code, and fills
|
||||
// msg with the ftp response message.
|
||||
int process_ftp(const char* response, std::string* msg)
|
||||
{
|
||||
cmatch what;
|
||||
if(regex_match(response, what, expression))
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[1] contains the response code
|
||||
// what[2] contains the separator character
|
||||
// what[3] contains the text message.
|
||||
if(msg)
|
||||
msg->assign(what[3].first, what[3].second);
|
||||
return std::atoi(what[1].first);
|
||||
}
|
||||
// failure did not match
|
||||
if(msg)
|
||||
msg->erase();
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550))
|
||||
//
|
||||
// problem with std::getline under MSVC6sp3
|
||||
istream& getline(istream& is, std::string& s)
|
||||
{
|
||||
s.erase();
|
||||
char c = is.get();
|
||||
while(c != '\n')
|
||||
{
|
||||
s.append(1, c);
|
||||
c = is.get();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string in, out;
|
||||
while(true)
|
||||
{
|
||||
cout << "enter test string" << endl;
|
||||
getline(cin, in);
|
||||
if(in == "quit")
|
||||
break;
|
||||
int result;
|
||||
result = process_ftp(in.c_str(), &out);
|
||||
if(result != -1)
|
||||
{
|
||||
cout << "Match found:" << endl;
|
||||
cout << "Response code: " << result << endl;
|
||||
cout << "Message text: " << out << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Match not found" << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
45
demo/snippets/snip10.cpp
Normal file
45
demo/snippets/snip10.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
#include <string>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
bool validate_card_format(const std::string& s)
|
||||
{
|
||||
static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
|
||||
return regex_match(s, e);
|
||||
}
|
||||
|
||||
const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
|
||||
const std::string machine_format("\\1\\2\\3\\4");
|
||||
const std::string human_format("\\1-\\2-\\3-\\4");
|
||||
|
||||
std::string machine_readable_card_number(const std::string& s)
|
||||
{
|
||||
return regex_merge(s, e, machine_format, boost::match_default | boost::format_sed);
|
||||
}
|
||||
|
||||
std::string human_readable_card_number(const std::string& s)
|
||||
{
|
||||
return regex_merge(s, e, human_format, boost::match_default | boost::format_sed);
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string s[4] = { "0000111122223333", "0000 1111 2222 3333",
|
||||
"0000-1111-2222-3333", "000-1111-2222-3333", };
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
cout << "validate_card_format(\"" << s[i] << "\") returned " << validate_card_format(s[i]) << endl;
|
||||
}
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
cout << "machine_readable_card_number(\"" << s[i] << "\") returned " << machine_readable_card_number(s[i]) << endl;
|
||||
}
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
cout << "human_readable_card_number(\"" << s[i] << "\") returned " << human_readable_card_number(s[i]) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
105
demo/snippets/snip2.cpp
Normal file
105
demo/snippets/snip2.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip2.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_search example: searches a cpp file for class definitions.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file in the form of a string
|
||||
// and searches for all the C++ class definitions, storing
|
||||
// their locations in a map of strings/int's
|
||||
|
||||
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||||
|
||||
boost::regex expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\\{|:[^;\\{()]*\\{)");
|
||||
|
||||
void IndexClasses(map_type& m, const std::string& file)
|
||||
{
|
||||
std::string::const_iterator start, end;
|
||||
start = file.begin();
|
||||
end = file.end();
|
||||
boost::match_results<std::string::const_iterator> what;
|
||||
unsigned int flags = boost::match_default;
|
||||
while(regex_search(start, end, what, expression, flags))
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[5] contains the class name.
|
||||
// what[6] contains the template specialisation if any.
|
||||
// add class name and position to map:
|
||||
m[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||||
what[5].first - file.begin();
|
||||
// update search position:
|
||||
start = what[0].second;
|
||||
// update flags:
|
||||
flags |= boost::match_prev_avail;
|
||||
flags |= boost::match_not_bob;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string text;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cout << "Processing file " << argv[i] << endl;
|
||||
map_type m;
|
||||
std::ifstream fs(argv[i]);
|
||||
load_file(text, fs);
|
||||
IndexClasses(m, text);
|
||||
cout << m.size() << " matches found" << endl;
|
||||
map_type::iterator c, d;
|
||||
c = m.begin();
|
||||
d = m.end();
|
||||
while(c != d)
|
||||
{
|
||||
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
106
demo/snippets/snip3.cpp
Normal file
106
demo/snippets/snip3.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip3.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_grep example 1: searches a cpp file for class definitions.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file in the form of a string
|
||||
// and searches for all the C++ class definitions, storing
|
||||
// their locations in a map of strings/int's
|
||||
|
||||
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||||
|
||||
boost::regex expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\\{|:[^;\\{()]*\\{)");
|
||||
|
||||
class IndexClassesPred
|
||||
{
|
||||
map_type& m;
|
||||
std::string::const_iterator base;
|
||||
public:
|
||||
IndexClassesPred(map_type& a, std::string::const_iterator b) : m(a), base(b) {}
|
||||
bool operator()(const boost::match_results<std::string::const_iterator, boost::regex::allocator_type>& what)
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[5] contains the class name.
|
||||
// what[6] contains the template specialisation if any.
|
||||
// add class name and position to map:
|
||||
m[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||||
what[5].first - base;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void IndexClasses(map_type& m, const std::string& file)
|
||||
{
|
||||
std::string::const_iterator start, end;
|
||||
start = file.begin();
|
||||
end = file.end();
|
||||
regex_grep(IndexClassesPred(m, start), start, end, expression);
|
||||
}
|
||||
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string text;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cout << "Processing file " << argv[i] << endl;
|
||||
map_type m;
|
||||
std::ifstream fs(argv[i]);
|
||||
load_file(text, fs);
|
||||
IndexClasses(m, text);
|
||||
cout << m.size() << " matches found" << endl;
|
||||
map_type::iterator c, d;
|
||||
c = m.begin();
|
||||
d = m.end();
|
||||
while(c != d)
|
||||
{
|
||||
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
130
demo/snippets/snip4.cpp
Normal file
130
demo/snippets/snip4.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip4.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_merge example:
|
||||
* converts a C++ file to syntax highlighted HTML.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <boost/regex.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file and transform to
|
||||
// syntax highlighted code in html format
|
||||
|
||||
boost::regex e1, e2;
|
||||
extern const char* expression_text;
|
||||
extern const char* format_string;
|
||||
extern const char* pre_expression;
|
||||
extern const char* pre_format;
|
||||
extern const char* header_text;
|
||||
extern const char* footer_text;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
e1.set_expression(expression_text);
|
||||
e2.set_expression(pre_expression);
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::cout << "Processing file " << argv[i] << std::endl;
|
||||
std::ifstream fs(argv[i]);
|
||||
std::string in;
|
||||
load_file(in, fs);
|
||||
std::string out_name(std::string(argv[i]) + std::string(".htm"));
|
||||
std::ofstream os(out_name.c_str());
|
||||
os << header_text;
|
||||
// strip '<' and '>' first by outputting to a
|
||||
// temporary string stream
|
||||
std::ostringstream t(std::ios::out | std::ios::binary);
|
||||
std::ostream_iterator<char, char> oi(t);
|
||||
regex_merge(oi, in.begin(), in.end(), e2, pre_format);
|
||||
// then output to final output stream
|
||||
// adding syntax highlighting:
|
||||
std::string s(t.str());
|
||||
std::ostream_iterator<char, char> out(os);
|
||||
regex_merge(out, s.begin(), s.end(), e1, format_string);
|
||||
os << footer_text;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern const char* pre_expression = "(<)|(>)|\\r";
|
||||
extern const char* pre_format = "(?1<)(?2>)";
|
||||
|
||||
|
||||
const char* expression_text = // preprocessor directives: index 1
|
||||
"(^[[:blank:]]*#([^\\n]*\\\\[[:space:]]+)*[^\\n]*)|"
|
||||
// comment: index 3
|
||||
"(//[^\\n]*|/\\*([^*]|\\*+[^*/])*\\*+/)|"
|
||||
// literals: index 5
|
||||
"\\<([+-]?((0x[[:xdigit:]]+)|(([[:digit:]]*\\.)?[[:digit:]]+([eE][+-]?[[:digit:]]+)?))u?((int(8|16|32|64))|L)?)\\>|"
|
||||
// string literals: index 14
|
||||
"('([^\\\\']|\\\\.)*'|\"([^\\\\\"]|\\\\.)*\")|"
|
||||
// keywords: index 17
|
||||
"\\<(__asm|__cdecl|__declspec|__export|__far16|__fastcall|__fortran|__import"
|
||||
"|__pascal|__rtti|__stdcall|_asm|_cdecl|__except|_export|_far16|_fastcall"
|
||||
"|__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto|bool"
|
||||
"|break|case|catch|cdecl|char|class|const|const_cast|continue|default|delete"
|
||||
"|do|double|dynamic_cast|else|enum|explicit|extern|false|float|for|friend|goto"
|
||||
"|if|inline|int|long|mutable|namespace|new|operator|pascal|private|protected"
|
||||
"|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_cast"
|
||||
"|struct|switch|template|this|throw|true|try|typedef|typeid|typename|union|unsigned"
|
||||
"|using|virtual|void|volatile|wchar_t|while)\\>"
|
||||
;
|
||||
|
||||
const char* format_string = "(?1<font color=\"#008040\">$&</font>)"
|
||||
"(?3<I><font color=\"#000080\">$&</font></I>)"
|
||||
"(?5<font color=\"#0000A0\">$&</font>)"
|
||||
"(?14<font color=\"#0000FF\">$&</font>)"
|
||||
"(?17<B>$&</B>)";
|
||||
|
||||
const char* header_text = "<HTML>\n<HEAD>\n"
|
||||
"<TITLE>Auto-generated html formated source</TITLE>\n"
|
||||
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=windows-1252\">\n"
|
||||
"</HEAD>\n"
|
||||
"<BODY LINK=\"#0000ff\" VLINK=\"#800080\" BGCOLOR=\"#ffff99\">\n"
|
||||
"<P> </P>\n<PRE>";
|
||||
|
||||
const char* footer_text = "</PRE>\n</BODY>\n\n";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
98
demo/snippets/snip5.cpp
Normal file
98
demo/snippets/snip5.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip5.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_grep example 2: searches a cpp file for class definitions,
|
||||
* using a global callback function.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file in the form of a string
|
||||
// and searches for all the C++ class definitions, storing
|
||||
// their locations in a map of strings/int's
|
||||
|
||||
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||||
|
||||
boost::regex expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\\{|:[^;\\{()]*\\{)");
|
||||
map_type class_index;
|
||||
std::string::const_iterator base;
|
||||
|
||||
bool grep_callback(const boost::match_results<std::string::const_iterator, boost::regex::allocator_type>& what)
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[5] contains the class name.
|
||||
// what[6] contains the template specialisation if any.
|
||||
// add class name and position to map:
|
||||
class_index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||||
what[5].first - base;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IndexClasses(const std::string& file)
|
||||
{
|
||||
std::string::const_iterator start, end;
|
||||
start = file.begin();
|
||||
end = file.end();
|
||||
base = start;
|
||||
regex_grep(grep_callback, start, end, expression);
|
||||
}
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string text;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cout << "Processing file " << argv[i] << endl;
|
||||
std::ifstream fs(argv[i]);
|
||||
load_file(text, fs);
|
||||
IndexClasses(text);
|
||||
cout << class_index.size() << " matches found" << endl;
|
||||
map_type::iterator c, d;
|
||||
c = class_index.begin();
|
||||
d = class_index.end();
|
||||
while(c != d)
|
||||
{
|
||||
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
|
||||
++c;
|
||||
}
|
||||
class_index.erase(class_index.begin(), class_index.end());
|
||||
}
|
||||
return 0;
|
||||
}
|
117
demo/snippets/snip6.cpp
Normal file
117
demo/snippets/snip6.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip6.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_grep example 2: searches a cpp file for class definitions,
|
||||
* using a bound member function callback.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/regex.hpp>
|
||||
#include <functional>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file in the form of a string
|
||||
// and searches for all the C++ class definitions, storing
|
||||
// their locations in a map of strings/int's
|
||||
|
||||
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||||
|
||||
class class_index
|
||||
{
|
||||
boost::regex expression;
|
||||
map_type index;
|
||||
std::string::const_iterator base;
|
||||
|
||||
bool grep_callback(boost::match_results<std::string::const_iterator, boost::regex::allocator_type> what);
|
||||
public:
|
||||
map_type& get_map() { return index; }
|
||||
void IndexClasses(const std::string& file);
|
||||
class_index()
|
||||
: index(),
|
||||
expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\\{|:[^;\\{()]*\\{)")
|
||||
{}
|
||||
};
|
||||
|
||||
bool class_index::grep_callback(boost::match_results<std::string::const_iterator, boost::regex::allocator_type> what)
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[5] contains the class name.
|
||||
// what[6] contains the template specialisation if any.
|
||||
// add class name and position to map:
|
||||
index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||||
what[5].first - base;
|
||||
return true;
|
||||
}
|
||||
|
||||
void class_index::IndexClasses(const std::string& file)
|
||||
{
|
||||
std::string::const_iterator start, end;
|
||||
start = file.begin();
|
||||
end = file.end();
|
||||
base = start;
|
||||
regex_grep(std::bind1st(std::mem_fun(&class_index::grep_callback), this),
|
||||
start,
|
||||
end,
|
||||
expression);
|
||||
}
|
||||
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string text;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cout << "Processing file " << argv[i] << endl;
|
||||
std::ifstream fs(argv[i]);
|
||||
load_file(text, fs);
|
||||
class_index i;
|
||||
i.IndexClasses(text);
|
||||
cout << i.get_map().size() << " matches found" << endl;
|
||||
map_type::iterator c, d;
|
||||
c = i.get_map().begin();
|
||||
d = i.get_map().end();
|
||||
while(c != d)
|
||||
{
|
||||
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
120
demo/snippets/snip7.cpp
Normal file
120
demo/snippets/snip7.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip7.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_grep example 2: searches a cpp file for class definitions,
|
||||
* using a C++ Builder closure as a callback.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <boost/regex.hpp>
|
||||
#include <functional>
|
||||
|
||||
// purpose:
|
||||
// takes the contents of a file in the form of a string
|
||||
// and searches for all the C++ class definitions, storing
|
||||
// their locations in a map of strings/int's
|
||||
|
||||
typedef std::map<std::string, int, std::less<std::string> > map_type;
|
||||
|
||||
class class_index
|
||||
{
|
||||
boost::regex expression;
|
||||
map_type index;
|
||||
std::string::const_iterator base;
|
||||
typedef boost::match_results<std::string::const_iterator, boost::regex::allocator_type> arg_type;
|
||||
|
||||
bool grep_callback(const boost::match_results<std::string::const_iterator, boost::regex::allocator_type>& what);
|
||||
public:
|
||||
map_type& get_map() { return index; }
|
||||
typedef bool (__closure* grep_callback_type)(const arg_type&);
|
||||
void IndexClasses(const std::string& file);
|
||||
class_index()
|
||||
: index(),
|
||||
expression("^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\\{|:[^;\\{()]*\\{)")
|
||||
{}
|
||||
};
|
||||
|
||||
bool class_index::grep_callback(const boost::match_results<std::string::const_iterator, boost::regex::allocator_type>& what)
|
||||
{
|
||||
// what[0] contains the whole string
|
||||
// what[5] contains the class name.
|
||||
// what[6] contains the template specialisation if any.
|
||||
// add class name and position to map:
|
||||
index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] =
|
||||
what[5].first - base;
|
||||
return true;
|
||||
}
|
||||
|
||||
void class_index::IndexClasses(const std::string& file)
|
||||
{
|
||||
std::string::const_iterator start, end;
|
||||
start = file.begin();
|
||||
end = file.end();
|
||||
base = start;
|
||||
class_index::grep_callback_type cl = &(this->grep_callback);
|
||||
regex_grep(cl,
|
||||
start,
|
||||
end,
|
||||
expression);
|
||||
}
|
||||
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
std::string text;
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
cout << "Processing file " << argv[i] << endl;
|
||||
std::ifstream fs(argv[i]);
|
||||
load_file(text, fs);
|
||||
class_index i;
|
||||
i.IndexClasses(text);
|
||||
cout << i.get_map().size() << " matches found" << endl;
|
||||
map_type::iterator c, d;
|
||||
c = i.get_map().begin();
|
||||
d = i.get_map().end();
|
||||
while(c != d)
|
||||
{
|
||||
cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
73
demo/snippets/snip8.cpp
Normal file
73
demo/snippets/snip8.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip8.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_split example: split a string into tokens.
|
||||
*/
|
||||
|
||||
|
||||
#include <list>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
|
||||
unsigned tokenise(std::list<std::string>& l, std::string& s)
|
||||
{
|
||||
return boost::regex_split(std::back_inserter(l), s);
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550))
|
||||
//
|
||||
// problem with std::getline under MSVC6sp3
|
||||
istream& getline(istream& is, std::string& s)
|
||||
{
|
||||
s.erase();
|
||||
char c = is.get();
|
||||
while(c != '\n')
|
||||
{
|
||||
s.append(1, c);
|
||||
c = is.get();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
string s;
|
||||
list<string> l;
|
||||
do{
|
||||
cout << "Enter text to split (or \"quit\" to exit): ";
|
||||
getline(cin, s);
|
||||
if(s == "quit") break;
|
||||
unsigned result = tokenise(l, s);
|
||||
cout << result << " tokens found" << endl;
|
||||
cout << "The remaining text is: \"" << s << "\"" << endl;
|
||||
while(l.size())
|
||||
{
|
||||
s = *(l.begin());
|
||||
l.pop_front();
|
||||
cout << s << endl;
|
||||
}
|
||||
}while(true);
|
||||
return 0;
|
||||
}
|
84
demo/snippets/snip9.cpp
Normal file
84
demo/snippets/snip9.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE snip9.cpp
|
||||
* VERSION 3.00
|
||||
* DESCRIPTION: regex_split example: spit out linked URL's.
|
||||
*/
|
||||
|
||||
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"",
|
||||
boost::regbase::normal | boost::regbase::icase);
|
||||
|
||||
void load_file(std::string& s, std::istream& is)
|
||||
{
|
||||
s.erase();
|
||||
//
|
||||
// attempt to grow string buffer to match file size,
|
||||
// this doesn't always work...
|
||||
s.reserve(is.rdbuf()->in_avail());
|
||||
char c;
|
||||
while(is.get(c))
|
||||
{
|
||||
// use logarithmic growth stategy, in case
|
||||
// in_avail (above) returned zero:
|
||||
if(s.capacity() == s.size())
|
||||
s.reserve(s.capacity() * 3);
|
||||
s.append(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::string s;
|
||||
std::list<std::string> l;
|
||||
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::cout << "Findings URL's in " << argv[i] << ":" << std::endl;
|
||||
s.erase();
|
||||
std::ifstream is(argv[i]);
|
||||
load_file(s, is);
|
||||
boost::regex_split(std::back_inserter(l), s, e);
|
||||
while(l.size())
|
||||
{
|
||||
s = *(l.begin());
|
||||
l.pop_front();
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
}
|
||||
//
|
||||
// alternative method:
|
||||
// split one match at a time and output direct to
|
||||
// cout via ostream_iterator<std::string>....
|
||||
//
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
std::cout << "Findings URL's in " << argv[i] << ":" << std::endl;
|
||||
s.erase();
|
||||
std::ifstream is(argv[i]);
|
||||
load_file(s, is);
|
||||
while(boost::regex_split(std::ostream_iterator<std::string>(std::cout), s, e, boost::match_default, 1)) std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
43
demo/timer/bc55.mak
Normal file
43
demo/timer/bc55.mak
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
# very basic makefile for timer.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
COMPOPTS= -O2 -tWC -tWM- -D_NO_VCL; -I../../../../; -L..\..\lib\bcb5
|
||||
|
||||
|
||||
timer.exe : ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
$(BCC32) @&&|
|
||||
$(COMPOPTS) -e$@ ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
43
demo/timer/bcb4.mak
Normal file
43
demo/timer/bcb4.mak
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
# very basic makefile for timer.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
COMPOPTS= -O2 -tWC -tWM- -D_NO_VCL; -I../../../../; -L..\..\lib\bcb4
|
||||
|
||||
|
||||
timer.exe : ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
$(BCC32) @&&|
|
||||
$(COMPOPTS) -e$@ ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
43
demo/timer/bcb5.mak
Normal file
43
demo/timer/bcb5.mak
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
# very basic makefile for timer.exe
|
||||
#
|
||||
# Borland C++ tools
|
||||
#
|
||||
# BCROOT defines the root directory of your bc builder install
|
||||
#
|
||||
|
||||
!ifndef BCROOT
|
||||
BCROOT=$(MAKEDIR)\..
|
||||
!endif
|
||||
|
||||
BCC32 = $(BCROOT)\bin\Bcc32.exe
|
||||
|
||||
IDE_LinkFLAGS32 = -L$(BCROOT)\LIB
|
||||
COMPOPTS= -O2 -tWC -tWM- -D_NO_VCL; -I../../../../; -L..\..\lib\bcb5
|
||||
|
||||
|
||||
timer.exe : ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
$(BCC32) @&&|
|
||||
$(COMPOPTS) -e$@ ..\..\..\timer\timer.cpp regex_timer.cpp
|
||||
|
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
33
demo/timer/gcc.mak
Normal file
33
demo/timer/gcc.mak
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
# very basic makefile for timer.exe
|
||||
#
|
||||
# egcs compiler GCC
|
||||
#
|
||||
CXX= -O2 -I../../../../ -I./
|
||||
|
||||
timer : regex_timer.o timer.o
|
||||
g++ -o -L../../lib/gcc timer regex_timer.o timer.o -lregex++
|
||||
|
||||
timer.o : ../../../timer/timer.cpp
|
||||
g++ -c $(CXX) ../../../timer/timer.cpp
|
||||
|
||||
regex_timer.o : regex_timer.cpp
|
||||
g++ -c $(CXX) regex_timer.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
37
demo/timer/makefile.in
Normal file
37
demo/timer/makefile.in
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
# very basic makefile for timer
|
||||
#
|
||||
CXX=@CXX@
|
||||
CXXFLAGS=@CXXFLAGS@
|
||||
LIBS=@LIBS@
|
||||
EXE=@ac_exe_ext@
|
||||
OBJ=@ac_obj_ext@
|
||||
|
||||
LIBDEP=../../lib/libregex++.a ../../../../boost/re_detail/regex_options.hpp ../../../../boost/re_detail/regex_config.hpp
|
||||
|
||||
regex_timer$(EXE) : regex_timer$(OBJ) timer$(OBJ)
|
||||
$(CXX) -o timer$(EXE) timer$(OBJ) regex_timer$(OBJ) -L../../lib -lregex++ $(LIBS)
|
||||
|
||||
regex_timer$(OBJ) : regex_timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -DSTRICT -I../../../../ -I./ regex_timer.cpp
|
||||
|
||||
timer$(OBJ) : ../../../timer/timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) -DSTRICT -I../../../../ -I./ ../../../timer/timer.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
322
demo/timer/regex_timer.cpp
Normal file
322
demo/timer/regex_timer.cpp
Normal file
@ -0,0 +1,322 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2000
|
||||
* Dr John Maddock
|
||||
*
|
||||
* Permission to use, copy, modify, distribute and sell this software
|
||||
* and its documentation for any purpose is hereby granted without fee,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear
|
||||
* in supporting documentation. Dr John Maddock makes no representations
|
||||
* about the suitability of this software for any purpose.
|
||||
* It is provided "as is" without express or implied warranty.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef BOOST_RE_OLD_IOSTREAM
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::cerr;
|
||||
using std::istream;
|
||||
using std::ostream;
|
||||
using std::endl;
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/timer.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
// no Koenig lookup, use using declaration instead:
|
||||
using namespace boost;
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
ostream& operator << (ostream& os, const std::wstring& s)
|
||||
{
|
||||
std::wstring::const_iterator i, j;
|
||||
i = s.begin();
|
||||
j = s.end();
|
||||
while(i != j)
|
||||
{
|
||||
os.put(*i);
|
||||
++i;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class S>
|
||||
class string_out_iterator
|
||||
{
|
||||
S* out;
|
||||
public:
|
||||
string_out_iterator(S& s) : out(&s) {}
|
||||
string_out_iterator& operator++() { return *this; }
|
||||
string_out_iterator& operator++(int) { return *this; }
|
||||
string_out_iterator& operator*() { return *this; }
|
||||
string_out_iterator& operator=(typename S::value_type v)
|
||||
{
|
||||
out->append(1, v);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_MSVC) || (defined(__BORLANDC__) && (__BORLANDC__ == 0x550)) || defined(__SGI_STL_PORT)
|
||||
//
|
||||
// problem with std::getline under MSVC6sp3
|
||||
// and C++ Builder 5.5, is this really that hard?
|
||||
istream& getline(istream& is, std::string& s)
|
||||
{
|
||||
s.erase();
|
||||
char c = is.get();
|
||||
while(c != '\n')
|
||||
{
|
||||
s.append(1, c);
|
||||
c = is.get();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::regex ex;
|
||||
boost::match_results<std::string::const_iterator> sm;
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
std::wstring ws1, ws2;
|
||||
boost::wregex wex;
|
||||
boost::match_results<std::wstring::const_iterator> wsm;
|
||||
#endif
|
||||
boost::match_results<std::deque<char>::iterator> dm;
|
||||
std::string s1, s2, ts;
|
||||
std::deque<char> ds;
|
||||
boost::regex_t r;
|
||||
boost::scoped_array<boost::regmatch_t> matches;
|
||||
size_t nsubs;
|
||||
boost::timer t;
|
||||
double tim;
|
||||
bool result;
|
||||
int iters = 100;
|
||||
|
||||
while(true)
|
||||
{
|
||||
cout << "Enter expression (or \"quit\" to exit): ";
|
||||
getline(cin, s1);
|
||||
if(s1 == "quit")
|
||||
break;
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
ws1.erase();
|
||||
std::copy(s1.begin(), s1.end(), string_out_iterator<std::wstring>(ws1));
|
||||
#endif
|
||||
try{
|
||||
ex.assign(s1.begin(), s1.end());
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
wex.assign(ws1.begin(), ws1.end());
|
||||
#endif
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout << "Error in expression: \"" << e.what() << "\"" << endl;
|
||||
continue;
|
||||
}
|
||||
int code = regcomp(&r, s1.c_str(), boost::REG_PERL);
|
||||
if(code != 0)
|
||||
{
|
||||
char buf[256];
|
||||
regerror(code, &r, buf, 256);
|
||||
cout << "regcomp error: \"" << buf << "\"" << endl;
|
||||
continue;
|
||||
}
|
||||
nsubs = r.re_nsub + 1;
|
||||
matches.reset(new boost::regmatch_t[nsubs]);
|
||||
|
||||
while(true)
|
||||
{
|
||||
cout << "Enter string to search (or \"quit\" to exit): ";
|
||||
getline(cin, s2);
|
||||
if(s2 == "quit")
|
||||
break;
|
||||
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
ws2.erase();
|
||||
std::copy(s2.begin(), s2.end(), string_out_iterator<std::wstring>(ws2));
|
||||
#endif
|
||||
ds.erase(ds.begin(), ds.end());
|
||||
std::copy(s2.begin(), s2.end(), std::back_inserter(ds));
|
||||
|
||||
int i;
|
||||
iters = 10;
|
||||
tim = 1.1;
|
||||
|
||||
#if defined(_WIN32) && defined(BOOST_RE_LOCALE_W32)
|
||||
MSG msg;
|
||||
PeekMessage(&msg, 0, 0, 0, 0);
|
||||
Sleep(0);
|
||||
#endif
|
||||
|
||||
// cache load:
|
||||
regex_search(s2, sm, ex);
|
||||
|
||||
// measure time interval for reg_expression<char>
|
||||
do{
|
||||
iters *= (tim > 0.001) ? (1.1/tim) : 100;
|
||||
t.restart();
|
||||
for(i =0; i < iters; ++i)
|
||||
{
|
||||
result = regex_search(s2, sm, ex);
|
||||
}
|
||||
tim = t.elapsed();
|
||||
}while((tim < t.elapsed_min() * 1000) || (tim < 1));
|
||||
|
||||
cout << "regex time: " << (tim * 1000000 / iters) << "us" << endl;
|
||||
if(result)
|
||||
{
|
||||
for(i = 0; i < sm.size(); ++i)
|
||||
{
|
||||
ts = sm[i];
|
||||
cout << "\tmatch " << i << ": \"";
|
||||
cout << ts;
|
||||
cout << "\" (matched=" << sm[i].matched << ")" << endl;
|
||||
}
|
||||
cout << "\tmatch $`: \"";
|
||||
cout << std::string(sm[-1]);
|
||||
cout << "\" (matched=" << sm[-1].matched << ")" << endl;
|
||||
cout << "\tmatch $': \"";
|
||||
cout << std::string(sm[-2]);
|
||||
cout << "\" (matched=" << sm[-2].matched << ")" << endl << endl;
|
||||
}
|
||||
|
||||
#ifndef BOOST_RE_NO_WCSTRING
|
||||
// measure time interval for boost::wregex
|
||||
iters = 10;
|
||||
tim = 1.1;
|
||||
// cache load:
|
||||
regex_search(ws2, wsm, wex);
|
||||
do{
|
||||
iters *= (tim > 0.001) ? (1.1/tim) : 100;
|
||||
t.restart();
|
||||
for(i = 0; i < iters; ++i)
|
||||
{
|
||||
result = regex_search(ws2, wsm, wex);
|
||||
}
|
||||
tim = t.elapsed();
|
||||
}while((tim < t.elapsed_min() * 1000) || (tim < 1));
|
||||
cout << "wregex time: " << (tim * 1000000 / iters) << "us" << endl;
|
||||
if(result)
|
||||
{
|
||||
std::wstring tw;
|
||||
for(i = 0; i < wsm.size(); ++i)
|
||||
{
|
||||
tw.erase();
|
||||
std::copy(wsm[i].first, wsm[i].second, string_out_iterator<std::wstring>(tw));
|
||||
cout << "\tmatch " << i << ": \"" << tw;
|
||||
cout << "\" (matched=" << sm[i].matched << ")" << endl;
|
||||
}
|
||||
cout << "\tmatch $`: \"";
|
||||
tw.erase();
|
||||
std::copy(wsm[-1].first, wsm[-1].second, string_out_iterator<std::wstring>(tw));
|
||||
cout << tw;
|
||||
cout << "\" (matched=" << sm[-1].matched << ")" << endl;
|
||||
cout << "\tmatch $': \"";
|
||||
tw.erase();
|
||||
std::copy(wsm[-2].first, wsm[-2].second, string_out_iterator<std::wstring>(tw));
|
||||
cout << tw;
|
||||
cout << "\" (matched=" << sm[-2].matched << ")" << endl << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
// measure time interval for reg_expression<char> using a deque
|
||||
iters = 10;
|
||||
tim = 1.1;
|
||||
// cache load:
|
||||
regex_search(ds.begin(), ds.end(), dm, ex);
|
||||
do{
|
||||
iters *= (tim > 0.001) ? (1.1/tim) : 100;
|
||||
t.restart();
|
||||
for(i = 0; i < iters; ++i)
|
||||
{
|
||||
result = regex_search(ds.begin(), ds.end(), dm, ex);
|
||||
}
|
||||
tim = t.elapsed();
|
||||
}while((tim < t.elapsed_min() * 1000) || (tim < 1));
|
||||
cout << "regex time (search over std::deque<char>): " << (tim * 1000000 / iters) << "us" << endl;
|
||||
|
||||
if(result)
|
||||
{
|
||||
for(i = 0; i < dm.size(); ++i)
|
||||
{
|
||||
ts.erase();
|
||||
std::copy(dm[i].first, dm[i].second, string_out_iterator<std::string>(ts));
|
||||
cout << "\tmatch " << i << ": \"" << ts;
|
||||
cout << "\" (matched=" << sm[i].matched << ")" << endl;
|
||||
}
|
||||
cout << "\tmatch $`: \"";
|
||||
ts.erase();
|
||||
std::copy(dm[-1].first, dm[-1].second, string_out_iterator<std::string>(ts));
|
||||
cout << ts;
|
||||
cout << "\" (matched=" << sm[-1].matched << ")" << endl;
|
||||
cout << "\tmatch $': \"";
|
||||
ts.erase();
|
||||
std::copy(dm[-2].first, dm[-2].second, string_out_iterator<std::string>(ts));
|
||||
cout << ts;
|
||||
cout << "\" (matched=" << sm[-2].matched << ")" << endl << endl;
|
||||
}
|
||||
|
||||
// measure time interval for POSIX matcher:
|
||||
iters = 10;
|
||||
tim = 1.1;
|
||||
// cache load:
|
||||
regexec(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
do{
|
||||
iters *= (tim > 0.001) ? (1.1/tim) : 100;
|
||||
t.restart();
|
||||
for(i = 0; i < iters; ++i)
|
||||
{
|
||||
result = regexec(&r, s2.c_str(), nsubs, matches.get(), 0);
|
||||
}
|
||||
tim = t.elapsed();
|
||||
}while((tim < t.elapsed_min() * 1000) || (tim < 1));
|
||||
cout << "POSIX regexec time: " << (tim * 1000000 / iters) << "us" << endl;
|
||||
|
||||
if(result == 0)
|
||||
{
|
||||
for(i = 0; i < nsubs; ++i)
|
||||
{
|
||||
if(matches[i].rm_so >= 0)
|
||||
{
|
||||
ts.assign(s2.begin() + matches[i].rm_so, s2.begin() + matches[i].rm_eo);
|
||||
cout << "\tmatch " << i << ": \"" << ts << "\" (matched=" << (matches[i].rm_so != -1) << ")"<< endl;
|
||||
}
|
||||
else
|
||||
cout << "\tmatch " << i << ": \"\" (matched=" << (matches[i].rm_so != -1) << ")" << endl; // no match
|
||||
}
|
||||
cout << "\tmatch $`: \"";
|
||||
ts.erase();
|
||||
ts.assign(s2.begin(), s2.begin() + matches[0].rm_so);
|
||||
cout << ts;
|
||||
cout << "\" (matched=" << (matches[0].rm_so != 0) << ")" << endl;
|
||||
cout << "\tmatch $': \"";
|
||||
ts.erase();
|
||||
ts.assign(s2.begin() + matches[0].rm_eo, s2.end());
|
||||
cout << ts;
|
||||
cout << "\" (matched=" << (matches[0].rm_eo != s2.size()) << ")" << endl << endl;
|
||||
}
|
||||
}
|
||||
regfree(&r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
23
demo/timer/sunpro.mak
Normal file
23
demo/timer/sunpro.mak
Normal file
@ -0,0 +1,23 @@
|
||||
# Makefile for timer application
|
||||
#
|
||||
# for SUN workshop 5.0 C++ compiler
|
||||
#
|
||||
|
||||
CXX=CC
|
||||
CPP_FLAGS = -O -I../../../../ -I./
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c -o $@ $(CPP_FLAGS) $<
|
||||
|
||||
timer : regex_timer.o timer.o
|
||||
$(CXX) -o $@ $(CPP_FLAGS) timer.o regex_timer.o -L../../lib -lregex++
|
||||
|
||||
timer.o : ../../../timer/timer.cpp
|
||||
$(CXX) -c $(CPPFLAGS) ../../../timer/timer.cpp
|
||||
|
||||
clean:
|
||||
rm -rf SunWS_cache
|
||||
rm -f timer.o timer
|
||||
|
||||
|
||||
|
30
demo/timer/vc6-stlport.mak
Normal file
30
demo/timer/vc6-stlport.mak
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# very basic VC6 makefile for timer
|
||||
#
|
||||
CXX=cl
|
||||
CXXFLAGS=-O2 -MT -GX -DSTRICT -I../../../../ -I./
|
||||
LIBS=/link /LIBPATH:..\..\lib\vc6-stlport kernel32.lib user32.lib
|
||||
EXE=.exe
|
||||
OBJ=.obj
|
||||
|
||||
LIBDEP= ../../../../boost/re_detail/regex_options.hpp ../../../../boost/re_detail/regex_config.hpp
|
||||
|
||||
regex_timer$(EXE) : regex_timer$(OBJ) timer$(OBJ)
|
||||
$(CXX) -o timer$(EXE) timer$(OBJ) regex_timer$(OBJ) $(LIBS)
|
||||
|
||||
regex_timer$(OBJ) : regex_timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) regex_timer.cpp
|
||||
|
||||
timer$(OBJ) : ../../../timer/timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) ../../../timer/timer.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
29
demo/timer/vc6.mak
Normal file
29
demo/timer/vc6.mak
Normal file
@ -0,0 +1,29 @@
|
||||
#
|
||||
# very basic VC6 makefile for timer
|
||||
#
|
||||
CXX=cl
|
||||
CXXFLAGS=-O2 -GX -DSTRICT -I../../../../ -I./
|
||||
LIBS=/link /LIBPATH:..\..\lib\vc6 kernel32.lib user32.lib
|
||||
EXE=.exe
|
||||
OBJ=.obj
|
||||
|
||||
LIBDEP= ../../../../boost/re_detail/regex_options.hpp ../../../../boost/re_detail/regex_config.hpp
|
||||
|
||||
regex_timer$(EXE) : regex_timer$(OBJ) timer$(OBJ)
|
||||
$(CXX) -o timer$(EXE) timer$(OBJ) regex_timer$(OBJ) $(LIBS)
|
||||
|
||||
regex_timer$(OBJ) : regex_timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) regex_timer.cpp
|
||||
|
||||
timer$(OBJ) : ../../../timer/timer.cpp $(LIBDEP)
|
||||
$(CXX) -c $(CXXFLAGS) ../../../timer/timer.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user