mirror of
https://github.com/boostorg/regex.git
synced 2025-07-29 12:07:28 +02:00
Updated regex examples and Jamfiles so that they are run as tests.
[SVN r12149]
This commit is contained in:
@ -1,24 +1,28 @@
|
|||||||
subproject libs/regex/example ;
|
subproject libs/regex/example ;
|
||||||
|
|
||||||
|
|
||||||
exe timer : timer/regex_timer.cpp
|
unit-test timer : timer/regex_timer.cpp
|
||||||
<lib>../build/libboost_regex$(SUFLIB)
|
<lib>../build/libboost_regex$(SUFLIB)
|
||||||
:
|
:
|
||||||
<include>../../../
|
<include>../../../
|
||||||
<define>BOOST_REGEX_NO_LIB=1
|
<define>BOOST_REGEX_NO_LIB=1
|
||||||
<define>BOOST_REGEX_STATIC_LINK=1
|
<define>BOOST_REGEX_STATIC_LINK=1
|
||||||
:
|
:
|
||||||
debug
|
release
|
||||||
|
:
|
||||||
|
timer/input_script.txt
|
||||||
;
|
;
|
||||||
|
|
||||||
exe jgrep : jgrep/jgrep.cpp jgrep/main.cpp
|
unit-test jgrep : jgrep/jgrep.cpp jgrep/main.cpp
|
||||||
<lib>../build/libboost_regex$(SUFLIB)
|
<lib>../build/libboost_regex$(SUFLIB)
|
||||||
:
|
:
|
||||||
<include>../../../
|
<include>../../../
|
||||||
<define>BOOST_REGEX_NO_LIB=1
|
<define>BOOST_REGEX_NO_LIB=1
|
||||||
<define>BOOST_REGEX_STATIC_LINK=1
|
<define>BOOST_REGEX_STATIC_LINK=1
|
||||||
:
|
:
|
||||||
debug
|
release
|
||||||
|
:
|
||||||
|
-n boost/ ../../../boost/regex.hpp
|
||||||
;
|
;
|
||||||
|
|
||||||
unit-test credit_card_example : snippets/credit_card_example.cpp
|
unit-test credit_card_example : snippets/credit_card_example.cpp
|
||||||
@ -44,7 +48,7 @@ unit-test partial_regex_grep : snippets/partial_regex_grep.cpp
|
|||||||
../index.htm
|
../index.htm
|
||||||
;
|
;
|
||||||
|
|
||||||
exe partial_regex_match : snippets/partial_regex_match.cpp
|
unit-test partial_regex_match : snippets/partial_regex_match.cpp
|
||||||
<lib>../build/libboost_regex$(SUFLIB)
|
<lib>../build/libboost_regex$(SUFLIB)
|
||||||
:
|
:
|
||||||
<include>../../../
|
<include>../../../
|
||||||
@ -52,6 +56,8 @@ exe partial_regex_match : snippets/partial_regex_match.cpp
|
|||||||
<define>BOOST_REGEX_STATIC_LINK=1
|
<define>BOOST_REGEX_STATIC_LINK=1
|
||||||
:
|
:
|
||||||
debug
|
debug
|
||||||
|
:
|
||||||
|
1234-5678-8765-4
|
||||||
;
|
;
|
||||||
|
|
||||||
unit-test regex_grep_example_1 : snippets/regex_grep_example_1.cpp
|
unit-test regex_grep_example_1 : snippets/regex_grep_example_1.cpp
|
||||||
@ -102,7 +108,7 @@ unit-test regex_grep_example_4 : snippets/regex_grep_example_4.cpp
|
|||||||
../../../boost/smart_ptr.hpp
|
../../../boost/smart_ptr.hpp
|
||||||
;
|
;
|
||||||
|
|
||||||
exe regex_match_example : snippets/regex_match_example.cpp
|
unit-test regex_match_example : snippets/regex_match_example.cpp
|
||||||
<lib>../build/libboost_regex$(SUFLIB)
|
<lib>../build/libboost_regex$(SUFLIB)
|
||||||
:
|
:
|
||||||
<include>../../../
|
<include>../../../
|
||||||
@ -110,6 +116,8 @@ exe regex_match_example : snippets/regex_match_example.cpp
|
|||||||
<define>BOOST_REGEX_STATIC_LINK=1
|
<define>BOOST_REGEX_STATIC_LINK=1
|
||||||
:
|
:
|
||||||
debug
|
debug
|
||||||
|
:
|
||||||
|
-auto
|
||||||
;
|
;
|
||||||
|
|
||||||
unit-test regex_merge_example : snippets/regex_merge_example.cpp
|
unit-test regex_merge_example : snippets/regex_merge_example.cpp
|
||||||
@ -136,7 +144,7 @@ unit-test regex_search_example : snippets/regex_search_example.cpp
|
|||||||
../../../boost/smart_ptr.hpp
|
../../../boost/smart_ptr.hpp
|
||||||
;
|
;
|
||||||
|
|
||||||
exe regex_split_example_1 : snippets/regex_split_example_1.cpp
|
unit-test regex_split_example_1 : snippets/regex_split_example_1.cpp
|
||||||
<lib>../build/libboost_regex$(SUFLIB)
|
<lib>../build/libboost_regex$(SUFLIB)
|
||||||
:
|
:
|
||||||
<include>../../../
|
<include>../../../
|
||||||
@ -144,6 +152,8 @@ exe regex_split_example_1 : snippets/regex_split_example_1.cpp
|
|||||||
<define>BOOST_REGEX_STATIC_LINK=1
|
<define>BOOST_REGEX_STATIC_LINK=1
|
||||||
:
|
:
|
||||||
debug
|
debug
|
||||||
|
:
|
||||||
|
-auto
|
||||||
;
|
;
|
||||||
|
|
||||||
unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp
|
unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp
|
||||||
@ -164,3 +174,4 @@ unit-test regex_split_example_2 : snippets/regex_split_example_2.cpp
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,10 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
std::string input;
|
std::string input;
|
||||||
std::cin >> input;
|
if(argc > 1)
|
||||||
|
input = argv[1];
|
||||||
|
else
|
||||||
|
std::cin >> input;
|
||||||
if(is_possible_card_number(input))
|
if(is_possible_card_number(input))
|
||||||
{
|
{
|
||||||
std::cout << "Matched OK..." << std::endl;
|
std::cout << "Matched OK..." << std::endl;
|
||||||
|
@ -68,30 +68,35 @@ istream& getline(istream& is, std::string& s)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main()
|
int main(int argc)
|
||||||
{
|
{
|
||||||
std::string in, out;
|
std::string in, out;
|
||||||
while(true)
|
do
|
||||||
{
|
{
|
||||||
cout << "enter test string" << endl;
|
if(argc == 1)
|
||||||
getline(cin, in);
|
{
|
||||||
if(in == "quit")
|
cout << "enter test string" << endl;
|
||||||
break;
|
getline(cin, in);
|
||||||
int result;
|
if(in == "quit")
|
||||||
result = process_ftp(in.c_str(), &out);
|
break;
|
||||||
if(result != -1)
|
}
|
||||||
{
|
else
|
||||||
cout << "Match found:" << endl;
|
in = "100 this is an ftp message text";
|
||||||
cout << "Response code: " << result << endl;
|
int result;
|
||||||
cout << "Message text: " << out << endl;
|
result = process_ftp(in.c_str(), &out);
|
||||||
}
|
if(result != -1)
|
||||||
else
|
{
|
||||||
{
|
cout << "Match found:" << endl;
|
||||||
cout << "Match not found" << endl;
|
cout << "Response code: " << result << endl;
|
||||||
}
|
cout << "Message text: " << out << endl;
|
||||||
cout << endl;
|
}
|
||||||
}
|
else
|
||||||
return 0;
|
{
|
||||||
|
cout << "Match not found" << endl;
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
} while(argc == 1);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,14 +51,19 @@ istream& getline(istream& is, std::string& s)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main(int argc)
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
list<string> l;
|
list<string> l;
|
||||||
do{
|
do{
|
||||||
cout << "Enter text to split (or \"quit\" to exit): ";
|
if(argc == 1)
|
||||||
getline(cin, s);
|
{
|
||||||
if(s == "quit") break;
|
cout << "Enter text to split (or \"quit\" to exit): ";
|
||||||
|
getline(cin, s);
|
||||||
|
if(s == "quit") break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s = "This is a string of tokens";
|
||||||
unsigned result = tokenise(l, s);
|
unsigned result = tokenise(l, s);
|
||||||
cout << result << " tokens found" << endl;
|
cout << result << " tokens found" << endl;
|
||||||
cout << "The remaining text is: \"" << s << "\"" << endl;
|
cout << "The remaining text is: \"" << s << "\"" << endl;
|
||||||
@ -68,6 +73,6 @@ int main()
|
|||||||
l.pop_front();
|
l.pop_front();
|
||||||
cout << s << endl;
|
cout << s << endl;
|
||||||
}
|
}
|
||||||
}while(true);
|
}while(argc == 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
7
example/timer/input_script.txt
Normal file
7
example/timer/input_script.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
abc
|
||||||
|
aaaaaaaaaaabcccccccc
|
||||||
|
quit
|
||||||
|
^([0-9]+)(\-| |$)(.*)$
|
||||||
|
100- this is a line of ftp response which contains a message string
|
||||||
|
quit
|
||||||
|
quit
|
@ -15,14 +15,18 @@
|
|||||||
|
|
||||||
#ifdef BOOST_RE_OLD_IOSTREAM
|
#ifdef BOOST_RE_OLD_IOSTREAM
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
|
#include <fstream.h>
|
||||||
#else
|
#else
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::istream;
|
using std::istream;
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
using std::ifstream;
|
||||||
|
using std::streambuf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -87,8 +91,21 @@ istream& getline(istream& is, std::string& s)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main(int argc, char**argv)
|
||||||
{
|
{
|
||||||
|
ifstream ifs;
|
||||||
|
streambuf* pbuf = 0;
|
||||||
|
if(argc == 2)
|
||||||
|
{
|
||||||
|
ifs.open(argv[1]);
|
||||||
|
if(ifs.bad())
|
||||||
|
{
|
||||||
|
cout << "Bad filename: " << argv[1] << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pbuf = cin.rdbuf(ifs.rdbuf());
|
||||||
|
}
|
||||||
|
|
||||||
boost::regex ex;
|
boost::regex ex;
|
||||||
boost::match_results<std::string::const_iterator> sm;
|
boost::match_results<std::string::const_iterator> sm;
|
||||||
#ifndef BOOST_NO_WREGEX
|
#ifndef BOOST_NO_WREGEX
|
||||||
@ -111,6 +128,8 @@ int main()
|
|||||||
{
|
{
|
||||||
cout << "Enter expression (or \"quit\" to exit): ";
|
cout << "Enter expression (or \"quit\" to exit): ";
|
||||||
getline(cin, s1);
|
getline(cin, s1);
|
||||||
|
if(argc == 2)
|
||||||
|
cout << endl << s1 << endl;
|
||||||
if(s1 == "quit")
|
if(s1 == "quit")
|
||||||
break;
|
break;
|
||||||
#ifndef BOOST_NO_WREGEX
|
#ifndef BOOST_NO_WREGEX
|
||||||
@ -143,6 +162,8 @@ int main()
|
|||||||
{
|
{
|
||||||
cout << "Enter string to search (or \"quit\" to exit): ";
|
cout << "Enter string to search (or \"quit\" to exit): ";
|
||||||
getline(cin, s2);
|
getline(cin, s2);
|
||||||
|
if(argc == 2)
|
||||||
|
cout << endl << s2 << endl;
|
||||||
if(s2 == "quit")
|
if(s2 == "quit")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -313,6 +334,10 @@ int main()
|
|||||||
}
|
}
|
||||||
regfree(&r);
|
regfree(&r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pbuf)
|
||||||
|
cin.rdbuf(pbuf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user