diff --git a/example/Jamfile b/example/Jamfile index f4ca6a56..ce32ebe0 100644 --- a/example/Jamfile +++ b/example/Jamfile @@ -1,24 +1,28 @@ subproject libs/regex/example ; -exe timer : timer/regex_timer.cpp +unit-test timer : timer/regex_timer.cpp ../build/libboost_regex$(SUFLIB) : ../../../ BOOST_REGEX_NO_LIB=1 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 ../build/libboost_regex$(SUFLIB) : ../../../ BOOST_REGEX_NO_LIB=1 BOOST_REGEX_STATIC_LINK=1 : - debug + release + : + -n boost/ ../../../boost/regex.hpp ; 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 ; -exe partial_regex_match : snippets/partial_regex_match.cpp +unit-test partial_regex_match : snippets/partial_regex_match.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -52,6 +56,8 @@ exe partial_regex_match : snippets/partial_regex_match.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + 1234-5678-8765-4 ; 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 ; -exe regex_match_example : snippets/regex_match_example.cpp +unit-test regex_match_example : snippets/regex_match_example.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -110,6 +116,8 @@ exe regex_match_example : snippets/regex_match_example.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + -auto ; 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 ; -exe regex_split_example_1 : snippets/regex_split_example_1.cpp +unit-test regex_split_example_1 : snippets/regex_split_example_1.cpp ../build/libboost_regex$(SUFLIB) : ../../../ @@ -144,6 +152,8 @@ exe regex_split_example_1 : snippets/regex_split_example_1.cpp BOOST_REGEX_STATIC_LINK=1 : debug + : + -auto ; 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 + diff --git a/example/snippets/partial_regex_match.cpp b/example/snippets/partial_regex_match.cpp index 5944df37..962e7f5f 100644 --- a/example/snippets/partial_regex_match.cpp +++ b/example/snippets/partial_regex_match.cpp @@ -29,7 +29,10 @@ int main(int argc, char* argv[]) { try{ std::string input; - std::cin >> input; + if(argc > 1) + input = argv[1]; + else + std::cin >> input; if(is_possible_card_number(input)) { std::cout << "Matched OK..." << std::endl; diff --git a/example/snippets/regex_match_example.cpp b/example/snippets/regex_match_example.cpp index 0066efcf..dbd77051 100644 --- a/example/snippets/regex_match_example.cpp +++ b/example/snippets/regex_match_example.cpp @@ -68,30 +68,35 @@ istream& getline(istream& is, std::string& s) } #endif -int main() +int main(int argc) { - 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; + std::string in, out; + do + { + if(argc == 1) + { + cout << "enter test string" << endl; + getline(cin, in); + if(in == "quit") + break; + } + else + in = "100 this is an ftp message text"; + 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; + } while(argc == 1); + return 0; } diff --git a/example/snippets/regex_split_example_1.cpp b/example/snippets/regex_split_example_1.cpp index bb6c16f7..db8efd7d 100644 --- a/example/snippets/regex_split_example_1.cpp +++ b/example/snippets/regex_split_example_1.cpp @@ -51,14 +51,19 @@ istream& getline(istream& is, std::string& s) #endif -int main() +int main(int argc) { string s; list l; do{ - cout << "Enter text to split (or \"quit\" to exit): "; - getline(cin, s); - if(s == "quit") break; + if(argc == 1) + { + 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); cout << result << " tokens found" << endl; cout << "The remaining text is: \"" << s << "\"" << endl; @@ -68,6 +73,6 @@ int main() l.pop_front(); cout << s << endl; } - }while(true); + }while(argc == 1); return 0; } diff --git a/example/timer/input_script.txt b/example/timer/input_script.txt new file mode 100644 index 00000000..0c068787 --- /dev/null +++ b/example/timer/input_script.txt @@ -0,0 +1,7 @@ +abc +aaaaaaaaaaabcccccccc +quit +^([0-9]+)(\-| |$)(.*)$ +100- this is a line of ftp response which contains a message string +quit +quit diff --git a/example/timer/regex_timer.cpp b/example/timer/regex_timer.cpp index 331f8d23..280c6eaf 100644 --- a/example/timer/regex_timer.cpp +++ b/example/timer/regex_timer.cpp @@ -15,14 +15,18 @@ #ifdef BOOST_RE_OLD_IOSTREAM #include +#include #else #include +#include using std::cout; using std::cin; using std::cerr; using std::istream; using std::ostream; using std::endl; +using std::ifstream; +using std::streambuf; #endif #include @@ -87,8 +91,21 @@ istream& getline(istream& is, std::string& s) #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::match_results sm; #ifndef BOOST_NO_WREGEX @@ -111,6 +128,8 @@ int main() { cout << "Enter expression (or \"quit\" to exit): "; getline(cin, s1); + if(argc == 2) + cout << endl << s1 << endl; if(s1 == "quit") break; #ifndef BOOST_NO_WREGEX @@ -143,6 +162,8 @@ int main() { cout << "Enter string to search (or \"quit\" to exit): "; getline(cin, s2); + if(argc == 2) + cout << endl << s2 << endl; if(s2 == "quit") break; @@ -313,6 +334,10 @@ int main() } regfree(&r); } + + if(pbuf) + cin.rdbuf(pbuf); + return 0; }