| 77 | }; |
| 78 | |
| 79 | cmList CMakeString::Match(std::string const& matchExpression, |
| 80 | MatchItems matchItems, cmMakefile* makefile) const |
| 81 | { |
| 82 | if (makefile) { |
| 83 | makefile->ClearMatches(); |
| 84 | } |
| 85 | |
| 86 | // Compile the regular expression. |
| 87 | cmsys::RegularExpression re; |
| 88 | if (!re.compile(matchExpression)) { |
| 89 | throw std::invalid_argument( |
| 90 | cmStrCat("Failed to compile regex \"", matchExpression, '"')); |
| 91 | } |
| 92 | |
| 93 | cmList output; |
| 94 | if (matchItems == MatchItems::Once) { |
| 95 | if (re.find(this->String_.data())) { |
| 96 | if (makefile) { |
| 97 | makefile->StoreMatches(re); |
| 98 | } |
| 99 | output.push_back(re.match()); |
| 100 | } |
| 101 | } else { |
| 102 | unsigned optAnchor = 0; |
| 103 | if (makefile && |
| 104 | makefile->GetPolicyStatus(cmPolicies::CMP0186) != cmPolicies::NEW) { |
| 105 | optAnchor = cmsys::RegularExpression::BOL_AT_OFFSET; |
| 106 | } |
| 107 | |
| 108 | // Scan through the input for all matches. |
| 109 | std::string::size_type base = 0; |
| 110 | unsigned optNonEmpty = 0; |
| 111 | while (re.find(this->String_.data(), base, optAnchor | optNonEmpty)) { |
| 112 | if (makefile) { |
| 113 | makefile->ClearMatches(); |
| 114 | makefile->StoreMatches(re); |
| 115 | } |
| 116 | |
| 117 | output.push_back(re.match()); |
| 118 | base = re.end(); |
| 119 | |
| 120 | if (re.start() == this->String_.length()) { |
| 121 | break; |
| 122 | } |
| 123 | if (re.start() == re.end()) { |
| 124 | optNonEmpty = cmsys::RegularExpression::NONEMPTY_AT_OFFSET; |
| 125 | } else { |
| 126 | optNonEmpty = 0; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return output; |
| 132 | } |
| 133 | |
| 134 | CMakeString CMakeString::Substring(long begin, long count) const |
| 135 | { |
no test coverage detected