Skip to content

Commit 94adb27

Browse files
committed
Cleanup string to allow string after formatted output
1 parent c21e6d0 commit 94adb27

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

include/boost/int128/fmt_format.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ struct formatter
269269
// LCOV_EXCL_STOP
270270
}
271271

272+
s.erase(0, s.find_first_not_of('\0'));
273+
s.erase(s.find_last_not_of('\0') + 1);
274+
272275
return fmt::format_to(ctx.out(), "{}", s);
273276
}
274277
};

include/boost/int128/format.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ struct formatter<T>
273273
// LCOV_EXCL_STOP
274274
}
275275

276+
s.erase(0, s.find_first_not_of('\0'));
277+
s.erase(s.find_last_not_of('\0') + 1);
278+
276279
return std::format_to(ctx.out(), "{}", s);
277280
}
278281
};

test/test_fmt_format.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void test_string_insertion()
128128
{
129129
BOOST_TEST_CSTR_EQ(fmt::format("Height is: {:d}", T {0}).c_str(), "Height is: 0");
130130
BOOST_TEST_CSTR_EQ(fmt::format("Height is: {}", T {2}).c_str(), "Height is: 2");
131+
132+
BOOST_TEST_CSTR_EQ(fmt::format("Height is: {:d} meters", T {0}).c_str(), "Height is: 0 meters");
133+
BOOST_TEST_CSTR_EQ(fmt::format("Height is: {} meters", T {2}).c_str(), "Height is: 2 meters");
131134
}
132135

133136
int main()

test/test_format.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ void test_string_insertion()
119119
{
120120
BOOST_TEST_CSTR_EQ(std::format("Height is: {:d}", T {0}).c_str(), "Height is: 0");
121121
BOOST_TEST_CSTR_EQ(std::format("Height is: {}", T {2}).c_str(), "Height is: 2");
122+
123+
BOOST_TEST_CSTR_EQ(std::format("Height is: {:d} meters", T {0}).c_str(), "Height is: 0 meters");
124+
BOOST_TEST_CSTR_EQ(std::format("Height is: {} meters", T {2}).c_str(), "Height is: 2 meters");
122125
}
123126

124127
int main()

0 commit comments

Comments
 (0)