Remove broken snprintf
This commit is contained in:
parent
1987db663b
commit
018d8b57f6
@ -584,14 +584,6 @@ typedef basic_printf_context_t<internal::wbuffer>::type wprintf_context;
|
||||
typedef basic_format_args<printf_context> printf_args;
|
||||
typedef basic_format_args<wprintf_context> wprintf_args;
|
||||
|
||||
template <typename OutputIt, typename Char = typename OutputIt::value_type>
|
||||
struct basic_printf_n_context_t {
|
||||
typedef fmt::internal::truncating_iterator<OutputIt> OutputIter;
|
||||
typedef output_range<OutputIter, Char> Range;
|
||||
typedef basic_printf_context<OutputIter, Char, printf_arg_formatter<Range>>
|
||||
type;
|
||||
};
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs an `~fmt::format_arg_store` object that contains references to
|
||||
@ -627,17 +619,6 @@ inline std::basic_string<Char> vsprintf(
|
||||
return to_string(buffer);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename S, typename Char = FMT_CHAR(S),
|
||||
FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)>
|
||||
inline format_to_n_result<OutputIt> vsnprintf(
|
||||
OutputIt out, std::size_t n, const S& format,
|
||||
basic_format_args<typename basic_printf_n_context_t<OutputIt, Char>::type>
|
||||
args) {
|
||||
typedef internal::truncating_iterator<OutputIt> It;
|
||||
auto it = printf(It(out, n), to_string_view(format), args);
|
||||
return {it.base(), it.count()};
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Formats arguments and returns the result as a string.
|
||||
@ -658,34 +639,6 @@ inline std::basic_string<FMT_CHAR(S)> sprintf(const S& format,
|
||||
return vsprintf(to_string_view(format), basic_format_args<context>(as));
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Formats arguments for up to ``n`` characters stored through output iterator
|
||||
``out``. The function returns the updated iterator and the untruncated amount
|
||||
of characters.
|
||||
|
||||
**Example**::
|
||||
std::vector<char> out;
|
||||
|
||||
typedef fmt::format_to_n_result<
|
||||
std::back_insert_iterator<std::vector<char>>> res;
|
||||
res Res = fmt::snprintf(std::back_inserter(out), 5, "The answer is %d", 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
FMT_ENABLE_IF(internal::is_string<S>::value&&
|
||||
internal::is_output_iterator<OutputIt>::value)>
|
||||
inline format_to_n_result<OutputIt> snprintf(OutputIt out, std::size_t n,
|
||||
const S& format,
|
||||
const Args&... args) {
|
||||
internal::check_format_string<Args...>(format);
|
||||
typedef FMT_CHAR(S) Char;
|
||||
typedef typename basic_printf_n_context_t<OutputIt, Char>::type context;
|
||||
format_arg_store<context, Args...> as{args...};
|
||||
return vsnprintf(out, n, to_string_view(format),
|
||||
basic_format_args<context>(as));
|
||||
}
|
||||
|
||||
template <typename S, typename Char = FMT_CHAR(S)>
|
||||
inline int vfprintf(
|
||||
std::FILE* f, const S& format,
|
||||
|
@ -554,23 +554,3 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
|
||||
fmt::make_wprintf_args(42, L"something")));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(PrintfTest, snprintf) {
|
||||
char buffer[4] = "xxx";
|
||||
auto result = fmt::snprintf(buffer, 0, "test");
|
||||
EXPECT_EQ("xxx", fmt::to_string_view(buffer));
|
||||
EXPECT_EQ(4u, result.size);
|
||||
EXPECT_EQ(buffer, result.out);
|
||||
result = fmt::snprintf(buffer, 2, "test");
|
||||
EXPECT_EQ("tex", fmt::to_string_view(buffer));
|
||||
EXPECT_EQ(4u, result.size);
|
||||
EXPECT_EQ(buffer + 2, result.out);
|
||||
result = fmt::snprintf(buffer, 3, "test");
|
||||
EXPECT_EQ("tes", fmt::to_string_view(buffer));
|
||||
EXPECT_EQ(4u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
result = fmt::snprintf(buffer, 4, "test");
|
||||
EXPECT_EQ("test", std::string(buffer, 4));
|
||||
EXPECT_EQ(4u, result.size);
|
||||
EXPECT_EQ(buffer + 4, result.out);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user