Advertisement
Guest User

Untitled

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