iter_iter_flg.pass.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <regex>
  9. // template <class charT, class traits = regex_traits<charT>> class basic_regex;
  10. // template <class ForwardIterator>
  11. // basic_regex(ForwardIterator first, ForwardIterator last,
  12. // flag_type f = regex_constants::ECMAScript);
  13. #include <regex>
  14. #include <cassert>
  15. #include "test_iterators.h"
  16. #include "test_macros.h"
  17. template <class Iter>
  18. void
  19. test(Iter first, Iter last, std::regex_constants::syntax_option_type f, unsigned mc)
  20. {
  21. std::basic_regex<typename std::iterator_traits<Iter>::value_type> r(first, last, f);
  22. assert(r.flags() == f);
  23. assert(r.mark_count() == mc);
  24. }
  25. int main(int, char**)
  26. {
  27. typedef forward_iterator<std::string::const_iterator> F;
  28. std::string s1("\\(a\\)");
  29. std::string s2("\\(a[bc]\\)");
  30. std::string s3("\\(a\\([bc]\\)\\)");
  31. std::string s4("(a([bc]))");
  32. test(F(s1.begin()), F(s1.end()), std::regex_constants::basic, 1);
  33. test(F(s2.begin()), F(s2.end()), std::regex_constants::basic, 1);
  34. test(F(s3.begin()), F(s3.end()), std::regex_constants::basic, 2);
  35. test(F(s4.begin()), F(s4.end()), std::regex_constants::basic, 0);
  36. test(F(s1.begin()), F(s1.end()), std::regex_constants::extended, 0);
  37. test(F(s2.begin()), F(s2.end()), std::regex_constants::extended, 0);
  38. test(F(s3.begin()), F(s3.end()), std::regex_constants::extended, 0);
  39. test(F(s4.begin()), F(s4.end()), std::regex_constants::extended, 2);
  40. test(F(s1.begin()), F(s1.end()), std::regex_constants::ECMAScript, 0);
  41. test(F(s2.begin()), F(s2.end()), std::regex_constants::ECMAScript, 0);
  42. test(F(s3.begin()), F(s3.end()), std::regex_constants::ECMAScript, 0);
  43. test(F(s4.begin()), F(s4.end()), std::regex_constants::ECMAScript, 2);
  44. test(F(s1.begin()), F(s1.end()), std::regex_constants::awk, 0);
  45. test(F(s2.begin()), F(s2.end()), std::regex_constants::awk, 0);
  46. test(F(s3.begin()), F(s3.end()), std::regex_constants::awk, 0);
  47. test(F(s4.begin()), F(s4.end()), std::regex_constants::awk, 2);
  48. test(F(s1.begin()), F(s1.end()), std::regex_constants::grep, 1);
  49. test(F(s2.begin()), F(s2.end()), std::regex_constants::grep, 1);
  50. test(F(s3.begin()), F(s3.end()), std::regex_constants::grep, 2);
  51. test(F(s4.begin()), F(s4.end()), std::regex_constants::grep, 0);
  52. test(F(s1.begin()), F(s1.end()), std::regex_constants::egrep, 0);
  53. test(F(s2.begin()), F(s2.end()), std::regex_constants::egrep, 0);
  54. test(F(s3.begin()), F(s3.end()), std::regex_constants::egrep, 0);
  55. test(F(s4.begin()), F(s4.end()), std::regex_constants::egrep, 2);
  56. return 0;
  57. }