|
24 | 24 | #include <algorithm> |
25 | 25 | #include <cctype> |
26 | 26 | #include <format> |
| 27 | +#include <span> |
27 | 28 | #include <stdexcept> |
28 | | -#include <string> |
| 29 | +#include <string_view> |
29 | 30 | #include <vector> |
30 | 31 |
|
31 | 32 |
|
@@ -194,6 +195,40 @@ class CppStringT : public std::basic_string<CharT> |
194 | 195 | } |
195 | 196 |
|
196 | 197 |
|
| 198 | + //--- endswith() -------------------------------------- |
| 199 | + /** Returns true if the string ends with the specified suffix, otherwise return false. Test begins at start position and stops at end position. */ |
| 200 | + inline const bool endswith(const CppStringT& suffix, const size_type start, const size_type end) const noexcept |
| 201 | + { |
| 202 | + return endswith(std::span{ suffix }, start, end); |
| 203 | + } |
| 204 | + |
| 205 | + /** Returns true if the string ends with the specified suffix, otherwise return false. Test begins at start position and stops at end of string. */ |
| 206 | + inline const bool endswith(const CppStringT& suffix, const size_type start) const noexcept |
| 207 | + { |
| 208 | + return endswith(std::span{ suffix }, start, this->size()-1); |
| 209 | + } |
| 210 | + |
| 211 | + /** Returns true if the string ends with the specified suffix, otherwise return false. Test runs on the whole string. */ |
| 212 | + inline const bool endswith(const CppStringT& suffix) const noexcept |
| 213 | + { |
| 214 | + return this->ends_with(suffix); |
| 215 | + } |
| 216 | + |
| 217 | + /** Returns true if the string ends with any of the specified suffixes, otherwise return false. Test begins at start position and stops at end of string. */ |
| 218 | + inline const bool endswith(const std::span<CppStringT>& suffixes, const size_type start, const size_type end) const noexcept |
| 219 | + { |
| 220 | + if (start > end) |
| 221 | + return false; |
| 222 | + |
| 223 | + for (auto& suffix : suffixes) { |
| 224 | + if (this->substr(start, end).ends_with(suffix)) |
| 225 | + return true; |
| 226 | + } |
| 227 | + |
| 228 | + return false; |
| 229 | + } |
| 230 | + |
| 231 | + |
197 | 232 | //--- find_n() ---------------------------------------- |
198 | 233 | /** Returns the lowest index in the string where substring sub is found within the slice str[start:start+count-1], or -1 (i.e. 'npos') if sub is not found. |
199 | 234 | * |
|
0 commit comments