FastLED 3.9.15
Loading...
Searching...
No Matches

◆ apply_width_align()

void fl::format_detail::apply_width_align ( fl::string & result,
const fl::string & value,
const FormatSpec & spec )
inline

Definition at line 121 of file format.h.

121 {
122 fl::size value_len = value.size();
123
124 if (spec.width <= 0 || static_cast<fl::size>(spec.width) <= value_len) {
125 result.append(value);
126 return;
127 }
128
129 fl::size padding = static_cast<fl::size>(spec.width) - value_len;
130 char fill = spec.fill;
131
132 char align = spec.align;
133 if (align == '\0') {
134 align = '>'; // Default right-align for numbers
135 }
136
137 if (align == '<') {
138 // Left align: value then padding
139 result.append(value);
140 for (fl::size i = 0; i < padding; ++i) {
141 result.append(fill);
142 }
143 } else if (align == '>') {
144 // Right align: padding then value
145 for (fl::size i = 0; i < padding; ++i) {
146 result.append(fill);
147 }
148 result.append(value);
149 } else if (align == '^') {
150 // Center align
151 fl::size left_pad = padding / 2;
152 fl::size right_pad = padding - left_pad;
153 for (fl::size i = 0; i < left_pad; ++i) {
154 result.append(fill);
155 }
156 result.append(value);
157 for (fl::size i = 0; i < right_pad; ++i) {
158 result.append(fill);
159 }
160 }
161}
constexpr int type_rank< T >::value
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
void fill(Iterator first, Iterator last, const T &value) FL_NOEXCEPT
Definition algorithm.h:204

References fl::format_detail::FormatSpec::align, fl::fill(), fl::format_detail::FormatSpec::fill, fl::type_rank< T >::value, and fl::format_detail::FormatSpec::width.

Referenced by format_impl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: