From f05dcc2e4838503e9ebc204cfa1c894bda9ff46f Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 30 Oct 2012 16:21:39 +0300 Subject: [PATCH] Add regexp routine (base on boost::expressive). --- platform/platform.pro | 1 + platform/platform_tests/platform_tests.pro | 1 + platform/platform_tests/regexp_test.cpp | 22 ++++++++++++++++++++++ platform/regexp.hpp | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 platform/platform_tests/regexp_test.cpp create mode 100644 platform/regexp.hpp 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 + +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); + } +}