[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
|
#pragma once
|
||||||
|
|
||||||
|
#if __has_include(<cassert>)
|
||||||
|
#include <cassert>
|
||||||
|
#else
|
||||||
|
#define assert(e) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "error.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;
|
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;
|
constexpr char *data() noexcept;
|
||||||
|
|
||||||
@ -153,14 +153,14 @@ constexpr char &BString<buffLen>::operator[](std::size_t i) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t buffLen>
|
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;
|
Error err;
|
||||||
auto currentLen = len();
|
auto currentLen = len();
|
||||||
if (cap() < currentLen + strLen + 1) {
|
if (cap() < currentLen + strLen + 1) {
|
||||||
strLen = cap() - currentLen;
|
strLen = cap() - currentLen;
|
||||||
err = OxError(1, "Insufficient space for full string");
|
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
|
// make sure last element is a null terminator
|
||||||
m_buff[currentLen + strLen] = 0;
|
m_buff[currentLen + strLen] = 0;
|
||||||
return err;
|
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>
|
template<typename StringType = String, typename ...Args>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
StringType sfmt(const char *fmt, Args... args) noexcept {
|
constexpr StringType sfmt(const char *fmt, Args... args) noexcept {
|
||||||
oxAssert(ox::detail::argCount(fmt) == sizeof...(args), "Argument count mismatch.");
|
assert(ox::detail::argCount(fmt) == sizeof...(args));
|
||||||
StringType out;
|
StringType out;
|
||||||
const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt);
|
const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt);
|
||||||
const auto &firstSegment = fmtSegments.segments[0];
|
const auto &firstSegment = fmtSegments.segments[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user