MCPcopy Create free account
hub / github.com/ElementsProject/elements / formatValue

Function formatValue

src/tinyformat.h:329–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327/// conversions.
328template<typename T>
329inline void formatValue(std::ostream& out, const char* /*fmtBegin*/,
330 const char* fmtEnd, int ntrunc, const T& value)
331{
332#ifndef TINYFORMAT_ALLOW_WCHAR_STRINGS
333 // Since we don't support printing of wchar_t using "%ls", make it fail at
334 // compile time in preference to printing as a void* at runtime.
335 typedef typename detail::is_wchar<T>::tinyformat_wchar_is_not_supported DummyType;
336 (void) DummyType(); // avoid unused type warning with gcc-4.8
337#endif
338 // The mess here is to support the %c and %p conversions: if these
339 // conversions are active we try to convert the type to a char or const
340 // void* respectively and format that instead of the value itself. For the
341 // %p conversion it's important to avoid dereferencing the pointer, which
342 // could otherwise lead to a crash when printing a dangling (const char*).
343 const bool canConvertToChar = detail::is_convertible<T,char>::value;
344 const bool canConvertToVoidPtr = detail::is_convertible<T, const void*>::value;
345 if (canConvertToChar && *(fmtEnd-1) == 'c')
346 detail::formatValueAsType<T, char>::invoke(out, value);
347 else if (canConvertToVoidPtr && *(fmtEnd-1) == 'p')
348 detail::formatValueAsType<T, const void*>::invoke(out, value);
349#ifdef TINYFORMAT_OLD_LIBSTDCPLUSPLUS_WORKAROUND
350 else if (detail::formatZeroIntegerWorkaround<T>::invoke(out, value)) /**/;
351#endif
352 else if (ntrunc >= 0) {
353 // Take care not to overread C strings in truncating conversions like
354 // "%.4s" where at most 4 characters may be read.
355 detail::formatTruncated(out, value, ntrunc);
356 }
357 else
358 out << value;
359}
360
361
362// Overloaded version for char types to support printing as an integer

Callers

nothing calls this directly

Calls 1

formatTruncatedFunction · 0.85

Tested by

no test coverage detected