MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / formatImpl

Function formatImpl

src/tinyformat.h:788–844  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

786
787//------------------------------------------------------------------------------
788inline void formatImpl(std::ostream& out, const char* fmt,
789 const detail::FormatArg* formatters,
790 int numFormatters)
791{
792 // Saved stream state
793 std::streamsize origWidth = out.width();
794 std::streamsize origPrecision = out.precision();
795 std::ios::fmtflags origFlags = out.flags();
796 char origFill = out.fill();
797
798 for (int argIndex = 0; argIndex < numFormatters; ++argIndex)
799 {
800 // Parse the format string
801 fmt = printFormatStringLiteral(out, fmt);
802 bool spacePadPositive = false;
803 int ntrunc = -1;
804 const char* fmtEnd = streamStateFromFormat(out, spacePadPositive, ntrunc, fmt,
805 formatters, argIndex, numFormatters);
806 if (argIndex >= numFormatters)
807 {
808 // Check args remain after reading any variable width/precision
809 TINYFORMAT_ERROR("tinyformat: Not enough format arguments");
810 return;
811 }
812 const FormatArg& arg = formatters[argIndex];
813 // Format the arg into the stream.
814 if(!spacePadPositive)
815 arg.format(out, fmt, fmtEnd, ntrunc);
816 else
817 {
818 // The following is a special case with no direct correspondence
819 // between stream formatting and the printf() behaviour. Simulate
820 // it crudely by formatting into a temporary string stream and
821 // munging the resulting string.
822 std::ostringstream tmpStream;
823 tmpStream.copyfmt(out);
824 tmpStream.setf(std::ios::showpos);
825 arg.format(tmpStream, fmt, fmtEnd, ntrunc);
826 std::string result = tmpStream.str(); // allocates... yuck.
827 for(size_t i = 0, iend = result.size(); i < iend; ++i)
828 if(result[i] == '+') result[i] = ' ';
829 out << result;
830 }
831 fmt = fmtEnd;
832 }
833
834 // Print remaining part of format string.
835 fmt = printFormatStringLiteral(out, fmt);
836 if(*fmt != '\0')
837 TINYFORMAT_ERROR("tinyformat: Too many conversion specifiers in format string");
838
839 // Restore stream state
840 out.width(origWidth);
841 out.precision(origPrecision);
842 out.flags(origFlags);
843 out.fill(origFill);
844}
845

Callers 1

vformatFunction · 0.85

Calls 5

fillMethod · 0.80
formatMethod · 0.80
strMethod · 0.80
flagsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected