All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
BeginsWithTest.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_BEGINS_WITH_TEST_H_INCLUDED
16 #define HEXT_BEGINS_WITH_TEST_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::BeginsWithTest
20 
21 #include "hext/Cloneable.h"
22 #include "hext/ValueTest.h"
23 
24 #include <string>
25 
26 
27 namespace hext {
28 
29 
30 /// Tests whether a string begins with a given literal.
31 ///
32 /// @par Example:
33 /// ~~~~~~~~~~~~~
34 /// BeginsWithTest begins("Start");
35 ///
36 /// assert( begins.test("Startles your sleeping ears to hear"));
37 /// assert(!begins.test("startles your sleeping ears to hear"));
38 /// assert(!begins.test(""));
39 /// ~~~~~~~~~~~~~
40 class BeginsWithTest final : public Cloneable<BeginsWithTest, ValueTest>
41 {
42 public:
43  /// Constructs a BeginsWithTest that succeeds for subjects that begin with
44  /// the given literal.
45  ///
46  /// @param literal: A string that a subject must begin with.
47  explicit BeginsWithTest(std::string literal) noexcept;
48 
49  /// Return true if subject begins with the given literal.
50  ///
51  /// @param subject: The string that is to be tested.
52  bool test(const char * subject) const override;
53 
54 private:
55  /// The literal that must be matched.
56  std::string lit_;
57 };
58 
59 
60 } // namespace hext
61 
62 
63 #endif // HEXT_BEGINS_WITH_TEST_H_INCLUDED
64 
bool test(const char *subject) const override
Return true if subject begins with the given literal.
Tests whether a string begins with a given literal.
BeginsWithTest(std::string literal) noexcept
Constructs a BeginsWithTest that succeeds for subjects that begin with the given literal.
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.