add comparisons against standard strings
parent
a539d6c945
commit
3df3ece0d2
|
@ -432,7 +432,7 @@ protected:
|
|||
return nullptr;
|
||||
}
|
||||
for (auto const &nm: p_names) {
|
||||
if (name == iter(nm)) {
|
||||
if (name == nm) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1168,7 +1168,7 @@ public:
|
|||
bool allow_optional = true;
|
||||
while (!args.empty()) {
|
||||
string_range s{args.front()};
|
||||
if (s == citer(p_pos_sep)) {
|
||||
if (s == p_pos_sep) {
|
||||
args.pop_front();
|
||||
allow_optional = false;
|
||||
continue;
|
||||
|
|
122
ostd/string.hh
122
ostd/string.hh
|
@ -520,6 +520,128 @@ inline std::enable_if_t<
|
|||
return rhs.compare(lhs) <= 0;
|
||||
}
|
||||
|
||||
/* comparisons between ranges and stdlib strings */
|
||||
|
||||
/** @brief Like `!lhs.compare(rhs)`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator==(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return !lhs.compare(rhs);
|
||||
}
|
||||
|
||||
/** @brief Like `lhs.compare(rhs)`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator!=(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return lhs.compare(rhs);
|
||||
}
|
||||
|
||||
/** @brief Like `lhs.compare(rhs) < 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator<(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
|
||||
/** @brief Like `lhs.compare(rhs) > 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator>(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return lhs.compare(rhs) > 0;
|
||||
}
|
||||
|
||||
/** @brief Like `lhs.compare(rhs) <= 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator<=(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return lhs.compare(rhs) <= 0;
|
||||
}
|
||||
|
||||
/** @brief Like `lhs.compare(rhs) >= 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator>=(
|
||||
basic_char_range<T, TR> lhs, std::basic_string<U, TR, A> const &rhs
|
||||
) noexcept {
|
||||
return lhs.compare(rhs) >= 0;
|
||||
}
|
||||
|
||||
/** @brief Like `!rhs.compare(lhs)`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator==(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return !rhs.compare(lhs);
|
||||
}
|
||||
|
||||
/** @brief Like `rhs.compare(lhs)`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator!=(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return rhs.compare(lhs);
|
||||
}
|
||||
|
||||
/** @brief Like `rhs.compare(lhs) > 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator<(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return rhs.compare(lhs) > 0;
|
||||
}
|
||||
|
||||
/** @brief Like `rhs.compare(lhs) < 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator>(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return rhs.compare(lhs) < 0;
|
||||
}
|
||||
|
||||
/** @brief Like `rhs.compare(lhs) >= 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator<=(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return rhs.compare(lhs) >= 0;
|
||||
}
|
||||
|
||||
/** @brief Like `rhs.compare(lhs) <= 0`. */
|
||||
template<typename T, typename TR, typename U, typename A>
|
||||
inline std::enable_if_t<
|
||||
std::is_same_v<std::remove_const_t<T>, std::remove_const_t<U>>, bool
|
||||
> operator>=(
|
||||
std::basic_string<U, TR, A> const &lhs, basic_char_range<T, TR> rhs
|
||||
) noexcept {
|
||||
return rhs.compare(lhs) <= 0;
|
||||
}
|
||||
|
||||
/** @brief Checks if a string slice starts with another slice. */
|
||||
inline bool starts_with(string_range a, string_range b) noexcept {
|
||||
if (a.size() < b.size()) {
|
||||
|
|
Loading…
Reference in New Issue