//Copyright (c) 2002 David J. Sankel // //Permission to use, copy, modify, distribute and sell this software //and its documentation for any purpose is hereby granted without fee, //provided that the above copyright notice appear in all copies and //that both that copyright notice and this permission notice appear //in supporting documentation. David J. Sankel makes no representations //about the suitability of this software for any purpose. //It is provided "as is" without express or implied warranty. #include #include #include #include #include #include #include using namespace std; int main( char argc, char ** argv) { const string error_message = "USEAGE: sed s/regex/format/\n" std::ios::sync_with_stdio( false ); //Speed optimization std::cin.unsetf( std::ios::skipws ); //Allows cin >> char to get whitespace if( argc != 2 ) { std::cerr << error_message; return EXIT_FAILURE; } string s = argv[1]; //The regex; const boost::regex input( "^s/(.*)/(.*)/" ); boost::smatch what; if( !regex_match( s, what, input ) ) { std::cerr << error_message; return EXIT_FAILURE; } //The following is the way I'd like to use the regex_merge. boost::regex_merge( std::ostream_iterator< char >( cout ), std::istream_iterator< char >( cin ), std::istream_iterator< char >(), boost::regex( string( what[1] ) ), string( what[2] ), boost::match_default | boost::match_not_dot_newline | boost::format_sed ); //The following is the way I am doing regex_merge now. // ostringstream t; // t << cin.rdbuf(); // s = t.str(); // boost::regex_merge( // std::ostream_iterator< char >( cout ), // s.begin(), s.end(), // boost::regex( string( what[1] ) ), // string( what[2] ), // boost::match_default | boost::match_not_dot_newline | // boost::format_sed ); }