[ox/std] Make substr always take and return a StringView

This commit is contained in:
Gary Talent 2024-05-02 22:20:25 -05:00
parent 59aa4ad21a
commit fda1280d29

View File

@ -14,26 +14,23 @@
#include "stringview.hpp"
#include "types.hpp"
#include "vector.hpp"
#include "writer.hpp"
namespace ox {
template<OxString_c Str>
[[nodiscard]]
constexpr Str substr(Str const&str, std::size_t pos) noexcept {
constexpr ox::StringView substr(ox::StringView const&str, std::size_t pos) noexcept {
if (str.len() >= pos) {
return Str(str.data() + pos, str.len() - pos);
return {str.data() + pos, str.len() - pos};
}
return Str();
return {};
}
template<OxString_c Str>
[[nodiscard]]
constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t end) noexcept {
constexpr ox::StringView substr(ox::StringView const&str, std::size_t start, std::size_t end) noexcept {
if (str.len() >= start && end >= start) {
return Str(str.data() + start, end - start);
return {str.data() + start, end - start};
}
return Str();
return {};
}
template<typename Integer>