[ox/std] Make substr support CStringView, and always return a StringView

This commit is contained in:
Gary Talent 2023-11-30 23:15:51 -06:00
parent 232a166833
commit fc5e63a4d7
2 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,7 @@ namespace ox {
template<OxString_c Str> template<OxString_c Str>
[[nodiscard]] [[nodiscard]]
constexpr Str substr(Str const&str, std::size_t pos) noexcept { constexpr ox::StringView substr(Str const&str, std::size_t pos) noexcept {
if (str.len() >= pos) { if (str.len() >= pos) {
return Str(str.data() + pos, str.len() - pos); return Str(str.data() + pos, str.len() - pos);
} }
@ -29,7 +29,7 @@ constexpr Str substr(Str const&str, std::size_t pos) noexcept {
template<OxString_c Str> template<OxString_c Str>
[[nodiscard]] [[nodiscard]]
constexpr Str substr(Str const&str, std::size_t start, std::size_t end) noexcept { constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t end) noexcept {
if (str.len() >= start && end >= start) { if (str.len() >= start && end >= start) {
return Str(str.data() + start, end - start); return Str(str.data() + start, end - start);
} }

View File

@ -273,6 +273,7 @@ template<std::size_t SmallStringSize>
class BasicString; class BasicString;
template<std::size_t sz> template<std::size_t sz>
class BString; class BString;
class CStringView;
class StringLiteral; class StringLiteral;
class StringView; class StringView;
@ -292,6 +293,10 @@ constexpr auto isOxString(const BString<sz>*) noexcept {
return true; return true;
} }
constexpr auto isOxString(const CStringView*) noexcept {
return true;
}
constexpr auto isOxString(const StringLiteral*) noexcept { constexpr auto isOxString(const StringLiteral*) noexcept {
return true; return true;
} }