[ox/std] Add IString::unsafeResize

This commit is contained in:
Gary Talent 2024-09-06 21:19:59 -05:00
parent 36057bb010
commit ba4540e43f

View File

@ -81,6 +81,11 @@ class IString {
constexpr ox::Error resize(size_t sz) noexcept; constexpr ox::Error resize(size_t sz) noexcept;
/**
* Resizes without clearing memory between current end and new end.
*/
constexpr ox::Error unsafeResize(size_t sz) noexcept;
/** /**
* Returns the capacity of bytes for this string. * Returns the capacity of bytes for this string.
*/ */
@ -220,6 +225,15 @@ constexpr ox::Error IString<StrCap>::resize(size_t sz) noexcept {
return {}; return {};
} }
template<std::size_t StrCap>
constexpr ox::Error IString<StrCap>::unsafeResize(size_t sz) noexcept {
if (sz > StrCap) [[unlikely]] {
return OxError(1, "Trying to extend IString beyond its cap");
}
m_size = sz;
return {};
}
template<size_t sz> template<size_t sz>
struct MaybeView<ox::IString<sz>> { struct MaybeView<ox::IString<sz>> {
using type = ox::StringView; using type = ox::StringView;