libhext: C++ Library Documentation  1.0.8-3ad0ae4
ContainsTest.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_CONTAINS_TEST_H_INCLUDED
16 #define HEXT_CONTAINS_TEST_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::ContainsTest
20 
21 #include "hext/Cloneable.h"
22 #include "hext/ValueTest.h"
23 #include "hext/Visibility.h"
24 
25 #include <string>
26 
27 
28 namespace hext {
29 
30 
31 /// Tests whether a string contains a given literal.
32 ///
33 /// @par Example:
34 /// ~~~~~~~~~~~~~
35 /// ContainsTest contains("foo");
36 ///
37 /// assert( contains.test("foo"));
38 /// assert( contains.test("barfoobar"));
39 /// assert(!contains.test("barfo"));
40 /// ~~~~~~~~~~~~~
41 class HEXT_PUBLIC ContainsTest final : public Cloneable<ContainsTest, ValueTest>
42 {
43 public:
44  /// Constructs a ContainsTest that succeeds for subjects that contain the
45  /// given literal.
46  ///
47  /// @param literal: A string that a subject must contain.
48  explicit ContainsTest(std::string literal) noexcept;
49 
50  /// Return true if subject contains the given literal.
51  ///
52  /// @param subject: The string that is to be tested.
53  bool test(const char * subject) const override;
54 
55 private:
56  /// The literal that must be matched.
57  std::string lit_;
58 };
59 
60 
61 } // namespace hext
62 
63 
64 #endif // HEXT_CONTAINS_TEST_H_INCLUDED
65 
Defines template hext::Cloneable.
Declares hext::ValueTest.
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:37
Tests whether a string contains a given literal.
Definition: ContainsTest.h:42
bool test(const char *subject) const override
Return true if subject contains the given literal.
ContainsTest(std::string literal) noexcept
Constructs a ContainsTest that succeeds for subjects that contain the given literal.