Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <boost/regex.hpp>
- std::string foo(const std::string &input) {
- // R"(...)" - c++11'ный аналог шарповского @"..."
- boost::regex r(R"(\([^()]+\)|(([a-z]|\*)+))");
- return boost::regex_replace(input, r, [] (const boost::smatch &s) -> std::string {
- return std::string(s.length(), ' ');
- });
- }
- void test(const std::string &in, const std::string &expected_out) {
- std::string real_out = foo(in);
- if (real_out == expected_out) {
- std::cout << "PASS" << std::endl;
- } else {
- std::cout << "FAIL: got \"" << real_out << "\" instead of \"" <<
- expected_out << "\"" << std::endl;
- }
- }
- int main() {
- test("", "");
- test("a", " ");
- test("a*b*c", " ");
- test("a+b", " + ");
- test("(a+b*c)+x*y", " + ");
- test("(a+b*c)+x+y", " + + ");
- test("(a+b*c)+x+y+", " + + +");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement