[ox/std] Make substr always take and return a StringView
This commit is contained in:
parent
59aa4ad21a
commit
fda1280d29
15
deps/ox/src/ox/std/strops.hpp
vendored
15
deps/ox/src/ox/std/strops.hpp
vendored
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user