mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Fix fmt function to handle empty strings and update make_prefix template parameters
This commit is contained in:
parent
e7a8005f58
commit
a2da0621e8
@ -199,6 +199,7 @@ void fmt_context::expend(std::size_t sz) noexcept {
|
||||
|
||||
bool fmt_context::append(span<char const> const &str) noexcept {
|
||||
auto sz = str.size();
|
||||
if (sz == 0) return true;
|
||||
if (str.back() == '\0') --sz;
|
||||
auto sbuf = buffer(sz);
|
||||
if (sbuf.size() < sz) {
|
||||
|
||||
@ -46,9 +46,9 @@ inline std::string make_string(char const *str) {
|
||||
}
|
||||
|
||||
/// \brief Combine prefix from a list of strings.
|
||||
template <typename... A>
|
||||
inline std::string make_prefix(std::string prefix, A &&...args) {
|
||||
return ipc::fmt(prefix, "__IPC_SHM__", std::forward<A>(args)...);
|
||||
template <typename A1, typename... A>
|
||||
inline std::string make_prefix(A1 &&prefix, A &&...args) {
|
||||
return ipc::fmt(std::forward<A1>(prefix), "__IPC_SHM__", std::forward<A>(args)...);
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
|
||||
@ -110,6 +110,13 @@ TEST(fmt, fmt) {
|
||||
std::string test(4096, ' ');
|
||||
std::memcpy(&test[test.size() - sizeof(txt) + 1], txt, sizeof(txt) - 1);
|
||||
EXPECT_EQ(s, test);
|
||||
|
||||
EXPECT_EQ(ipc::fmt("", 1, "", '2', "", 3.0), "123.000000");
|
||||
std::string empty;
|
||||
EXPECT_EQ(ipc::fmt(empty, 1, "", '2', "", 3.0), "123.000000");
|
||||
EXPECT_EQ(ipc::fmt(empty, 1, empty, '2', "", 3.0), "123.000000");
|
||||
EXPECT_EQ(ipc::fmt("", 1, empty, '2', empty, 3.0), "123.000000");
|
||||
EXPECT_EQ(ipc::fmt("", 1, "", '2', empty), "12");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user