Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Wildcard Class Reference

#include <ored/utilities/wildcard.hpp>

+ Collaboration diagram for Wildcard:

Public Member Functions

 Wildcard (const std::string &pattern, const bool usePrefixes=true, const bool aggressivePrefixes=false)
 
bool hasWildcard () const
 
std::size_t wildcardPos () const
 
bool isPrefix () const
 
bool matches (const std::string &s) const
 
const std::string & pattern () const
 
const std::string & regex () const
 
const std::string & prefix () const
 

Private Attributes

std::string pattern_
 
bool usePrefixes_
 
bool aggressivePrefixes_
 
bool hasWildCard_ = false
 
std::size_t wildCardPos_
 
boost::optional< std::string > regexString_
 
boost::optional< std::string > prefixString_
 
QuantLib::ext::shared_ptr< std::regex > regex_
 

Detailed Description

Definition at line 36 of file wildcard.hpp.

Constructor & Destructor Documentation

◆ Wildcard()

Wildcard ( const std::string &  pattern,
const bool  usePrefixes = true,
const bool  aggressivePrefixes = false 
)
explicit

all characters in s keep their original meaning except * which is a placeholder for zero or more characters not equal to newline

Definition at line 39 of file wildcard.cpp.

40 : pattern_(pattern), usePrefixes_(usePrefixes), aggressivePrefixes_(aggressivePrefixes) {
41
42 wildCardPos_ = pattern_.find("*");
43
44 if (wildCardPos_ == std::string::npos)
45 return;
46
47 hasWildCard_ = true;
48
49 if (usePrefixes && (aggressivePrefixes || wildCardPos_ == pattern_.size() - 1)) {
51 } else {
53 static std::vector<std::string> specialChars = {"\\", ".", "+", "?", "^", "$", "(",
54 ")", "[", "]", "{", "}", "|"};
55 for (auto const& c : specialChars) {
56 boost::replace_all(*regexString_, c, "\\" + c);
57 }
58 boost::replace_all(*regexString_, "*", ".*");
59 }
60}
boost::optional< std::string > prefixString_
Definition: wildcard.hpp:60
const std::string & pattern() const
Definition: wildcard.cpp:80
boost::optional< std::string > regexString_
Definition: wildcard.hpp:59
std::size_t wildCardPos_
Definition: wildcard.hpp:58
std::string pattern_
Definition: wildcard.hpp:53

Member Function Documentation

◆ hasWildcard()

bool hasWildcard ( ) const

Definition at line 62 of file wildcard.cpp.

62{ return hasWildCard_; }
+ Here is the caller graph for this function:

◆ wildcardPos()

std::size_t wildcardPos ( ) const

Definition at line 64 of file wildcard.cpp.

64{ return wildCardPos_; }
+ Here is the caller graph for this function:

◆ isPrefix()

bool isPrefix ( ) const

Definition at line 66 of file wildcard.cpp.

66{ return prefixString_ ? true : false; }
+ Here is the caller graph for this function:

◆ matches()

bool matches ( const std::string &  s) const

Definition at line 68 of file wildcard.cpp.

68 {
69 if (prefixString_) {
70 return s.substr(0, (*prefixString_).size()) == (*prefixString_);
71 } else if (regexString_) {
72 if (regex_ == nullptr)
73 regex_ = QuantLib::ext::make_shared<std::regex>(*regexString_);
74 return std::regex_match(s, *regex_);
75 } else {
76 return s == pattern_;
77 }
78}
QuantLib::ext::shared_ptr< std::regex > regex_
Definition: wildcard.hpp:61
+ Here is the caller graph for this function:

◆ pattern()

const std::string & pattern ( ) const

Definition at line 80 of file wildcard.cpp.

80{ return pattern_; }
+ Here is the caller graph for this function:

◆ regex()

const std::string & regex ( ) const

Definition at line 82 of file wildcard.cpp.

82 {
83 QL_REQUIRE(regexString_, "string '" << pattern_ << "' is not a regex (usePrefixes = " << std::boolalpha
84 << usePrefixes_ << ", aggressivePrefixes = " << aggressivePrefixes_
85 << ", isPrefix = " << !prefixString_ << ")");
86 return *regexString_;
87}
+ Here is the caller graph for this function:

◆ prefix()

const std::string & prefix ( ) const

Definition at line 89 of file wildcard.cpp.

89 {
90 QL_REQUIRE(prefixString_, "string '" << pattern_ << "' is not a prefix (usePrefixes = " << std::boolalpha
91 << usePrefixes_ << ", aggressivePrefixes = " << aggressivePrefixes_
92 << ", isRegex = " << !regexString_ << ")");
93 return *prefixString_;
94}
+ Here is the caller graph for this function:

Member Data Documentation

◆ pattern_

std::string pattern_
private

Definition at line 53 of file wildcard.hpp.

◆ usePrefixes_

bool usePrefixes_
private

Definition at line 54 of file wildcard.hpp.

◆ aggressivePrefixes_

bool aggressivePrefixes_
private

Definition at line 55 of file wildcard.hpp.

◆ hasWildCard_

bool hasWildCard_ = false
private

Definition at line 57 of file wildcard.hpp.

◆ wildCardPos_

std::size_t wildCardPos_
private

Definition at line 58 of file wildcard.hpp.

◆ regexString_

boost::optional<std::string> regexString_
private

Definition at line 59 of file wildcard.hpp.

◆ prefixString_

boost::optional<std::string> prefixString_
private

Definition at line 60 of file wildcard.hpp.

◆ regex_

QuantLib::ext::shared_ptr<std::regex> regex_
mutableprivate

Definition at line 61 of file wildcard.hpp.