All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
RegexTest.h
Go to the documentation of this file.
1 // Copyright 2015 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 
24 #include <boost/regex.hpp>
25 
26 
27 namespace hext {
28 
29 
30 /// Tests whether another string matches a given regex.
31 ///
32 /// @par Example:
33 /// ~~~~~~~~~~~~~
34 /// RegexTest has_number(boost::regex("\\d+"));
35 /// assert( has_number.test("Nr. 23!"));
36 /// assert( has_number.test("23"));
37 /// assert(!has_number.test("foo"));
38 ///
39 /// RegexTest is_date(boost::regex("^\\d{2}-\\d{2}-\\d{4}$"));
40 /// assert( is_date.test("01-01-1970"));
41 /// assert( is_date.test("19-01-2038"));
42 /// assert(!is_date.test("09-09-99"));
43 /// assert(!is_date.test("Born on 09-09-1941."));
44 /// ~~~~~~~~~~~~~
45 class RegexTest final : public Cloneable<RegexTest, ValueTest>
46 {
47 public:
48  /// Constructs a RegexTest that succeeds if a subject matches regex.
49  explicit RegexTest(boost::regex regex);
50 
51  /// Returns true if given regex matches subject.
52  bool test(const char * subject) const override;
53 
54 private:
55  /// The regex a subject has to match.
56  boost::regex rx_;
57 };
58 
59 
60 } // namespace hext
61 
62 
63 #endif // HEXT_REGEX_TEST_H_INCLUDED
64 
bool test(const char *subject) const override
Returns true if given regex matches subject.
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:34
Declares hext::ValueTest.
Defines template hext::Cloneable.
Tests whether another string matches a given regex.
Definition: RegexTest.h:45
RegexTest(boost::regex regex)
Constructs a RegexTest that succeeds if a subject matches regex.