mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 16:26:27 +08:00
NFC: linting fixes
This commit is contained in:
parent
181ef323a5
commit
3a9c8dcdff
@ -1,9 +1,9 @@
|
||||
#ifndef FMT_C_API_H
|
||||
#define FMT_C_API_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define FMT_C_ABI_VERSION 1
|
||||
@ -252,13 +252,12 @@ static inline FmtArg fmt_identity(FmtArg x) { return x; }
|
||||
# define FMT_MAP(f, ...) \
|
||||
FMT_CAT(FMT_MAP_, FMT_NARG(__VA_ARGS__))(f, ##__VA_ARGS__)
|
||||
|
||||
# define fmt_format(buf, cap, fmt, ...) \
|
||||
# define fmt_format(buf, cap, fmt, ...) \
|
||||
fmt_c_format( \
|
||||
buf, cap, fmt, \
|
||||
(FmtArg[]){{FMT_INT}, FMT_MAP(FMT_MAKE_ARG, ##__VA_ARGS__)} + 1, \
|
||||
FMT_NARG(__VA_ARGS__))
|
||||
|
||||
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // FMT_C_API_H
|
||||
13
src/fmt-c.cc
13
src/fmt-c.cc
@ -9,7 +9,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
int fmt_c_get_version(void) { return FMT_C_ABI_VERSION; }
|
||||
@ -62,7 +61,8 @@ static bool populate_store(const FmtArg* c_args, size_t arg_count,
|
||||
|
||||
case FMT_CUSTOM: {
|
||||
if (!c_args[i].custom_fn || !c_args[i].value.ptr) {
|
||||
g_fixed_store[i] = fmt::basic_format_arg<Context>(fmt::string_view("<error>"));
|
||||
g_fixed_store[i] =
|
||||
fmt::basic_format_arg<Context>(fmt::string_view("<error>"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -90,14 +90,13 @@ static bool populate_store(const FmtArg* c_args, size_t arg_count,
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int fmt_c_format(char* buffer, size_t capacity, const char* format_str,
|
||||
const FmtArg* args, size_t arg_count) {
|
||||
const FmtArg* args, size_t arg_count) {
|
||||
if (!format_str) return FMT_ERR_NULL_FORMAT;
|
||||
if (arg_count > FMT_C_MAX_ARGS) return FMT_ERR_INVALID_ARG;
|
||||
|
||||
@ -119,7 +118,8 @@ int fmt_c_format(char* buffer, size_t capacity, const char* format_str,
|
||||
return static_cast<int>(result.size);
|
||||
}
|
||||
|
||||
auto result = fmt::vformat_to_n(buffer, capacity - 1, format_str, format_args_view);
|
||||
auto result =
|
||||
fmt::vformat_to_n(buffer, capacity - 1, format_str, format_args_view);
|
||||
*result.out = '\0';
|
||||
return static_cast<int>(result.size);
|
||||
|
||||
@ -130,5 +130,4 @@ int fmt_c_format(char* buffer, size_t capacity, const char* format_str,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // extern "C"
|
||||
@ -297,7 +297,7 @@ TEST(all_integer_types) {
|
||||
unsigned long long ull = 800ULL;
|
||||
|
||||
fmt_format(buf, sizeof(buf), "{} {} {} {} {} {} {} {}", s, i, l, ll, us, ui,
|
||||
ul, ull);
|
||||
ul, ull);
|
||||
ASSERT_TRUE(strstr(buf, "100") != NULL);
|
||||
ASSERT_TRUE(strstr(buf, "800") != NULL);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user