From 1758679bd6e11c529126977e61bc349d1069542f Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 16 Mar 2001 12:41:36 +0000 Subject: [PATCH] regex: minor changes to make the test code more conservative in C++ usage [SVN r9563] --- demo/regress/parse.cpp | 10 +++++----- demo/regress/regress.cpp | 2 +- demo/regress/regress.h | 8 ++++---- demo/regress/tests.cpp | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/demo/regress/parse.cpp b/demo/regress/parse.cpp index f61b71df..1a547550 100644 --- a/demo/regress/parse.cpp +++ b/demo/regress/parse.cpp @@ -172,7 +172,7 @@ bool parse_function::operator()(const parse_grep& g) } cout << "Warning: Unknown flag: "; string_type t(i, j); - cout << make_narrow(t.c_str()); + cout << make_narrow(t).c_str(); cout << endl; return true; } @@ -184,9 +184,9 @@ bool parse_function::operator()(const parse_grep& g) case 1: // set the text to match: search_text = string_type(i, j); - jm_trace("Initial search text: " << make_narrow(search_text)); + jm_trace("Initial search text: " << make_narrow(search_text).c_str()); expand_escapes(search_text); - jm_trace("Search text after escapes expanded: " << make_narrow(search_text)); + jm_trace("Search text after escapes expanded: " << make_narrow(search_text).c_str()); break; case 2: // maybe set format string: @@ -232,8 +232,8 @@ void parse_input_line(const string_type& s) parse_function op; do_test = false; regex_grep(op, s.begin(), s.end(), parse_expression); - jm_trace("expression: " << make_narrow(expression)); - jm_trace("search string: " << make_narrow(search_text)); + jm_trace("expression: " << make_narrow(expression).c_str()); + jm_trace("search string: " << make_narrow(search_text).c_str()); } int to_int(string_type::const_iterator i, string_type::const_iterator j) diff --git a/demo/regress/regress.cpp b/demo/regress/regress.cpp index 90a69c99..fce25059 100644 --- a/demo/regress/regress.cpp +++ b/demo/regress/regress.cpp @@ -101,7 +101,7 @@ int main(int argc, char * argv[]) string_type s; get_line(is, s); ++line; - jm_trace("Reading test script line " << line << " " << make_narrow(s.c_str())); + jm_trace("Reading test script line " << line << " " << make_narrow(s).c_str()); parse_input_line(s); if(do_test) { diff --git a/demo/regress/regress.h b/demo/regress/regress.h index c86260ae..80d32a85 100644 --- a/demo/regress/regress.h +++ b/demo/regress/regress.h @@ -51,14 +51,14 @@ using std::endl; typedef wchar_t char_t; #endif -#define NO_POSIX_TEST typedef std::basic_string string_type; typedef std::basic_string nstring_type; inline istream& get_line(istream& is, nstring_type& s, char delim = '\n'); istream& get_line(istream& is, string_type& s, char delim = L'\n'); #define BOOST_RE_STR(x) L##x std::string make_narrow(const wchar_t* ptr); -//ostream& operator << (ostream& os, const string_type& s); +inline std::string make_narrow(const std::wstring& s) +{ return make_narrow(s.c_str()); } #else // TEST_UNICODE @@ -71,11 +71,11 @@ typedef char char_t; typedef std::basic_string string_type; inline istream& get_line(istream& is, string_type& s, char delim = '\n'); #define BOOST_RE_STR(x) x -#define make_narrow(x) x +inline std::string make_narrow(const std::string& s) +{ return s; } #endif // TEST_UNICODE -//ostream& operator << (ostream& os, const wchar_t* s); void parse_input_line(const string_type& s); void expand_escapes(string_type& s); void run_tests(); diff --git a/demo/regress/tests.cpp b/demo/regress/tests.cpp index efdca26c..d99fa4b4 100644 --- a/demo/regress/tests.cpp +++ b/demo/regress/tests.cpp @@ -213,7 +213,7 @@ void cpp_tests(const reg_expression& e, bool recurse = true) if(s != merge_string) { begin_error(); - cout << "merge result mismatch: found \"" << make_narrow(s.c_str()) << "\" expected \"" << make_narrow(merge_string.c_str()) << "\"" << endl; + cout << "merge result mismatch: found \"" << make_narrow(s).c_str() << "\" expected \"" << make_narrow(merge_string.c_str()) << "\"" << endl; } return; } @@ -713,8 +713,8 @@ void begin_error() if(line != last_line) { cout << "Error in line " << line << " of file " << file << endl; - cout << "Expression: " << make_narrow(expression.c_str()) << endl; - cout << "Search text: " << make_narrow(search_text.c_str()) << endl; + cout << "Expression: " << make_narrow(expression).c_str() << endl; + cout << "Search text: " << make_narrow(search_text).c_str() << endl; cout << "Flags: "; bool started = false; unsigned int id = 0; @@ -724,7 +724,7 @@ void begin_error() { if(started) cout << " | "; - cout << make_narrow(flag_data[id].name); + cout << make_narrow(flag_data[id].name).c_str(); started = true; } ++id;