diff options
author | vng <viktor.govako@gmail.com> | 2012-10-30 17:21:39 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:46:27 +0300 |
commit | f05dcc2e4838503e9ebc204cfa1c894bda9ff46f (patch) | |
tree | 95de4ed2114ee9fbfb6786cd0c32f61382e06b72 /platform | |
parent | b51574bdc59b52b4d8b77cd36d43c19a6ef3ee4e (diff) |
Add regexp routine (base on boost::expressive).
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform.pro | 1 | ||||
-rw-r--r-- | platform/platform_tests/platform_tests.pro | 1 | ||||
-rw-r--r-- | platform/platform_tests/regexp_test.cpp | 22 | ||||
-rw-r--r-- | platform/regexp.hpp | 18 |
4 files changed, 42 insertions, 0 deletions
diff --git a/platform/platform.pro b/platform/platform.pro index 4572240ac3..7497a66c59 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -68,6 +68,7 @@ HEADERS += \ servers_list.hpp \ constants.hpp \ file_name_utils.hpp \ + regexp.hpp \ SOURCES += \ preferred_languages.cpp \ diff --git a/platform/platform_tests/platform_tests.pro b/platform/platform_tests/platform_tests.pro index 29bee1215e..821e52437a 100644 --- a/platform/platform_tests/platform_tests.pro +++ b/platform/platform_tests/platform_tests.pro @@ -33,3 +33,4 @@ SOURCES += \ language_test.cpp \ downloader_test.cpp \ video_timer_test.cpp \ + regexp_test.cpp \ diff --git a/platform/platform_tests/regexp_test.cpp b/platform/platform_tests/regexp_test.cpp new file mode 100644 index 0000000000..7e0e0dea35 --- /dev/null +++ b/platform/platform_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/platform/regexp.hpp b/platform/regexp.hpp new file mode 100644 index 0000000000..171c365684 --- /dev/null +++ b/platform/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); + } +} |