[ox/std] Make sfmt usable as constexpr
This commit is contained in:
parent
6da3d3b8f5
commit
5ed806f4c0
6
deps/ox/src/ox/std/assert.hpp
vendored
6
deps/ox/src/ox/std/assert.hpp
vendored
@ -8,6 +8,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<cassert>)
|
||||
#include <cassert>
|
||||
#else
|
||||
#define assert(e) {}
|
||||
#endif
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
|
6
deps/ox/src/ox/std/bstring.hpp
vendored
6
deps/ox/src/ox/std/bstring.hpp
vendored
@ -45,7 +45,7 @@ class BString {
|
||||
|
||||
constexpr char &operator[](std::size_t i) noexcept;
|
||||
|
||||
Error append(const char *str, std::size_t strLen) noexcept;
|
||||
constexpr Error append(const char *str, std::size_t strLen) noexcept;
|
||||
|
||||
constexpr char *data() noexcept;
|
||||
|
||||
@ -153,14 +153,14 @@ constexpr char &BString<buffLen>::operator[](std::size_t i) noexcept {
|
||||
}
|
||||
|
||||
template<std::size_t buffLen>
|
||||
Error BString<buffLen>::append(const char *str, std::size_t strLen) noexcept {
|
||||
constexpr Error BString<buffLen>::append(const char *str, std::size_t strLen) noexcept {
|
||||
Error err;
|
||||
auto currentLen = len();
|
||||
if (cap() < currentLen + strLen + 1) {
|
||||
strLen = cap() - currentLen;
|
||||
err = OxError(1, "Insufficient space for full string");
|
||||
}
|
||||
ox_memcpy(m_buff + currentLen, str, strLen);
|
||||
ox_strncpy(m_buff + currentLen, str, strLen);
|
||||
// make sure last element is a null terminator
|
||||
m_buff[currentLen + strLen] = 0;
|
||||
return err;
|
||||
|
4
deps/ox/src/ox/std/fmt.hpp
vendored
4
deps/ox/src/ox/std/fmt.hpp
vendored
@ -169,8 +169,8 @@ constexpr Fmt<segementCnt> fmtSegments(const char *fmt) noexcept {
|
||||
|
||||
template<typename StringType = String, typename ...Args>
|
||||
[[nodiscard]]
|
||||
StringType sfmt(const char *fmt, Args... args) noexcept {
|
||||
oxAssert(ox::detail::argCount(fmt) == sizeof...(args), "Argument count mismatch.");
|
||||
constexpr StringType sfmt(const char *fmt, Args... args) noexcept {
|
||||
assert(ox::detail::argCount(fmt) == sizeof...(args));
|
||||
StringType out;
|
||||
const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt);
|
||||
const auto &firstSegment = fmtSegments.segments[0];
|
||||
|
Loading…
Reference in New Issue
Block a user