15 #include "absl/strings/internal/str_format/bind.h"
48 bool Bind(
const UnboundConversion* unbound, BoundConversion* bound);
54 inline bool ArgContext::Bind(
const UnboundConversion* unbound,
55 BoundConversion* bound) {
56 const FormatArgImpl*
arg =
nullptr;
57 int arg_position = unbound->arg_position;
58 if (
static_cast<size_t>(arg_position - 1) >=
pack_.size())
return false;
62 int width = unbound->width.value();
63 bool force_left =
false;
64 if (unbound->width.is_from_arg()) {
65 if (!BindFromPosition(unbound->width.get_from_arg(), &
width,
pack_))
76 int precision = unbound->precision.value();
77 if (unbound->precision.is_from_arg()) {
78 if (!BindFromPosition(unbound->precision.get_from_arg(), &
precision,
102 template <
typename Converter>
103 class ConverterConsumer {
112 bool ConvertOne(
const UnboundConversion&
conv,
string_view conv_string) {
113 BoundConversion bound;
115 return converter_.ConvertOne(bound, conv_string);
123 template <
typename Converter>
124 bool ConvertAll(
const UntypedFormatSpecImpl
format,
126 if (
format.has_parsed_conversion()) {
127 return format.parsed_conversion()->ProcessFormat(
135 class DefaultConverter {
137 explicit DefaultConverter(FormatSinkImpl*
sink) :
sink_(
sink) {}
141 bool ConvertOne(
const BoundConversion& bound,
string_view )
const {
149 class SummarizingConverter {
151 explicit SummarizingConverter(FormatSinkImpl*
sink) :
sink_(
sink) {}
155 bool ConvertOne(
const BoundConversion& bound,
string_view )
const {
156 UntypedFormatSpecImpl
spec(
"%d");
158 std::ostringstream ss;
159 ss <<
"{" << Streamable(
spec, {*bound.arg()}) <<
":"
161 if (bound.width() >= 0) ss << bound.width();
162 if (bound.precision() >= 0) ss <<
"." << bound.precision();
163 ss << bound.conversion_char() <<
"}";
169 FormatSinkImpl*
sink_;
177 return ArgContext(pack).Bind(props, bound);
182 typedef SummarizingConverter Converter;
199 using Converter = DefaultConverter;
210 size_t orig =
out->size();
234 errno =
sink.error();
241 return static_cast<int>(
sink.count());
253 return static_cast<int>(
total);