57 size_t pad = FieldPadding(spec.width, text.size());
64 else if (spec.CenterAlign())
67 right_pad = pad - left_pad;
74 if (
auto ec = WritePadding(spec.fill, left_pad); ec != ErrorCode::OK)
78 if (
auto ec = WriteRaw(text); ec != ErrorCode::OK)
82 return WritePadding(spec.fill, right_pad);
99 std::string_view prefix,
100 std::string_view digits,
103 auto write_char = [
this](
char ch) -> ErrorCode
107 return ErrorCode::OK;
109 return WriteRaw(std::string_view(&ch, 1));
111 auto write_text = [
this](std::string_view text) -> ErrorCode
115 return ErrorCode::OK;
117 return WriteRaw(text);
120 size_t zeros = IntegerPrecisionZeros(spec, digits.size());
122 digits.size() + zeros + prefix.size() +
static_cast<size_t>(sign_char !=
'\0');
123 size_t pad = FieldPadding(spec.width, total);
125 spec.ZeroPad() && !spec.LeftAlign() && !spec.CenterAlign() && !spec.HasPrecision();
127 size_t middle_zeros = zero_fill ? pad : 0;
128 size_t right_pad = 0;
131 if (spec.LeftAlign())
135 else if (spec.CenterAlign())
138 right_pad = pad - left_pad;
146 if (
auto ec = WritePadding(spec.fill, left_pad); ec != ErrorCode::OK)
150 if (
auto ec = write_char(sign_char); ec != ErrorCode::OK)
154 if (
auto ec = write_text(prefix); ec != ErrorCode::OK)
158 if (
auto ec = WritePadding(
'0', middle_zeros); ec != ErrorCode::OK)
162 if (
auto ec = WritePadding(
'0', zeros); ec != ErrorCode::OK)
166 if (
auto ec = write_text(digits); ec != ErrorCode::OK)
170 return WritePadding(spec.fill, right_pad);
187 auto write_char = [
this](
char ch) -> ErrorCode
191 return ErrorCode::OK;
193 return WriteRaw(std::string_view(&ch, 1));
196 size_t total = text.size() +
static_cast<size_t>(sign_char !=
'\0');
197 size_t pad = FieldPadding(spec.width, total);
198 bool zero_fill = spec.ZeroPad() && !spec.LeftAlign() && !spec.CenterAlign();
200 size_t middle_zeros = zero_fill ? pad : 0;
201 size_t right_pad = 0;
204 if (spec.LeftAlign())
208 else if (spec.CenterAlign())
211 right_pad = pad - left_pad;
219 if (
auto ec = WritePadding(spec.fill, left_pad); ec != ErrorCode::OK)
223 if (
auto ec = write_char(sign_char); ec != ErrorCode::OK)
227 if (
auto ec = WritePadding(
'0', middle_zeros); ec != ErrorCode::OK)
231 if (
auto ec = WriteRaw(text); ec != ErrorCode::OK)
235 return WritePadding(spec.fill, right_pad);
ErrorCode WriteIntegerField(char sign_char, std::string_view prefix, std::string_view digits, const Spec &spec)
按符号、前缀、精度与填充策略写出一个整数载荷 / Write one integer payload with sign, prefix, precision, and padding policy a...