Advertisement
Guest User

Untitled

a guest
Dec 11th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <boost/regex.hpp>
  4.  
  5. std::string foo(const std::string &input) {
  6.     // R"(...)" - c++11'ный аналог шарповского @"..."
  7.     boost::regex r(R"(\([^()]+\)|(([a-z]|\*)+))");
  8.     return boost::regex_replace(input, r, [] (const boost::smatch &s) -> std::string {
  9.         return std::string(s.length(), ' ');
  10.     });
  11. }
  12.  
  13. void test(const std::string &in, const std::string &expected_out) {
  14.     std::string real_out = foo(in);
  15.     if (real_out == expected_out) {
  16.         std::cout << "PASS" << std::endl;
  17.     } else {
  18.         std::cout << "FAIL: got \"" << real_out << "\" instead of \"" <<
  19.             expected_out << "\"" << std::endl;
  20.     }
  21. }
  22.  
  23. int main() {
  24.     test("", "");
  25.     test("a", " ");
  26.     test("a*b*c", "     ");
  27.     test("a+b", " + ");
  28.     test("(a+b*c)+x*y", "       +   ");
  29.     test("(a+b*c)+x+y", "       + + ");
  30.     test("(a+b*c)+x+y+", "       + + +");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement