MCPcopy Create free account
hub / github.com/FastLED/FastLED / apply_width_align

Function apply_width_align

src/fl/stl/format.h:121–161  ·  view source on GitHub ↗

Apply width/alignment to a formatted string

Source from the content-addressed store, hash-verified

119
120// Apply width/alignment to a formatted string
121inline void apply_width_align(fl::string& result, const fl::string& value, const FormatSpec& spec) {
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}
162
163// Format an integer value
164template <typename T>

Callers 1

format_implFunction · 0.85

Calls 2

sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected