boost.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ///////////////////////////////////////////////////////////////
  2. // Copyright 2015 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
  5. //
  6. #include "performance.hpp"
  7. #include <boost/regex.hpp>
  8. #include <boost/version.hpp>
  9. #include <boost/lexical_cast.hpp>
  10. struct boost_regex : public abstract_regex
  11. {
  12. private:
  13. boost::regex e;
  14. boost::cmatch what;
  15. public:
  16. virtual bool set_expression(const char* pe, bool isperl)
  17. {
  18. e.assign(pe, isperl ? boost::regex::perl : boost::regex::extended);
  19. return e.status() == 0;
  20. }
  21. virtual bool match_test(const char* text);
  22. virtual unsigned find_all(const char* text);
  23. virtual std::string name();
  24. struct initializer
  25. {
  26. initializer()
  27. {
  28. boost_regex::register_instance(boost::shared_ptr<abstract_regex>(new boost_regex));
  29. }
  30. void do_nothing()const {}
  31. };
  32. static const initializer init;
  33. };
  34. const boost_regex::initializer boost_regex::init;
  35. bool boost_regex::match_test(const char * text)
  36. {
  37. return regex_match(text, what, e);
  38. }
  39. unsigned boost_regex::find_all(const char * text)
  40. {
  41. boost::regex_iterator<const char*> i(text, text + std::strlen(text), e), j;
  42. unsigned count = 0;
  43. while(i != j)
  44. {
  45. ++i;
  46. ++count;
  47. }
  48. return count;
  49. }
  50. std::string boost_regex::name()
  51. {
  52. init.do_nothing();
  53. return boost_name();
  54. }