ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
4.0 KiB

  1. //
  2. // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOSTER_PERL_REGEX_H
  9. #define BOOSTER_PERL_REGEX_H
  10. #include <booster/config.h>
  11. #include <booster/copy_ptr.h>
  12. #include <string>
  13. #include <vector>
  14. #include <booster/backtrace.h>
  15. namespace booster {
  16. ///
  17. /// \brief Exception that is thrown in case of creation of invalid regex
  18. ///
  19. class regex_error : public booster::runtime_error {
  20. public:
  21. regex_error(std::string const &s) : booster::runtime_error(s)
  22. {
  23. }
  24. };
  25. ///
  26. /// \brief This is a simple wrapper of PCRE library.
  27. ///
  28. /// It is designed to be used with sub_match, match_results, regex_match and regex_search template functions.
  29. ///
  30. /// It provides API similar to ones of Boost.Regex but it is also much simplified.
  31. ///
  32. class BOOSTER_API regex {
  33. public:
  34. typedef char value_type;
  35. explicit regex();
  36. ///
  37. /// Copy regular expression. Note. This is much more efficient then creating a new expression
  38. /// with same patter.
  39. ///
  40. regex(regex const &);
  41. ///
  42. /// Copy regular expression. Note. This is much more efficient then creating a new expression
  43. /// with same patter.
  44. ///
  45. regex const &operator=(regex const &);
  46. ~regex();
  47. ///
  48. /// Create regular expression using a \a patter and special \a flags. Note, at this point flags
  49. /// should be normal or perl only (which are equivalent). May be extended in future.
  50. ///
  51. /// Throws regex_error in case of invalid expression.
  52. ///
  53. regex(std::string const &pattern,int flags = normal);
  54. ///
  55. /// Assigns regular expression using a \a patter and special \a flags. Note, at this point flags
  56. /// should be normal or perl only (which are equivalent). May be extended in future.
  57. ///
  58. /// Throws regex_error in case of invalid expression.
  59. ///
  60. void assign(std::string const &pattern,int flags = normal);
  61. ///
  62. /// Get expression flags. Now always 0.
  63. ///
  64. int flags() const;
  65. ///
  66. /// Get the string that the regular expression was created with.
  67. ///
  68. std::string str() const;
  69. ///
  70. /// Get number of captured subexpressions.
  71. ///
  72. unsigned mark_count() const;
  73. ///
  74. /// Match the expression in the text in range [begin,end) exactly. Parameter \a flags currently unused.
  75. ///
  76. /// Return true if matches
  77. ///
  78. bool match(char const *begin,char const *end,int flags = 0) const;
  79. ///
  80. /// Match the expression in the text in range [begin,end) exactly. Parameter \a flags currently unused.
  81. ///
  82. /// Return true if matches, and stores captured sub-patterns in \a marks. Each pair represents
  83. /// a text in rage [begin+first,begin+second).
  84. ///
  85. /// If no such patter was captured, returns (-1,-1) as pair.
  86. ///
  87. bool match(char const *begin,char const *end,std::vector<std::pair<int,int> > &marks,int flags = 0) const;
  88. ///
  89. /// Search the expression in the text in range [begin,end). Parameter \a flags currently unused.
  90. ///
  91. /// Return true if found.
  92. ///
  93. bool search(char const *begin,char const *end,int flags = 0) const;
  94. ///
  95. /// Search the expression in the text in range [begin,end). Parameter \a flags currently unused.
  96. ///
  97. /// Return true if found, and stores captured sub-patterns in \a marks. Each pair represents
  98. /// a text in rage [begin+first,begin+second).
  99. ///
  100. /// If no such patter was captured, returns (-1,-1) as pair.
  101. ///
  102. bool search(char const *begin,char const *end,std::vector<std::pair<int,int> > &marks,int flags = 0) const;
  103. ///
  104. /// Returns true if the expression wasn't assigned.
  105. ///
  106. bool empty() const;
  107. static const int perl = 0; ///< Constant for expression type - Perl Compatible Regex.
  108. static const int normal = 0; ///< Constant for expression type - synonym of perl, default.
  109. static const int icase = 0x100; ///< Make case insensitive comparison \ver{v1_2}
  110. static const int utf8 = 0x200; ///< Assume that input is UTF-8 so for example '.' would match UTF-8 code point \ver{v1_2}
  111. private:
  112. struct data;
  113. copy_ptr<data> d;
  114. };
  115. } // booster
  116. #endif