Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_wildcard_pattern.cpp
Go to the documentation of this file.
1/*
2 * Created by Martin on 19/07/2017.
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See accompanying
5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7
9#include "catch_enforce.h"
10#include "catch_string_manip.h"
11
12#include <sstream>
13
14namespace Catch {
15
16 WildcardPattern::WildcardPattern( std::string const& pattern,
17 CaseSensitive::Choice caseSensitivity )
18 : m_caseSensitivity( caseSensitivity ),
19 m_pattern( adjustCase( pattern ) )
20 {
21 if( startsWith( m_pattern, '*' ) ) {
22 m_pattern = m_pattern.substr( 1 );
23 m_wildcard = WildcardAtStart;
24 }
25 if( endsWith( m_pattern, '*' ) ) {
26 m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
27 m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
28 }
29 }
30
31 bool WildcardPattern::matches( std::string const& str ) const {
32 switch( m_wildcard ) {
33 case NoWildcard:
34 return m_pattern == adjustCase( str );
35 case WildcardAtStart:
36 return endsWith( adjustCase( str ), m_pattern );
37 case WildcardAtEnd:
38 return startsWith( adjustCase( str ), m_pattern );
39 case WildcardAtBothEnds:
40 return contains( adjustCase( str ), m_pattern );
41 default:
42 CATCH_INTERNAL_ERROR( "Unknown enum" );
43 }
44 }
45
46 std::string WildcardPattern::adjustCase( std::string const& str ) const {
47 return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
48 }
49}
#define CATCH_INTERNAL_ERROR(msg)
WildcardPattern(std::string const &pattern, CaseSensitive::Choice caseSensitivity)
virtual bool matches(std::string const &str) const
bool startsWith(std::string const &s, std::string const &prefix)
bool contains(std::string const &s, std::string const &infix)
std::string toLower(std::string const &s)
bool endsWith(std::string const &s, std::string const &suffix)