summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-01-02 16:55:06 -0600
committerDominick Allen <djallen@librehumanitas.org>2025-01-02 16:55:06 -0600
commit908fdf06b41f9084d719a4b517c868b1ad29a9ac (patch)
tree82b58e8afea2f0fc01c67e71241c2b93678ae42e /include
parent8f12614f2da8221438a3807b1d234517650fbdb6 (diff)
Fix warnings from clang-tidy in fud_format.hpp
Diffstat (limited to 'include')
-rw-r--r--include/fud_format.hpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/include/fud_format.hpp b/include/fud_format.hpp
index 9be3dd9..8dd2231 100644
--- a/include/fud_format.hpp
+++ b/include/fud_format.hpp
@@ -30,9 +30,7 @@
#include "fud_string_view.hpp"
#include "fud_utf8.hpp"
-#include <concepts>
#include <cstdint>
-#include <format>
#include <limits>
#include <variant>
#include <cstdio>
@@ -41,16 +39,17 @@ namespace fud {
// TODO: constants file?
constexpr size_t bitsPerOctal = 3;
-constexpr size_t maxIntCharCount = bitsPerOctal * sizeof(uint64_t) + 4;
+constexpr size_t maxIntCharCount = (bitsPerOctal * sizeof(uint64_t)) + 4;
struct FormatString {
template <size_t N>
- consteval FormatString(const utf8 (&input)[N]) : m_size{N - 1}, m_data{input}
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
+ consteval FormatString(const utf8 (&input)[N]) : m_size{N - 1}, m_data{input}
{
static_assert(N > 0);
}
- StringView view()
+ [[nodiscard]] StringView view() const
{
return StringView{m_size, m_data};
}
@@ -75,7 +74,7 @@ struct FormatAlign {
constexpr static Option<FormatAlign> from(utf8 letter)
{
- FormatAlign formatAlign;
+ FormatAlign formatAlign{};
switch (letter) {
case '<':
formatAlign.value = Value::Left;
@@ -247,7 +246,7 @@ template <size_t Size>
struct FormatArguments {
Array<FormatArgument, Size> arguments;
- constexpr size_t size() const
+ [[nodiscard]] constexpr size_t size() const
{
return Size;
}
@@ -260,13 +259,11 @@ struct FormatArguments {
template <typename... Args>
static auto makeFormatArguments(Args&&... args) -> FormatArguments
{
- return FormatArguments{Array<FormatArgument, Size>{{FormatArgument{args}...}}};
+ return FormatArguments{Array<FormatArgument, Size>{{FormatArgument{std::forward<Args>(args)}...}}};
}
};
-static_assert(sizeof(FormatArguments<1>) > 0);
-
-enum class FormatCharMode
+enum class FormatCharMode : uint8_t
{
Unchecked,
AsciiOnly,
@@ -726,6 +723,7 @@ FudStatus fillSignedBuffer(IntCharArray& buffer, T value, uint8_t& bufferLength,
} else {
unsignedValue = static_cast<uint64_t>(value);
}
+ // NOLINTNEXTLINE(bugprone-branch-clone)
if constexpr (std::is_same_v<T, char>) {
return fillUnsignedBuffer(buffer, static_cast<uint8_t>(unsignedValue), bufferLength, radix, uppercase);
} else if constexpr (std::is_same_v<T, int8_t>) {
@@ -735,7 +733,7 @@ FudStatus fillSignedBuffer(IntCharArray& buffer, T value, uint8_t& bufferLength,
} else if constexpr (std::is_same_v<T, int32_t>) {
return fillUnsignedBuffer(buffer, static_cast<uint32_t>(unsignedValue), bufferLength, radix, uppercase);
} else if constexpr (std::is_same_v<T, int64_t>) {
- return fillUnsignedBuffer(buffer, static_cast<uint64_t>(unsignedValue), bufferLength, radix, uppercase);
+ return fillUnsignedBuffer(buffer, unsignedValue, bufferLength, radix, uppercase);
}
}
@@ -1294,10 +1292,13 @@ template <typename Sink, typename T>
using FormatType::GeneralLower, FormatType::GeneralUpper;
using FormatType::ScientificLower, FormatType::ScientificUpper;
+ // NOLINTNEXTLINE(bugprone-branch-clone)
if (floatSpec.formatType == FloatHexLower || floatSpec.formatType == FloatHexUpper) {
+ // do nothing - not implemented
} else if (floatSpec.formatType == ScientificLower || floatSpec.formatType == ScientificUpper) {
return formatScientific(sink, floatSpec, decimalRepr, uppercase);
} else if (floatSpec.formatType == FixedLower || floatSpec.formatType == FixedUpper) {
+ // do nothing - not implemented
} else if (floatSpec.formatType == GeneralLower || floatSpec.formatType == GeneralUpper) {
} else {
result.status = FudStatus::FormatInvalid;
@@ -1385,6 +1386,7 @@ FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& for
template <typename Sink>
FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& formatSpec, const utf8* arg)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return format(sink, formatMode, formatSpec, reinterpret_cast<const char*>(arg));
}