All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RegexTest.h
Go to the documentation of this file.
1 // Copyright 2015, 2016 Thomas Trapp
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEXT_REGEX_TEST_H_INCLUDED
16 #define HEXT_REGEX_TEST_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::RegexTest
20 
21 #include "hext/Cloneable.h"
22 #include "hext/ValueTest.h"
23 #include "hext/Visibility.h"
24 
25 #include <boost/regex.hpp>
26 
27 
28 namespace hext {
29 
30 
31 /// Tests whether another string matches a given regex.
32 ///
33 /// @par Example:
34 /// ~~~~~~~~~~~~~
35 /// RegexTest has_number(boost::regex("\\d+"));
36 /// assert( has_number.test("Nr. 23!"));
37 /// assert( has_number.test("23"));
38 /// assert(!has_number.test("foo"));
39 ///
40 /// RegexTest is_date(boost::regex("^\\d{2}-\\d{2}-\\d{4}$"));
41 /// assert( is_date.test("01-01-1970"));
42 /// assert( is_date.test("19-01-2038"));
43 /// assert(!is_date.test("09-09-99"));
44 /// assert(!is_date.test("Born on 09-09-1941."));
45 /// ~~~~~~~~~~~~~
46 class HEXT_PUBLIC RegexTest final : public Cloneable<RegexTest, ValueTest>
47 {
48 public:
49  /// Constructs a RegexTest that succeeds if a subject matches regex.
50  explicit RegexTest(boost::regex regex);
51 
52  /// Returns true if given regex matches subject.
53  bool test(const char * subject) const override;
54 
55 private:
56  /// The regex a subject has to match.
57  boost::regex rx_;
58 };
59 
60 
61 } // namespace hext
62 
63 
64 #endif // HEXT_REGEX_TEST_H_INCLUDED
65 
Defines HEXT_PUBLIC and HEXT_PRIVATE.
#define HEXT_PUBLIC
Definition: Visibility.h:26
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:36
Declares hext::ValueTest.
Defines template hext::Cloneable.
Tests whether another string matches a given regex.
Definition: RegexTest.h:46