diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/base.pro | 1 | ||||
-rw-r--r-- | base/base_tests/base_tests.pro | 1 | ||||
-rw-r--r-- | base/base_tests/regexp_test.cpp | 22 | ||||
-rw-r--r-- | base/regexp.hpp | 18 |
4 files changed, 42 insertions, 0 deletions
diff --git a/base/base.pro b/base/base.pro index f7ce1aa03f..06587971b3 100644 --- a/base/base.pro +++ b/base/base.pro @@ -79,3 +79,4 @@ HEADERS += \ strings_bundle.hpp \ string_format.hpp \ object_tracker.hpp \ + regexp.hpp diff --git a/base/base_tests/base_tests.pro b/base/base_tests/base_tests.pro index 021127f81c..0cb91f591d 100644 --- a/base/base_tests/base_tests.pro +++ b/base/base_tests/base_tests.pro @@ -35,6 +35,7 @@ SOURCES += \ containers_test.cpp \ fence_manager_test.cpp \ string_format_test.cpp \ + regexp_test.cpp HEADERS += diff --git a/base/base_tests/regexp_test.cpp b/base/base_tests/regexp_test.cpp new file mode 100644 index 0000000000..7e0e0dea35 --- /dev/null +++ b/base/base_tests/regexp_test.cpp @@ -0,0 +1,22 @@ +#include "../../testing/testing.hpp" + +#include "../regexp.hpp" + + +UNIT_TEST(RegExp_Or) +{ + regexp::RegExpT exp; + regexp::Create("\\.mwm\\.(downloading2?$|resume2?$)", exp); + + TEST(regexp::IsExist("Aruba.mwm.downloading", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.downloading1", exp), ()); + TEST(regexp::IsExist("Aruba.mwm.downloading2", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.downloading3", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.downloading.tmp", exp), ()); + + TEST(regexp::IsExist("Aruba.mwm.resume", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.resume1", exp), ()); + TEST(regexp::IsExist("Aruba.mwm.resume2", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.resume3", exp), ()); + TEST(!regexp::IsExist("Aruba.mwm.resume.tmp", exp), ()); +} diff --git a/base/regexp.hpp b/base/regexp.hpp new file mode 100644 index 0000000000..171c365684 --- /dev/null +++ b/base/regexp.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include <boost/xpressive/xpressive.hpp> + +namespace regexp +{ + typedef boost::xpressive::sregex RegExpT; + + inline void Create(string const & regexp, RegExpT & out) + { + out = RegExpT::compile(regexp); + } + + inline bool IsExist(string const & str, RegExpT const & regexp) + { + return boost::xpressive::regex_search(str, regexp); + } +} |