summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/regex/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/regex/example')
-rw-r--r--src/boost/libs/regex/example/Jamfile.v281
-rw-r--r--src/boost/libs/regex/example/grep/grep.cpp217
-rw-r--r--src/boost/libs/regex/example/snippets/CMakeLists.txt30
-rw-r--r--src/boost/libs/regex/example/snippets/captures_example.cpp68
-rw-r--r--src/boost/libs/regex/example/snippets/credit_card_example.cpp67
-rw-r--r--src/boost/libs/regex/example/snippets/icu_example.cpp188
-rw-r--r--src/boost/libs/regex/example/snippets/mfc_example.cpp162
-rw-r--r--src/boost/libs/regex/example/snippets/partial_regex_grep.cpp109
-rw-r--r--src/boost/libs/regex/example/snippets/partial_regex_iterate.cpp118
-rw-r--r--src/boost/libs/regex/example/snippets/partial_regex_match.cpp69
-rw-r--r--src/boost/libs/regex/example/snippets/regex_grep_example_1.cpp131
-rw-r--r--src/boost/libs/regex/example/snippets/regex_grep_example_2.cpp123
-rw-r--r--src/boost/libs/regex/example/snippets/regex_grep_example_3.cpp153
-rw-r--r--src/boost/libs/regex/example/snippets/regex_grep_example_4.cpp155
-rw-r--r--src/boost/libs/regex/example/snippets/regex_iterator_example.cpp114
-rw-r--r--src/boost/libs/regex/example/snippets/regex_match_example.cpp105
-rw-r--r--src/boost/libs/regex/example/snippets/regex_merge_example.cpp137
-rw-r--r--src/boost/libs/regex/example/snippets/regex_replace_example.cpp138
-rw-r--r--src/boost/libs/regex/example/snippets/regex_search_example.cpp129
-rw-r--r--src/boost/libs/regex/example/snippets/regex_split_example_1.cpp76
-rw-r--r--src/boost/libs/regex/example/snippets/regex_split_example_2.cpp86
-rw-r--r--src/boost/libs/regex/example/snippets/regex_token_iterator_eg_1.cpp72
-rw-r--r--src/boost/libs/regex/example/snippets/regex_token_iterator_eg_2.cpp89
-rw-r--r--src/boost/libs/regex/example/timer/bc55.mak51
-rw-r--r--src/boost/libs/regex/example/timer/bcb4.mak51
-rw-r--r--src/boost/libs/regex/example/timer/bcb5.mak51
-rw-r--r--src/boost/libs/regex/example/timer/gcc.mak38
-rw-r--r--src/boost/libs/regex/example/timer/input_script.txt14
-rw-r--r--src/boost/libs/regex/example/timer/regex_timer.cpp375
-rw-r--r--src/boost/libs/regex/example/timer/vc6-stlport.mak39
-rw-r--r--src/boost/libs/regex/example/timer/vc6.mak39
31 files changed, 3275 insertions, 0 deletions
diff --git a/src/boost/libs/regex/example/Jamfile.v2 b/src/boost/libs/regex/example/Jamfile.v2
new file mode 100644
index 000000000..dd958c7da
--- /dev/null
+++ b/src/boost/libs/regex/example/Jamfile.v2
@@ -0,0 +1,81 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+
+project
+ : requirements
+ <threading>multi
+ <link>shared:<define>BOOST_REGEX_DYN_LINK=1
+ # There are unidentified linker problems on these platforms:
+ <toolset>mipspro-7.4:<link>static
+ <toolset>sun-5.9:<link>static
+ <toolset>msvc:<warnings>all
+ <toolset>gcc:<warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <define>U_USING_ICU_NAMESPACE=0
+ #<toolset>gcc-mw:<link>static
+ #<toolset>gcc-mingw:<link>static
+ <toolset>gcc-cygwin:<link>static
+ ;
+
+rule regex-test-run ( sources + : input * : name * )
+{
+ return [
+ run
+ # sources
+ $(sources)
+ # dependencies
+ ../build//boost_regex
+ : # additional args
+ $(input)
+ : # test-files
+ : # requirements
+ <toolset>msvc-7.1:<define>TEST_MFC=1 <toolset>msvc-7.0:<define>TEST_MFC=1
+ : # test name
+ $(name)
+ ] ;
+}
+
+test-suite regex-examples :
+
+[ regex-test-run timer/regex_timer.cpp : $(BOOST_ROOT)/libs/regex/example/timer/input_script.txt ]
+[ regex-test-run grep/grep.cpp ../../program_options/build//boost_program_options/<link>static : -n -b $(BOOST_ROOT)/boost/regex.hpp $(BOOST_ROOT)/boost/type_traits.hpp : test_grep ]
+[ regex-test-run snippets/credit_card_example.cpp ]
+[ regex-test-run snippets/mfc_example.cpp ]
+[ regex-test-run snippets/icu_example.cpp ]
+[ regex-test-run snippets/partial_regex_grep.cpp : $(BOOST_ROOT)/libs/regex/index.htm ]
+[ regex-test-run snippets/partial_regex_iterate.cpp : $(BOOST_ROOT)/libs/regex/index.htm ]
+[ regex-test-run snippets/partial_regex_match.cpp : 1234-5678-8765-4 ]
+[ regex-test-run snippets/regex_grep_example_1.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_grep_example_2.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_grep_example_3.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_grep_example_4.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_match_example.cpp : -auto ]
+[ regex-test-run snippets/regex_merge_example.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_replace_example.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_search_example.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ regex-test-run snippets/regex_split_example_1.cpp : -auto ]
+[ regex-test-run snippets/regex_split_example_2.cpp : $(BOOST_ROOT)/libs/regex/doc/html/index.html ]
+[ regex-test-run snippets/regex_token_iterator_eg_1.cpp : -auto ]
+[ regex-test-run snippets/regex_token_iterator_eg_2.cpp : $(BOOST_ROOT)/libs/regex/doc/html/index.html ]
+[ regex-test-run snippets/regex_iterator_example.cpp : $(BOOST_ROOT)/boost/rational.hpp ]
+[ run snippets/captures_example.cpp
+ ../test/captures//boost_regex_extra
+ : : : <threading>multi <define>BOOST_REGEX_MATCH_EXTRA=1 ]
+
+;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/grep/grep.cpp b/src/boost/libs/regex/example/grep/grep.cpp
new file mode 100644
index 000000000..5c212ea68
--- /dev/null
+++ b/src/boost/libs/regex/example/grep/grep.cpp
@@ -0,0 +1,217 @@
+/*
+ *
+ * Copyright (c) 2004
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+
+#ifdef BOOST_MSVC
+#pragma warning(disable:4512 4244)
+#endif
+
+#include <boost/program_options.hpp>
+
+namespace po = boost::program_options;
+
+int after_context;
+int before_context;
+bool print_byte_offset;
+bool count_only;
+std::string pattern;
+bool print_non_matching_files;
+bool files_only;
+bool print_line_numbers;
+
+boost::regex_constants::syntax_option_type flags = boost::regex_constants::basic;
+boost::regex re;
+boost::smatch what;
+std::string current_file;
+int file_count;
+
+void process_stream(std::istream& is)
+{
+ std::string line;
+ int match_found = 0;
+ int linenum = 1;
+ while(std::getline(is, line))
+ {
+ bool result = boost::regex_search(line, what, re);
+ if(result)
+ {
+ if(print_non_matching_files)
+ return;
+ if(files_only)
+ {
+ std::cout << current_file << std::endl;
+ return;
+ }
+ if(!match_found && !count_only && (file_count > 1))
+ {
+ std::cout << current_file << ":\n";
+ }
+ ++match_found;
+ if(!count_only)
+ {
+ if(print_line_numbers)
+ {
+ std::cout << linenum << ":";
+ }
+ if(print_byte_offset)
+ {
+ std::cout << what.position() << ":";
+ }
+ std::cout << what[0] << std::endl;
+ }
+ }
+ ++linenum;
+ }
+ if(count_only && match_found)
+ {
+ std::cout << match_found << " matches found in file " << current_file << std::endl;
+ }
+ else if(print_non_matching_files && !match_found)
+ {
+ std::cout << current_file << std::endl;
+ }
+}
+
+void process_file(const std::string& name)
+{
+ current_file = name;
+ std::ifstream is(name.c_str());
+ if(is.bad())
+ {
+ std::cerr << "Unable to open file " << name << std::endl;
+ }
+ process_stream(is);
+}
+
+int main(int argc, char * argv[])
+{
+ try{
+ po::options_description opts("Options");
+ opts.add_options()
+ ("help,h", "produce help message")
+ //("after-context,A", po::value<int>(&after_context)->default_value(0), "Print arg lines of trailing context after matching lines. Places a line containing -- between contiguous groups of matches.")
+ //("before-context,B", po::value<int>(&before_context)->default_value(0), "Print arg lines of leading context before matching lines. Places a line containing -- between contiguous groups of matches.")
+ //("context,C", po::value<int>(), "Print arg lines of output context. Places a line containing -- between contiguous groups of matches.")
+ ("byte-offset,b", "Print the byte offset within the input file before each line of output.")
+ ("count,c", "Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.")
+ ("extended-regexp,E", "Interpret PATTERN as an POSIX-extended regular expression.")
+ ("perl-regexp,P", "Interpret PATTERN as a Perl regular expression.")
+ //("regexp,e", po::value<std::string>(&pattern), "Use PATTERN as the pattern; useful to protect patterns beginning with -.")
+ ("basic-regexp,G", "Interpret arg as a POSIX-basic regular expression (see below). This is the default.")
+ ("ignore-case,i", "Ignore case distinctions in both the PATTERN and the input files.")
+ ("files-without-match,L", "Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.")
+ ("files-with-matches,l", "Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.")
+ ("line-number,n", "Prefix each line of output with the line number within its input file.")
+ ;
+ // Hidden options, will be allowed both on command line and
+ // in config file, but will not be shown to the user.
+ po::options_description hidden("Hidden options");
+ hidden.add_options()
+ ("input-file", po::value< std::vector<std::string> >(), "input file")
+ ("input-pattern", po::value< std::string >(), "input file")
+ ;
+
+ po::options_description cmdline_options;
+ cmdline_options.add(opts).add(hidden);
+
+ po::positional_options_description p;
+ p.add("input-pattern", 1);
+ p.add("input-file", -1);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).options(cmdline_options)/*.options(hidden)*/.positional(p).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help"))
+ {
+ std::cout << opts << "\n";
+ return 0;
+ }
+ if (vm.count("context"))
+ {
+ after_context = vm["context"].as< int >();
+ before_context = after_context;
+ }
+ if(vm.count("extended-regexp"))
+ {
+ flags = boost::regex_constants::extended;
+ }
+ if(vm.count("basic-regexp"))
+ {
+ flags = boost::regex_constants::basic;
+ }
+ if(vm.count("perl-regexp"))
+ {
+ flags = boost::regex_constants::perl;
+ }
+ if(vm.count("ignore-case"))
+ {
+ flags |= boost::regex_constants::icase;
+ }
+ if(vm.count("byte-offset"))
+ {
+ print_byte_offset = true;
+ }
+ if(vm.count("count"))
+ {
+ count_only = true;
+ }
+ if(vm.count("files-without-match"))
+ {
+ print_non_matching_files = true;
+ }
+ if(vm.count("files-with-matches"))
+ {
+ files_only = true;
+ }
+ if(vm.count("line-number"))
+ {
+ print_line_numbers = true;
+ }
+ if(vm.count("input-pattern"))
+ {
+ pattern = vm["input-pattern"].as< std::string >();
+ re.assign(pattern, flags);
+ }
+ else
+ {
+ std::cerr << "No pattern specified" << std::endl;
+ return 1;
+ }
+ if (vm.count("input-file"))
+ {
+ const std::vector<std::string>& files = vm["input-file"].as< std::vector<std::string> >();
+ file_count = files.size();
+ for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i)
+ {
+ process_file(*i);
+ }
+ }
+ else
+ {
+ // no input files, scan stdin instead:
+ process_stream(std::cin);
+ }
+
+ }
+ catch(const std::exception& e)
+ {
+ std::cerr << e.what() << std::endl;
+ }
+
+ return 0;
+}
+
diff --git a/src/boost/libs/regex/example/snippets/CMakeLists.txt b/src/boost/libs/regex/example/snippets/CMakeLists.txt
new file mode 100644
index 000000000..f672785bd
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Copyright 2019 Mike Dev
+# Distributed under the Boost Software License, Version 1.0.
+# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
+#
+# NOTE: CMake support for Boost.Regex is currently experimental at best
+# and we are currently only building a few examples
+
+set(examples
+ partial_regex_grep
+ partial_regex_iterate
+ partial_regex_match
+ regex_grep_example_1
+ regex_grep_example_2
+ regex_grep_example_3
+ regex_grep_example_4
+ regex_iterator_example
+ regex_match_example
+ regex_merge_example
+ regex_replace_example
+ regex_search_example
+ regex_split_example_1
+ regex_split_example_2
+ regex_token_iterator_eg_1
+ regex_token_iterator_eg_2
+)
+
+foreach( example IN LISTS examples )
+ add_executable( boost_regex_ex_${example} ${example}.cpp )
+ target_link_libraries( boost_regex_ex_${example} Boost::regex )
+endforeach()
diff --git a/src/boost/libs/regex/example/snippets/captures_example.cpp b/src/boost/libs/regex/example/snippets/captures_example.cpp
new file mode 100644
index 000000000..d1ff1e9f8
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/captures_example.cpp
@@ -0,0 +1,68 @@
+/*
+ *
+ * Copyright (c) 2003-2004
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE captures_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: Demonstrate the behaviour of captures.
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+
+
+void print_captures(const std::string& regx, const std::string& text)
+{
+ boost::regex e(regx);
+ boost::smatch what;
+ std::cout << "Expression: \"" << regx << "\"\n";
+ std::cout << "Text: \"" << text << "\"\n";
+ if(boost::regex_match(text, what, e, boost::match_extra))
+ {
+ unsigned i, j;
+ std::cout << "** Match found **\n Sub-Expressions:\n";
+ for(i = 0; i < what.size(); ++i)
+ std::cout << " $" << i << " = \"" << what[i] << "\"\n";
+ std::cout << " Captures:\n";
+ for(i = 0; i < what.size(); ++i)
+ {
+ std::cout << " $" << i << " = {";
+ for(j = 0; j < what.captures(i).size(); ++j)
+ {
+ if(j)
+ std::cout << ", ";
+ else
+ std::cout << " ";
+ std::cout << "\"" << what.captures(i)[j] << "\"";
+ }
+ std::cout << " }\n";
+ }
+ }
+ else
+ {
+ std::cout << "** No Match found **\n";
+ }
+}
+
+int main(int , char* [])
+{
+ print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
+ print_captures("a(b+|((c)*))+d", "abd");
+ print_captures("(.*)bar|(.*)bah", "abcbar");
+ print_captures("(.*)bar|(.*)bah", "abcbah");
+ print_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party");
+ print_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party");
+ print_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party");
+ print_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party");
+ return 0;
+}
+
diff --git a/src/boost/libs/regex/example/snippets/credit_card_example.cpp b/src/boost/libs/regex/example/snippets/credit_card_example.cpp
new file mode 100644
index 000000000..1620d8cca
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/credit_card_example.cpp
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE credit_card_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: Credit card number formatting code.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+
+bool validate_card_format(const std::string& s)
+{
+ static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
+ return boost::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 boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed);
+}
+
+std::string human_readable_card_number(const std::string& s)
+{
+ return boost::regex_replace(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", };
+ int i;
+ for(i = 0; i < 4; ++i)
+ {
+ cout << "validate_card_format(\"" << s[i] << "\") returned " << validate_card_format(s[i]) << endl;
+ }
+ for(i = 0; i < 4; ++i)
+ {
+ cout << "machine_readable_card_number(\"" << s[i] << "\") returned " << machine_readable_card_number(s[i]) << endl;
+ }
+ for(i = 0; i < 4; ++i)
+ {
+ cout << "human_readable_card_number(\"" << s[i] << "\") returned " << human_readable_card_number(s[i]) << endl;
+ }
+ return 0;
+}
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/icu_example.cpp b/src/boost/libs/regex/example/snippets/icu_example.cpp
new file mode 100644
index 000000000..6d1fc3bec
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/icu_example.cpp
@@ -0,0 +1,188 @@
+/*
+ *
+ * Copyright (c) 2004
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE mfc_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: examples of using Boost.Regex with MFC and ATL string types.
+ */
+
+#include <boost/regex/config.hpp>
+
+#ifdef BOOST_HAS_ICU
+
+#include <boost/regex/icu.hpp>
+#include <iostream>
+#include <assert.h>
+
+//
+// Find out if *password* meets our password requirements,
+// as defined by the regular expression *requirements*.
+//
+bool is_valid_password(const U_NAMESPACE_QUALIFIER UnicodeString& password, const U_NAMESPACE_QUALIFIER UnicodeString& requirements)
+{
+ return boost::u32regex_match(password, boost::make_u32regex(requirements));
+}
+
+//
+// Extract filename part of a path from a UTF-8 encoded std::string and return the result
+// as another std::string:
+//
+std::string get_filename(const std::string& path)
+{
+ boost::u32regex r = boost::make_u32regex("(?:\\A|.*\\\\)([^\\\\]+)");
+ boost::smatch what;
+ if(boost::u32regex_match(path, what, r))
+ {
+ // extract $1 as a std::string:
+ return what.str(1);
+ }
+ else
+ {
+ throw std::runtime_error("Invalid pathname");
+ }
+}
+
+U_NAMESPACE_QUALIFIER UnicodeString extract_greek(const U_NAMESPACE_QUALIFIER UnicodeString& text)
+{
+ // searches through some UTF-16 encoded text for a block encoded in Greek,
+ // this expression is imperfect, but the best we can do for now - searching
+ // for specific scripts is actually pretty hard to do right.
+ boost::u32regex r = boost::make_u32regex(L"[\\x{370}-\\x{3FF}](?:[^[:L*:]]|[\\x{370}-\\x{3FF}])*");
+ boost::u16match what;
+ if(boost::u32regex_search(text, what, r))
+ {
+ // extract $0 as a UnicodeString:
+ return U_NAMESPACE_QUALIFIER UnicodeString(what[0].first, what.length(0));
+ }
+ else
+ {
+ throw std::runtime_error("No Greek found!");
+ }
+}
+
+void enumerate_currencies(const std::string& text)
+{
+ // enumerate and print all the currency symbols, along
+ // with any associated numeric values:
+ const char* re =
+ "([[:Sc:]][[:Cf:][:Cc:][:Z*:]]*)?"
+ "([[:Nd:]]+(?:[[:Po:]][[:Nd:]]+)?)?"
+ "(?(1)"
+ "|(?(2)"
+ "[[:Cf:][:Cc:][:Z*:]]*"
+ ")"
+ "[[:Sc:]]"
+ ")";
+ boost::u32regex r = boost::make_u32regex(re);
+ boost::u32regex_iterator<std::string::const_iterator> i(boost::make_u32regex_iterator(text, r)), j;
+ while(i != j)
+ {
+ std::cout << (*i)[0] << std::endl;
+ ++i;
+ }
+}
+
+void enumerate_currencies2(const std::string& text)
+{
+ // enumerate and print all the currency symbols, along
+ // with any associated numeric values:
+ const char* re =
+ "([[:Sc:]][[:Cf:][:Cc:][:Z*:]]*)?"
+ "([[:Nd:]]+(?:[[:Po:]][[:Nd:]]+)?)?"
+ "(?(1)"
+ "|(?(2)"
+ "[[:Cf:][:Cc:][:Z*:]]*"
+ ")"
+ "[[:Sc:]]"
+ ")";
+ boost::u32regex r = boost::make_u32regex(re);
+ boost::u32regex_token_iterator<std::string::const_iterator>
+ i(boost::make_u32regex_token_iterator(text, r, 1)), j;
+ while(i != j)
+ {
+ std::cout << *i << std::endl;
+ ++i;
+ }
+}
+
+
+//
+// Take a credit card number as a string of digits,
+// and reformat it as a human readable string with "-"
+// separating each group of four digit;,
+// note that we're mixing a UTF-32 regex, with a UTF-16
+// string and a UTF-8 format specifier, and it still all
+// just works:
+//
+const boost::u32regex e = boost::make_u32regex("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
+const char* human_format = "$1-$2-$3-$4";
+
+U_NAMESPACE_QUALIFIER UnicodeString human_readable_card_number(const U_NAMESPACE_QUALIFIER UnicodeString& s)
+{
+ return boost::u32regex_replace(s, e, human_format);
+}
+
+
+int main()
+{
+ // password checks using u32regex_match:
+ U_NAMESPACE_QUALIFIER UnicodeString pwd = "abcDEF---";
+ U_NAMESPACE_QUALIFIER UnicodeString pwd_check = "(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}";
+ bool b = is_valid_password(pwd, pwd_check);
+ assert(b);
+ pwd = "abcD-";
+ b = is_valid_password(pwd, pwd_check);
+ assert(!b);
+ // filename extraction with u32regex_match:
+ std::string file = "abc.hpp";
+ file = get_filename(file);
+ assert(file == "abc.hpp");
+ file = "c:\\a\\b\\c\\d.h";
+ file = get_filename(file);
+ assert(file == "d.h");
+
+ // Greek text extraction with u32regex_search:
+ const UChar t[] = {
+ 'S', 'o', 'm', 'e', ' ', 'w', 'h', 'e', 'r', 'e', ' ', 'i', 'n', 0x0391, 0x039D, 0x0395, 0x0398, 0x0391, 0
+ };
+ const UChar g[] = {
+ 0x0391, 0x039D, 0x0395, 0x0398, 0x0391, 0
+ };
+ U_NAMESPACE_QUALIFIER UnicodeString text = t;
+ U_NAMESPACE_QUALIFIER UnicodeString greek = extract_greek(text);
+ assert(greek == g);
+
+ // extract currency symbols with associated value, use iterator interface:
+ std::string text2 = " $100.23 or \xC2\xA3""198.12 "; // \xC2\xA3 is the pound sign encoded in UTF-8
+ enumerate_currencies(text2);
+ enumerate_currencies2(text2);
+
+ U_NAMESPACE_QUALIFIER UnicodeString credit_card_number = "1234567887654321";
+ credit_card_number = human_readable_card_number(credit_card_number);
+ assert(credit_card_number == "1234-5678-8765-4321");
+ return 0;
+}
+
+#else
+
+#include <iostream>
+
+int main()
+{
+ std::cout << "<NOTE>ICU support not enabled, feature unavailable</NOTE>";
+ return 0;
+}
+
+
+#endif
+
diff --git a/src/boost/libs/regex/example/snippets/mfc_example.cpp b/src/boost/libs/regex/example/snippets/mfc_example.cpp
new file mode 100644
index 000000000..4b3ae62ba
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/mfc_example.cpp
@@ -0,0 +1,162 @@
+/*
+ *
+ * Copyright (c) 2004
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE mfc_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: examples of using Boost.Regex with MFC and ATL string types.
+ */
+
+#ifdef TEST_MFC
+
+#include <boost/regex/mfc.hpp>
+#include <cstringt.h>
+#include <atlstr.h>
+#include <assert.h>
+#include <tchar.h>
+#include <iostream>
+
+#ifdef _UNICODE
+#define cout wcout
+#endif
+
+//
+// Find out if *password* meets our password requirements,
+// as defined by the regular expression *requirements*.
+//
+bool is_valid_password(const CString& password, const CString& requirements)
+{
+ return boost::regex_match(password, boost::make_regex(requirements));
+}
+
+//
+// Extract filename part of a path from a CString and return the result
+// as another CString:
+//
+CString get_filename(const CString& path)
+{
+ boost::tregex r(__T("(?:\\A|.*\\\\)([^\\\\]+)"));
+ boost::tmatch what;
+ if(boost::regex_match(path, what, r))
+ {
+ // extract $1 as a CString:
+ return CString(what[1].first, what.length(1));
+ }
+ else
+ {
+ throw std::runtime_error("Invalid pathname");
+ }
+}
+
+CString extract_postcode(const CString& address)
+{
+ // searches throw address for a UK postcode and returns the result,
+ // the expression used is by Phil A. on www.regxlib.com:
+ boost::tregex r(__T("^(([A-Z]{1,2}[0-9]{1,2})|([A-Z]{1,2}[0-9][A-Z]))\\s?([0-9][A-Z]{2})$"));
+ boost::tmatch what;
+ if(boost::regex_search(address, what, r))
+ {
+ // extract $0 as a CString:
+ return CString(what[0].first, what.length());
+ }
+ else
+ {
+ throw std::runtime_error("No postcode found");
+ }
+}
+
+void enumerate_links(const CString& html)
+{
+ // enumerate and print all the <a> links in some HTML text,
+ // the expression used is by Andew Lee on www.regxlib.com:
+ boost::tregex r(__T("href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"));
+ boost::tregex_iterator i(boost::make_regex_iterator(html, r)), j;
+ while(i != j)
+ {
+ std::cout << (*i)[1] << std::endl;
+ ++i;
+ }
+}
+
+void enumerate_links2(const CString& html)
+{
+ // enumerate and print all the <a> links in some HTML text,
+ // the expression used is by Andew Lee on www.regxlib.com:
+ boost::tregex r(__T("href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"));
+ boost::tregex_token_iterator i(boost::make_regex_token_iterator(html, r, 1)), j;
+ while(i != j)
+ {
+ std::cout << *i << std::endl;
+ ++i;
+ }
+}
+
+//
+// Take a credit card number as a string of digits,
+// and reformat it as a human readable string with "-"
+// separating each group of four digits:
+//
+const boost::tregex e(__T("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"));
+const CString human_format = __T("$1-$2-$3-$4");
+
+CString human_readable_card_number(const CString& s)
+{
+ return boost::regex_replace(s, e, human_format);
+}
+
+
+int main()
+{
+ // password checks using regex_match:
+ CString pwd = "abcDEF---";
+ CString pwd_check = "(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}";
+ bool b = is_valid_password(pwd, pwd_check);
+ assert(b);
+ pwd = "abcD-";
+ b = is_valid_password(pwd, pwd_check);
+ assert(!b);
+
+ // filename extraction with regex_match:
+ CString file = "abc.hpp";
+ file = get_filename(file);
+ assert(file == "abc.hpp");
+ file = "c:\\a\\b\\c\\d.h";
+ file = get_filename(file);
+ assert(file == "d.h");
+
+ // postcode extraction with regex_search:
+ CString address = "Joe Bloke, 001 Somestreet, Somewhere,\nPL2 8AB";
+ CString postcode = extract_postcode(address);
+ assert(postcode = "PL2 8NV");
+
+ // html link extraction with regex_iterator:
+ CString text = "<dt><a href=\"syntax_perl.html\">Perl Regular Expressions</a></dt><dt><a href=\"syntax_extended.html\">POSIX-Extended Regular Expressions</a></dt><dt><a href=\"syntax_basic.html\">POSIX-Basic Regular Expressions</a></dt>";
+ enumerate_links(text);
+ enumerate_links2(text);
+
+ CString credit_card_number = "1234567887654321";
+ credit_card_number = human_readable_card_number(credit_card_number);
+ assert(credit_card_number == "1234-5678-8765-4321");
+ return 0;
+}
+
+#else
+
+#include <iostream>
+
+int main()
+{
+ std::cout << "<NOTE>MFC support not enabled, feature unavailable</NOTE>";
+ return 0;
+}
+
+#endif
diff --git a/src/boost/libs/regex/example/snippets/partial_regex_grep.cpp b/src/boost/libs/regex/example/snippets/partial_regex_grep.cpp
new file mode 100644
index 000000000..9934ebc58
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/partial_regex_grep.cpp
@@ -0,0 +1,109 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE partial_regex_grep.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: Search example using partial matches.
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <cstring>
+
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std{ using ::memmove; }
+#endif
+
+// match some kind of html tag:
+boost::regex e("<[^>]*>");
+// count how many:
+unsigned int tags = 0;
+// saved position of partial match:
+const char* next_pos = 0;
+
+bool grep_callback(const boost::match_results<const char*>& m)
+{
+ if(m[0].matched == false)
+ {
+ // save position and return:
+ next_pos = m[0].first;
+ }
+ else
+ ++tags;
+ return true;
+}
+
+void search(std::istream& is)
+{
+ char buf[4096];
+ next_pos = buf + sizeof(buf);
+ bool have_more = true;
+ while(have_more)
+ {
+ // how much do we copy forward from last try:
+ std::ptrdiff_t leftover = (buf + sizeof(buf)) - next_pos;
+ // and how much is left to fill:
+ std::ptrdiff_t size = next_pos - buf;
+ // copy forward whatever we have left:
+ std::memmove(buf, next_pos, leftover);
+ // fill the rest from the stream:
+ is.read(buf + leftover, size);
+ std::streamsize read = is.gcount();
+ // check to see if we've run out of text:
+ have_more = read == size;
+ // reset next_pos:
+ next_pos = buf + sizeof(buf);
+ // and then grep:
+ boost::regex_grep<bool(*)(const boost::cmatch&), const char*>(grep_callback,
+ static_cast<const char*>(buf),
+ static_cast<const char*>(buf + read + leftover),
+ e,
+ boost::match_default | boost::match_partial);
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ if(argc > 1)
+ {
+ for(int i = 1; i < argc; ++i)
+ {
+ std::ifstream fs(argv[i]);
+ if(fs.bad()) continue;
+ search(fs);
+ fs.close();
+ }
+ }
+ else
+ {
+ std::string one("<META NAME=\"keywords\" CONTENT=\"regex++, regular expressions, regular expression library, C++\">");
+ std::string what;
+ while(what.size() < 10000)
+ {
+ what.append(one);
+ what.append(13, ' ');
+ }
+ std::stringstream ss;
+ ss.str(what);
+ search(ss);
+ }
+ std::cout << "total tag count was " << tags << std::endl;
+ return 0;
+}
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/partial_regex_iterate.cpp b/src/boost/libs/regex/example/snippets/partial_regex_iterate.cpp
new file mode 100644
index 000000000..62f67dd21
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/partial_regex_iterate.cpp
@@ -0,0 +1,118 @@
+/*
+ *
+ * Copyright (c) 1998-2007
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE partial_regex_iterate.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: Search example using partial matches.
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <cstring>
+
+#ifdef BOOST_NO_STDC_NAMESPACE
+namespace std{ using ::memmove; }
+#endif
+
+// match some kind of html tag:
+boost::regex e("<[^>]*>");
+// count how many:
+unsigned int tags = 0;
+
+void search(std::istream& is)
+{
+ // buffer we'll be searching in:
+ char buf[4096];
+ // saved position of end of partial match:
+ const char* next_pos = buf + sizeof(buf);
+ // flag to indicate whether there is more input to come:
+ bool have_more = true;
+
+ while(have_more)
+ {
+ // how much do we copy forward from last try:
+ std::ptrdiff_t leftover = (buf + sizeof(buf)) - next_pos;
+ // and how much is left to fill:
+ std::ptrdiff_t size = next_pos - buf;
+ // copy forward whatever we have left:
+ std::memmove(buf, next_pos, leftover);
+ // fill the rest from the stream:
+ is.read(buf + leftover, size);
+ std::streamsize read = is.gcount();
+ // check to see if we've run out of text:
+ have_more = read == size;
+ // reset next_pos:
+ next_pos = buf + sizeof(buf);
+ // and then iterate:
+ boost::cregex_iterator a(
+ buf,
+ buf + read + leftover,
+ e,
+ boost::match_default | boost::match_partial);
+ boost::cregex_iterator b;
+
+ while(a != b)
+ {
+ if((*a)[0].matched == false)
+ {
+ // Partial match, save position and break:
+ next_pos = (*a)[0].first;
+ break;
+ }
+ else
+ {
+ // full match:
+ ++tags;
+ }
+
+ // move to next match:
+ ++a;
+ }
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ if(argc > 1)
+ {
+ for(int i = 1; i < argc; ++i)
+ {
+ std::ifstream fs(argv[i]);
+ if(fs.bad()) continue;
+ search(fs);
+ fs.close();
+ }
+ }
+ else
+ {
+ std::string one("<META NAME=\"keywords\" CONTENT=\"regex++, regular expressions, regular expression library, C++\">");
+ std::string what;
+ while(what.size() < 10000)
+ {
+ what.append(one);
+ what.append(13, ' ');
+ }
+ std::stringstream ss;
+ ss.str(what);
+ search(ss);
+ }
+ std::cout << "total tag count was " << tags << std::endl;
+ return 0;
+}
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/partial_regex_match.cpp b/src/boost/libs/regex/example/snippets/partial_regex_match.cpp
new file mode 100644
index 000000000..096072bf9
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/partial_regex_match.cpp
@@ -0,0 +1,69 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE partial_regex_match.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_match example using partial matches.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+#include <iostream>
+
+boost::regex e("(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})");
+
+bool is_possible_card_number(const std::string& input)
+{
+ //
+ // return false for partial match, true for full match, or throw for
+ // impossible match based on what we have so far...
+ boost::match_results<std::string::const_iterator> what;
+ if(0 == boost::regex_match(input, what, e, boost::match_default | boost::match_partial))
+ {
+ // the input so far could not possibly be valid so reject it:
+ throw std::runtime_error("Invalid data entered - this could not possibly be a valid card number");
+ }
+ // OK so far so good, but have we finished?
+ if(what[0].matched)
+ {
+ // excellent, we have a result:
+ return true;
+ }
+ // what we have so far is only a partial match...
+ return false;
+}
+
+int main(int argc, char* argv[])
+{
+ try{
+ std::string input;
+ if(argc > 1)
+ input = argv[1];
+ else
+ std::cin >> input;
+ if(is_possible_card_number(input))
+ {
+ std::cout << "Matched OK..." << std::endl;
+ }
+ else
+ std::cout << "Got a partial match..." << std::endl;
+ }
+ catch(const std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ }
+ return 0;
+}
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_grep_example_1.cpp b/src/boost/libs/regex/example/snippets/regex_grep_example_1.cpp
new file mode 100644
index 000000000..2878f5783
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_grep_example_1.cpp
@@ -0,0 +1,131 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_grep_example_1.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_grep example 1: searches a cpp file for class definitions.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+#include <map>
+
+// 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, std::string::difference_type, std::less<std::string> > map_type;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+boost::regex expression(re);
+
+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>& 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;
+ }
+private:
+ IndexClassesPred& operator=(const IndexClassesPred&);
+};
+
+void IndexClasses(map_type& m, const std::string& file)
+{
+ std::string::const_iterator start, end;
+ start = file.begin();
+ end = file.end();
+ boost::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();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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);
+ fs.close();
+ 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;
+}
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_grep_example_2.cpp b/src/boost/libs/regex/example/snippets/regex_grep_example_2.cpp
new file mode 100644
index 000000000..b5222c2dd
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_grep_example_2.cpp
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_grep_example_2.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_grep example 2: searches a cpp file for class definitions,
+ * using a global callback function.
+ */
+
+#include <boost/regex.hpp>
+#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, std::string::difference_type, std::less<std::string> > map_type;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+
+boost::regex expression(re);
+map_type class_index;
+std::string::const_iterator base;
+
+bool grep_callback(const boost::match_results<std::string::const_iterator>& 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;
+ boost::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();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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);
+ fs.close();
+ 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;
+}
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_grep_example_3.cpp b/src/boost/libs/regex/example/snippets/regex_grep_example_3.cpp
new file mode 100644
index 000000000..9097dfda6
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_grep_example_3.cpp
@@ -0,0 +1,153 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_grep_example_3.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_grep example 3: searches a cpp file for class definitions,
+ * using a bound member function callback.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+#include <map>
+#include <functional>
+#include <boost/detail/workaround.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, std::string::difference_type, std::less<std::string> > map_type;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+
+class class_index
+{
+ boost::regex expression;
+ map_type index;
+ std::string::const_iterator base;
+
+ bool grep_callback(boost::match_results<std::string::const_iterator> what);
+public:
+ map_type& get_map() { return index; }
+ void IndexClasses(const std::string& file);
+ class_index()
+ : expression(re) {}
+};
+
+bool class_index::grep_callback(boost::match_results<std::string::const_iterator> 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;
+#if BOOST_WORKAROUND(_MSC_VER, < 1300) && !defined(_STLP_VERSION)
+ boost::regex_grep(std::bind1st(std::mem_fun1(&class_index::grep_callback), this),
+ start,
+ end,
+ expression);
+#elif defined(BOOST_NO_CXX98_BINDERS)
+ boost::regex_grep(std::bind(&class_index::grep_callback, this, std::placeholders::_1),
+ start,
+ end,
+ expression);
+#else
+ boost::regex_grep(std::bind1st(std::mem_fun(&class_index::grep_callback), this),
+ start,
+ end,
+ expression);
+#endif
+}
+
+
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+
+void load_file(std::string& s, std::istream& is)
+{
+ s.erase();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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);
+ fs.close();
+ class_index idx;
+ idx.IndexClasses(text);
+ cout << idx.get_map().size() << " matches found" << endl;
+ map_type::iterator c, d;
+ c = idx.get_map().begin();
+ d = idx.get_map().end();
+ while(c != d)
+ {
+ cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl;
+ ++c;
+ }
+ }
+ return 0;
+}
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_grep_example_4.cpp b/src/boost/libs/regex/example/snippets/regex_grep_example_4.cpp
new file mode 100644
index 000000000..e50383b39
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_grep_example_4.cpp
@@ -0,0 +1,155 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_grep_example_4.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_grep example 4: searches a cpp file for class definitions,
+ * using a C++ Builder closure as a callback.
+ */
+
+#if defined(__BORLANDC__) && !defined(__clang__)
+
+#include <boost/regex.hpp>
+#include <string>
+#include <map>
+#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;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+
+class class_index
+{
+ boost::regex expression;
+ map_type index;
+ std::string::const_iterator base;
+ typedef boost::match_results<std::string::const_iterator> arg_type;
+
+ bool grep_callback(const boost::match_results<std::string::const_iterator>& 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(re)
+ {}
+};
+
+bool class_index::grep_callback(const boost::match_results<std::string::const_iterator>& 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);
+ boost::regex_grep(cl,
+ start,
+ end,
+ expression);
+}
+
+
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+
+void load_file(std::string& s, std::istream& is)
+{
+ s.erase();
+ if(is.bad()) return;
+ 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);
+ fs.close();
+ 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;
+}
+
+#else // __BORLANDC__ && !defined(__clang__)
+
+int main()
+{
+ return 0;
+}
+
+
+#endif
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_iterator_example.cpp b/src/boost/libs/regex/example/snippets/regex_iterator_example.cpp
new file mode 100644
index 000000000..101052f1a
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_iterator_example.cpp
@@ -0,0 +1,114 @@
+/*
+ *
+ * Copyright (c) 2003
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_iterator_example_2.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_iterator example 2: searches a cpp file for class definitions,
+ * using global data.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+#include <map>
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+
+// 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, std::string::difference_type, std::less<std::string> > map_type;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+
+boost::regex expression(re);
+map_type class_index;
+
+bool regex_callback(const boost::match_results<std::string::const_iterator>& 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[what[5].str() + what[6].str()] = what.position(5);
+ return true;
+}
+
+void load_file(std::string& s, std::istream& is)
+{
+ s.erase();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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);
+ fs.close();
+ // construct our iterators:
+ boost::sregex_iterator m1(text.begin(), text.end(), expression);
+ boost::sregex_iterator m2;
+ std::for_each(m1, m2, &regex_callback);
+ // copy results:
+ 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;
+}
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_match_example.cpp b/src/boost/libs/regex/example/snippets/regex_match_example.cpp
new file mode 100644
index 000000000..16ba79b90
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_match_example.cpp
@@ -0,0 +1,105 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_match_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: ftp based regex_match example.
+ */
+
+#include <boost/regex.hpp>
+#include <cstdlib>
+#include <stdlib.h>
+#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 ::atoi(what[1].first);
+ }
+ // failure did not match
+ if(msg)
+ msg->erase();
+ return -1;
+}
+
+#if defined(BOOST_MSVC) || (defined(BOOST_BORLANDC) && (BOOST_BORLANDC == 0x550))
+//
+// problem with std::getline under MSVC6sp3
+istream& getline(istream& is, std::string& s)
+{
+ s.erase();
+ char c = static_cast<char>(is.get());
+ while(c != '\n')
+ {
+ s.append(1, c);
+ c = static_cast<char>(is.get());
+ }
+ return is;
+}
+#endif
+
+int main(int argc, const char*[])
+{
+ 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/src/boost/libs/regex/example/snippets/regex_merge_example.cpp b/src/boost/libs/regex/example/snippets/regex_merge_example.cpp
new file mode 100644
index 000000000..cb8b493ca
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_merge_example.cpp
@@ -0,0 +1,137 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_merge_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_merge example:
+ * converts a C++ file to syntax highlighted HTML.
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <iterator>
+#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();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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)
+{
+ try{
+ e1.assign(expression_text);
+ e2.assign(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);
+ fs.close();
+ 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> oi(t);
+ boost::regex_merge(oi, in.begin(), in.end(), e2, pre_format, boost::match_default | boost::format_all);
+ // then output to final output stream
+ // adding syntax highlighting:
+ std::string s(t.str());
+ std::ostream_iterator<char> out(os);
+ boost::regex_merge(out, s.begin(), s.end(), e1, format_string, boost::match_default | boost::format_all);
+ os << footer_text;
+ os.close();
+ }
+ }
+ catch(...)
+ { return -1; }
+ return 0;
+}
+
+const char* pre_expression = "(<)|(>)|\\r";
+const char* pre_format = "(?1&lt;)(?2&gt;)";
+
+
+const char* expression_text = // preprocessor directives: index 1
+ "(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|"
+ // comment: index 2
+ "(//[^\\n]*|/\\*.*?\\*/)|"
+ // literals: index 3
+ "\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|"
+ // string literals: index 4
+ "('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|"
+ // keywords: index 5
+ "\\<(__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>)"
+ "(?2<I><font color=\"#000080\">$&</font></I>)"
+ "(?3<font color=\"#0000A0\">$&</font>)"
+ "(?4<font color=\"#0000FF\">$&</font>)"
+ "(?5<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=\"#ffffff\">\n"
+ "<P> </P>\n<PRE>";
+
+const char* footer_text = "</PRE>\n</BODY>\n\n";
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_replace_example.cpp b/src/boost/libs/regex/example/snippets/regex_replace_example.cpp
new file mode 100644
index 000000000..19331ab86
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_replace_example.cpp
@@ -0,0 +1,138 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_replace_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_replace example:
+ * converts a C++ file to syntax highlighted HTML.
+ */
+
+#include <boost/regex.hpp>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <iterator>
+#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();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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)
+{
+ try{
+ e1.assign(expression_text);
+ e2.assign(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);
+ fs.close();
+ 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> oi(t);
+ boost::regex_replace(oi, in.begin(), in.end(), e2, pre_format, boost::match_default | boost::format_all);
+ // then output to final output stream
+ // adding syntax highlighting:
+ std::string s(t.str());
+ std::ostream_iterator<char> out(os);
+ boost::regex_replace(out, s.begin(), s.end(), e1, format_string, boost::match_default | boost::format_all);
+ os << footer_text;
+ os.close();
+ }
+ }
+ catch(...)
+ { return -1; }
+ return 0;
+}
+
+const char* pre_expression = "(<)|(>)|(&)|\\r";
+const char* pre_format = "(?1&lt;)(?2&gt;)(?3&amp;)";
+
+
+const char* expression_text = // preprocessor directives: index 1
+ "(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|"
+ // comment: index 2
+ "(//[^\\n]*|/\\*.*?\\*/)|"
+ // literals: index 3
+ "\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|"
+ // string literals: index 4
+ "('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|"
+ // keywords: index 5
+ "\\<(__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>)"
+ "(?2<I><font color=\"#000080\">$&</font></I>)"
+ "(?3<font color=\"#0000A0\">$&</font>)"
+ "(?4<font color=\"#0000FF\">$&</font>)"
+ "(?5<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=\"#ffffff\">\n"
+ "<P> </P>\n<PRE>";
+
+const char* footer_text = "</PRE>\n</BODY>\n\n";
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_search_example.cpp b/src/boost/libs/regex/example/snippets/regex_search_example.cpp
new file mode 100644
index 000000000..ee9cd90fe
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_search_example.cpp
@@ -0,0 +1,129 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_search_example.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_search example: searches a cpp file for class definitions.
+ */
+
+#include <boost/regex.hpp>
+#include <string>
+#include <map>
+
+// 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, std::string::difference_type, std::less<std::string> > map_type;
+
+const char* re =
+ // possibly leading whitespace:
+ "^[[:space:]]*"
+ // possible template declaration:
+ "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
+ // class or struct:
+ "(class|struct)[[:space:]]*"
+ // leading declspec macros etc:
+ "("
+ "\\<\\w+\\>"
+ "("
+ "[[:blank:]]*\\([^)]*\\)"
+ ")?"
+ "[[:space:]]*"
+ ")*"
+ // the class name
+ "(\\<\\w*\\>)[[:space:]]*"
+ // template specialisation parameters
+ "(<[^;:{]+>)?[[:space:]]*"
+ // terminate in { or :
+ "(\\{|:[^;\\{()]*\\{)";
+
+
+boost::regex expression(re);
+
+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;
+ boost::match_flag_type flags = boost::match_default;
+ while(boost::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();
+ if(is.bad()) return;
+ s.reserve(static_cast<std::string::size_type>(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);
+ fs.close();
+ 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;
+}
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_split_example_1.cpp b/src/boost/libs/regex/example/snippets/regex_split_example_1.cpp
new file mode 100644
index 000000000..76a3c950d
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_split_example_1.cpp
@@ -0,0 +1,76 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_split_example_1.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_split example: split a string into tokens.
+ */
+
+
+#include <boost/regex.hpp>
+#include <list>
+
+
+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(BOOST_BORLANDC) && (BOOST_BORLANDC == 0x550))
+//
+// problem with std::getline under MSVC6sp3
+istream& getline(istream& is, std::string& s)
+{
+ s.erase();
+ char c = static_cast<char>(is.get());
+ while(c != '\n')
+ {
+ s.append(1, c);
+ c = static_cast<char>(is.get());
+ }
+ return is;
+}
+#endif
+
+
+int main(int argc, const char*[])
+{
+ string s;
+ list<string> l;
+ do{
+ 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;
+ while(l.size())
+ {
+ s = *(l.begin());
+ l.pop_front();
+ cout << s << endl;
+ }
+ }while(argc == 1);
+ return 0;
+}
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_split_example_2.cpp b/src/boost/libs/regex/example/snippets/regex_split_example_2.cpp
new file mode 100644
index 000000000..ad7350229
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_split_example_2.cpp
@@ -0,0 +1,86 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_split_example_2.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_split example: spit out linked URL's.
+ */
+
+
+#include <boost/regex.hpp>
+#include <list>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+
+boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"",
+ boost::regex::normal | boost::regbase::icase);
+
+void load_file(std::string& s, std::istream& is)
+{
+ s.erase();
+ if(is.bad()) return;
+ //
+ // attempt to grow string buffer to match file size,
+ // this doesn't always work...
+ s.reserve(static_cast<std::string::size_type>(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;
+ int i;
+ for(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);
+ is.close();
+ 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(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);
+ is.close();
+ while(boost::regex_split(std::ostream_iterator<std::string>(std::cout), s, e, boost::match_default, 1)) std::cout << std::endl;
+ }
+
+ return 0;
+}
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_1.cpp b/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_1.cpp
new file mode 100644
index 000000000..4bf5c62f0
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_1.cpp
@@ -0,0 +1,72 @@
+/*
+ *
+ * Copyright (c) 2003
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_token_iterator_example_1.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_token_iterator example: split a string into tokens.
+ */
+
+
+#include <boost/regex.hpp>
+
+#include <iostream>
+using namespace std;
+
+
+#if defined(BOOST_MSVC) || (defined(BOOST_BORLANDC) && (BOOST_BORLANDC == 0x550))
+//
+// problem with std::getline under MSVC6sp3
+istream& getline(istream& is, std::string& s)
+{
+ s.erase();
+ char c = static_cast<char>(is.get());
+ while(c != '\n')
+ {
+ s.append(1, c);
+ c = static_cast<char>(is.get());
+ }
+ return is;
+}
+#endif
+
+
+int main(int argc, const char*[])
+{
+ string s;
+ do{
+ 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";
+
+ boost::regex re("\\s+");
+ boost::sregex_token_iterator i(s.begin(), s.end(), re, -1);
+ boost::sregex_token_iterator j;
+
+ unsigned count = 0;
+ while(i != j)
+ {
+ cout << *i++ << endl;
+ count++;
+ }
+ cout << "There were " << count << " tokens found." << endl;
+
+ }while(argc == 1);
+ return 0;
+}
+
+
diff --git a/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_2.cpp b/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_2.cpp
new file mode 100644
index 000000000..3458ce4d3
--- /dev/null
+++ b/src/boost/libs/regex/example/snippets/regex_token_iterator_eg_2.cpp
@@ -0,0 +1,89 @@
+/*
+ *
+ * Copyright (c) 2003
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+ /*
+ * LOCATION: see http://www.boost.org for most recent version.
+ * FILE regex_token_iterator_example_2.cpp
+ * VERSION see <boost/version.hpp>
+ * DESCRIPTION: regex_token_iterator example: spit out linked URL's.
+ */
+
+
+#include <boost/regex.hpp>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+
+boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"",
+ boost::regex::normal | boost::regbase::icase);
+
+void load_file(std::string& s, std::istream& is)
+{
+ s.erase();
+ if(is.bad()) return;
+ //
+ // attempt to grow string buffer to match file size,
+ // this doesn't always work...
+ s.reserve(static_cast<std::string::size_type>(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;
+ int i;
+ for(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);
+ is.close();
+ boost::sregex_token_iterator i(s.begin(), s.end(), e, 1);
+ boost::sregex_token_iterator j;
+ while(i != j)
+ {
+ std::cout << *i++ << std::endl;
+ }
+ }
+ //
+ // alternative method:
+ // test the array-literal constructor, and split out the whole
+ // match as well as $1....
+ //
+ for(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);
+ is.close();
+ const int subs[] = {1, 0,};
+ boost::sregex_token_iterator i(s.begin(), s.end(), e, subs);
+ boost::sregex_token_iterator j;
+ while(i != j)
+ {
+ std::cout << *i++ << std::endl;
+ }
+ }
+
+ return 0;
+}
+
+
diff --git a/src/boost/libs/regex/example/timer/bc55.mak b/src/boost/libs/regex/example/timer/bc55.mak
new file mode 100644
index 000000000..44795fc6c
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/bc55.mak
@@ -0,0 +1,51 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+
+# 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- -Vx -Ve -D_NO_VCL; -I../../../../; -L..\..\build\bcb5
+
+
+timer.exe : regex_timer.cpp
+ $(BCC32) @&&|
+ $(COMPOPTS) -e$@ regex_timer.cpp
+|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/timer/bcb4.mak b/src/boost/libs/regex/example/timer/bcb4.mak
new file mode 100644
index 000000000..372b647d4
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/bcb4.mak
@@ -0,0 +1,51 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+
+# 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- -Vx -Ve -D_NO_VCL; -I../../../../; -L..\..\build\bcb4
+
+
+timer.exe : regex_timer.cpp
+ $(BCC32) @&&|
+ $(COMPOPTS) -e$@ regex_timer.cpp
+|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/timer/bcb5.mak b/src/boost/libs/regex/example/timer/bcb5.mak
new file mode 100644
index 000000000..44795fc6c
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/bcb5.mak
@@ -0,0 +1,51 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+
+# 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- -Vx -Ve -D_NO_VCL; -I../../../../; -L..\..\build\bcb5
+
+
+timer.exe : regex_timer.cpp
+ $(BCC32) @&&|
+ $(COMPOPTS) -e$@ regex_timer.cpp
+|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/timer/gcc.mak b/src/boost/libs/regex/example/timer/gcc.mak
new file mode 100644
index 000000000..2faf64189
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/gcc.mak
@@ -0,0 +1,38 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+
+# very basic makefile for timer.exe
+#
+# GNU compiler GCC
+#
+CXX= $(INCLUDES) -I../../../../ -I./ $(CXXFLAGS)
+
+timer : regex_timer.cpp
+ g++ $(CXX) -O2 -o timer regex_timer.cpp -L../../build/gcc $(LDFLAGS) -lboost_regex $(LIBS)
+
+debug : regex_timer.cpp timer.cpp
+ g++ $(CXX) -g -o timer regex_timer.cpp -L../../build/gcc $(LDFLAGS) -lboost_regex_debug $(LIBS)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/timer/input_script.txt b/src/boost/libs/regex/example/timer/input_script.txt
new file mode 100644
index 000000000..4a9e3e2df
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/input_script.txt
@@ -0,0 +1,14 @@
+abc
+aaaaaaaaaaabcccccccc
+quit
+^([0-9]+)(\-| |$)(.*)$
+100- this is a line of ftp response which contains a message string
+quit
+quit
+
+# Copyright 2007 John Maddock.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt).
+
+
diff --git a/src/boost/libs/regex/example/timer/regex_timer.cpp b/src/boost/libs/regex/example/timer/regex_timer.cpp
new file mode 100644
index 000000000..d121b70f1
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/regex_timer.cpp
@@ -0,0 +1,375 @@
+/*
+ *
+ * Copyright (c) 1998-2002
+ * John Maddock
+ *
+ * Use, modification and distribution are subject to the
+ * Boost Software License, Version 1.0. (See accompanying file
+ * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ *
+ */
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4996 4127)
+#endif
+
+#include <boost/config.hpp>
+#include <boost/regex.hpp>
+#include <boost/cregex.hpp>
+#include <boost/timer.hpp>
+#include <boost/smart_ptr.hpp>
+
+#include <string>
+#include <algorithm>
+#include <deque>
+#include <iterator>
+
+#ifdef BOOST_RE_OLD_IOSTREAM
+#include <iostream.h>
+#include <fstream.h>
+#else
+#include <iostream>
+#include <fstream>
+using std::cout;
+using std::cin;
+using std::cerr;
+using std::istream;
+using std::ostream;
+using std::endl;
+using std::ifstream;
+using std::streambuf;
+using std::getline;
+#endif
+
+#if defined(_WIN32) && defined(BOOST_REGEX_USE_WIN32_LOCALE)
+#include <windows.h>
+#endif
+
+#if (defined(_MSC_VER) && (_MSC_VER <= 1300)) || defined(__sgi)
+// maybe no Koenig lookup, use using declaration instead:
+using namespace boost;
+#endif
+
+#ifndef BOOST_NO_WREGEX
+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(static_cast<char>(*i));
+ ++i;
+ }
+ return os;
+}
+#endif
+
+template <class S>
+class string_out_iterator
+{
+public:
+ typedef std::output_iterator_tag iterator_category;
+ typedef void value_type;
+ typedef void difference_type;
+ typedef void pointer;
+ typedef void reference;
+private:
+ 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;
+ }
+};
+
+namespace boost{
+#if defined(BOOST_MSVC) || (defined(BOOST_BORLANDC) && (BOOST_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 = static_cast<char>(is.get());
+ while(c != '\n')
+ {
+ BOOST_ASSERT(is.good());
+ s.append(1, c);
+ c = static_cast<char>(is.get());
+ }
+ return is;
+}
+#else
+istream& getline(istream& is, std::string& s)
+{
+ std::getline(is, s);
+ if(s.size() && (s[s.size() -1] == '\r'))
+ s.erase(s.size() - 1);
+ return is;
+}
+#endif
+}
+
+
+int main(int argc, char**argv)
+{
+ ifstream ifs;
+ std::istream* p_in = &std::cin;
+ if(argc == 2)
+ {
+ ifs.open(argv[1]);
+ ifs.peek();
+ if(!ifs.good())
+ {
+ cout << "Bad filename: " << argv[1] << endl;
+ return -1;
+ }
+ p_in = &ifs;
+ }
+
+ boost::regex ex;
+ boost::match_results<std::string::const_iterator> sm;
+#ifndef BOOST_NO_WREGEX
+ 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_tA r;
+ boost::scoped_array<boost::regmatch_t> matches;
+ std::size_t nsubs;
+ boost::timer t;
+ double tim;
+ int result = 0;
+ unsigned iters = 100;
+ double wait_time = (std::min)(t.elapsed_min() * 1000, 0.5);
+
+ while(true)
+ {
+ cout << "Enter expression (or \"quit\" to exit): ";
+ boost::getline(*p_in, s1);
+ if(argc == 2)
+ cout << endl << s1 << endl;
+ if(s1 == "quit")
+ break;
+#ifndef BOOST_NO_WREGEX
+ ws1.erase();
+ std::copy(s1.begin(), s1.end(), string_out_iterator<std::wstring>(ws1));
+#endif
+ try{
+ ex.assign(s1);
+#ifndef BOOST_NO_WREGEX
+ wex.assign(ws1);
+#endif
+ }
+ catch(std::exception& e)
+ {
+ cout << "Error in expression: \"" << e.what() << "\"" << endl;
+ continue;
+ }
+ int code = regcompA(&r, s1.c_str(), boost::REG_PERL);
+ if(code != 0)
+ {
+ char buf[256];
+ regerrorA(code, &r, buf, 256);
+ cout << "regcompA 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): ";
+ boost::getline(*p_in, s2);
+ if(argc == 2)
+ cout << endl << s2 << endl;
+ if(s2 == "quit")
+ break;
+
+#ifndef BOOST_NO_WREGEX
+ 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));
+
+ unsigned i;
+ iters = 10;
+ tim = 1.1;
+
+#if defined(_WIN32) && defined(BOOST_REGEX_USE_WIN32_LOCALE)
+ MSG msg;
+ PeekMessage(&msg, 0, 0, 0, 0);
+ Sleep(0);
+#endif
+
+ // cache load:
+ regex_search(s2, sm, ex);
+
+ // measure time interval for basic_regex<char>
+ do{
+ iters *= static_cast<unsigned>((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 < wait_time);
+
+ 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_NO_WREGEX
+ // measure time interval for boost::wregex
+ iters = 10;
+ tim = 1.1;
+ // cache load:
+ regex_search(ws2, wsm, wex);
+ do{
+ iters *= static_cast<unsigned>((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 < wait_time);
+ 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 basic_regex<char> using a deque
+ iters = 10;
+ tim = 1.1;
+ // cache load:
+ regex_search(ds.begin(), ds.end(), dm, ex);
+ do{
+ iters *= static_cast<unsigned>((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 < wait_time);
+ 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:
+ regexecA(&r, s2.c_str(), nsubs, matches.get(), 0);
+ do{
+ iters *= static_cast<unsigned>((tim > 0.001) ? (1.1/tim) : 100);
+ t.restart();
+ for(i = 0; i < iters; ++i)
+ {
+ result = regexecA(&r, s2.c_str(), nsubs, matches.get(), 0);
+ }
+ tim = t.elapsed();
+ }while(tim < wait_time);
+ cout << "POSIX regexecA 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 != (int)s2.size()) << ")" << endl << endl;
+ }
+ }
+ regfreeA(&r);
+ }
+
+ return 0;
+}
+
+#if defined(_WIN32) && defined(BOOST_REGEX_USE_WIN32_LOCALE) && !defined(UNDER_CE)
+#if !defined(BOOST_EMBTC)
+#pragma comment(lib, "user32.lib")
+#else
+#pragma comment(lib, "user32.a")
+#endif
+#endif
diff --git a/src/boost/libs/regex/example/timer/vc6-stlport.mak b/src/boost/libs/regex/example/timer/vc6-stlport.mak
new file mode 100644
index 000000000..1b5f686dd
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/vc6-stlport.mak
@@ -0,0 +1,39 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+#
+# very basic VC6 makefile for timer
+#
+CXX=cl
+CXXFLAGS=/Oityb1 /GF /Gy -MT -GX -DSTRICT -I../../../../ -I./
+LIBS=/link /LIBPATH:..\..\build\vc6-stlport kernel32.lib user32.lib
+EXE=.exe
+OBJ=.obj
+
+LIBDEP= ../../../../boost/regex/detail/regex_options.hpp ../../../../boost/regex/detail/regex_config.hpp
+
+regex_timer$(EXE) : regex_timer$(OBJ)
+ $(CXX) -o timer$(EXE) 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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/boost/libs/regex/example/timer/vc6.mak b/src/boost/libs/regex/example/timer/vc6.mak
new file mode 100644
index 000000000..c611195fa
--- /dev/null
+++ b/src/boost/libs/regex/example/timer/vc6.mak
@@ -0,0 +1,39 @@
+# copyright John Maddock 2003
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt.
+#
+# very basic VC6 makefile for timer
+#
+CXX=cl
+CXXFLAGS=/Oityb1 /GF /Gy -GX -DSTRICT -I../../../../ -I./
+LIBS=/link /LIBPATH:..\..\build\vc6
+EXE=.exe
+OBJ=.obj
+
+LIBDEP= ../../../../boost/regex/detail/regex_options.hpp ../../../../boost/regex/detail/regex_config.hpp
+
+regex_timer$(EXE) : regex_timer$(OBJ)
+ $(CXX) -o timer$(EXE) 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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+