8#ifndef INCLUDED_BDLT_FORMATTER
9#define INCLUDED_BDLT_FORMATTER
60#include <bdlscm_version.h>
83template <
template<
typename>
class tt_SPECIFIER_FORMATTER,
class t_CHAR>
92 typedef bsl::ptrdiff_t ptrdiff_t;
103 mutable tt_SPECIFIER_FORMATTER<t_CHAR> d_specifierFormatter;
111 bsl::size_t d_numModifiers;
132 template <
class t_PARSE_CONTEXT>
134 t_PARSE_CONTEXT& context);
140 template <
class t_FORMAT_CONTEXT,
class t_VALUE>
141 typename t_FORMAT_CONTEXT::iterator
format(
142 const t_VALUE& value,
143 t_FORMAT_CONTEXT& formatContext)
const;
151template <
template<
typename>
class tt_SPECIFIER_FORMATTER,
class t_CHAR>
156 while (!spec->empty() && t_CHAR(
'%') != spec->front()) {
157 if (!d_specifierFormatter.parseNextModifier(spec)) {
158 BSLS_THROW(bsl::format_error(
"Illegal modifier"));
166template <
template<
typename>
class tt_SPECIFIER_FORMATTER,
class t_CHAR>
170, d_literalFormatter()
171, d_specifierFormatter()
177template <
template<
typename>
class tt_SPECIFIER_FORMATTER,
class t_CHAR>
178template <
class t_PARSE_CONTEXT>
180typename t_PARSE_CONTEXT::iterator
184 const Sections sections =
static_cast<Sections
>(
185 Spec::e_SECTIONS_WIDTH | Spec::e_SECTIONS_FILL_ALIGN |
186 Spec::e_SECTIONS_REMAINING_SPEC |
187 d_specifierFormatter.extraSections());
189 d_spec.parse(&context, sections);
192 parseModifiers(&spec);
195 d_specifierFormatter.parseDefault();
198 if (spec.
front() != t_CHAR(
'%')) {
200 "Format string must start with a '%'"));
203 while (!spec.
empty()) {
204 const t_CHAR c = spec.
front();
207 if (t_CHAR(
'%') == c) {
209 BSLS_THROW(bsl::format_error(
"Incomplete '%' sequence"));
212 if (!d_specifierFormatter.parseNextSpecifier(&spec) &&
213 !d_literalFormatter. parseNextSpecifier(&spec)) {
215 "Unrecognized format specifier"));
224 return context.begin();
229template <
template<
typename>
class tt_SPECIFIER_FORMATTER,
class t_CHAR>
230template <
class t_FORMAT_CONTEXT,
class t_VALUE>
231typename t_FORMAT_CONTEXT::iterator
233 const t_VALUE& value,
234 t_FORMAT_CONTEXT& formatContext)
const
237 typename t_FORMAT_CONTEXT::char_type>::value));
239 d_spec.postprocess(formatContext);
242 d_specifierFormatter.postprocess(d_spec);
244 const ptrdiff_t contentWidth = d_literalWidth +
245 d_literalFormatter.totalWidth() +
246 d_specifierFormatter.totalWidth(value);
248 ptrdiff_t leftPadding, rightPadding;
249 PadUtil::computePadding(&leftPadding,
251 d_spec.postprocessedWidth(),
254 StringView filler(d_spec.filler(), d_spec.numFillerCharacters());
256 typename t_FORMAT_CONTEXT::iterator outIt = formatContext.out();
258 outIt = PadUtil::pad(outIt, leftPadding, filler);
261 outIt = d_specifierFormatter.formatDefault(outIt, value);
266 while (!spec.
empty()) {
267 const t_CHAR c = spec.
front();
270 if (c == t_CHAR(
'%')) {
273 if (!d_specifierFormatter.formatNextSpecifier(
274 &spec, &outIt, value) &&
275 !d_literalFormatter.formatNextSpecifier(&spec, &outIt)) {
277 "unrecognized format specifier");
286 outIt = PadUtil::pad(outIt, rightPadding, filler);
Definition bslstl_stringview.h:471
BSLS_KEYWORD_CONSTEXPR_CPP14 basic_string_view substr(size_type position=0, size_type numChars=npos) const
Definition bslstl_stringview.h:2027
BSLS_KEYWORD_CONSTEXPR_CPP14 const_reference front() const
Definition bslstl_stringview.h:1966
BSLS_KEYWORD_CONSTEXPR_CPP14 void remove_prefix(size_type numChars)
Definition bslstl_stringview.h:1800
BSLS_KEYWORD_CONSTEXPR bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this view has length 0, and false otherwise.
Definition bslstl_stringview.h:1931
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_INVOKE_NORETURN(X)
Definition bsls_assert.h:2101
#define BSLS_THROW(X)
Definition bsls_exceptionutil.h:374
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR_CPP20
Definition bsls_keyword.h:645
Definition bbldc_basicisma30360.h:112
Definition bslmf_issame.h:146
Definition bslfmt_padutil.h:151