MCPcopy Create free account
hub / github.com/apache/trafficserver / Adjust_Alignment

Function Adjust_Alignment

lib/swoc/src/bw_format.cc:275–309  ·  view source on GitHub ↗

This performs generic alignment operations. If a formatter specialization performs this operation instead, that should result in output that is at least @a spec._min characters wide, which will cause this function to make no further adjustments. */

Source from the content-addressed store, hash-verified

273 cause this function to make no further adjustments.
274 */
275void
276Adjust_Alignment(BufferWriter &aux, Spec const &spec) {
277 size_t extent = aux.extent();
278 size_t min = spec._min;
279 if (extent < min) {
280 size_t delta = min - extent;
281 size_t left_delta = 0, right_delta = delta; // left justify values
282 if (Spec::Align::RIGHT == spec._align) {
283 left_delta = delta;
284 right_delta = 0;
285 } else if (Spec::Align::CENTER == spec._align) {
286 left_delta = delta / 2;
287 right_delta = (delta + 1) / 2;
288 }
289 if (left_delta > 0) {
290 size_t work_area = extent + left_delta;
291 aux.commit(left_delta); // cover work area.
292 aux.copy(left_delta, 0, extent); // move to create space for left fill.
293 aux.discard(work_area); // roll back to write the left fill.
294 for (int i = left_delta; i > 0; --i) {
295 aux.write(spec._fill);
296 }
297 aux.commit(extent);
298 }
299 for (int i = right_delta; i > 0; --i) {
300 aux.write(spec._fill);
301 }
302
303 } else {
304 size_t max = spec._max;
305 if (max < extent) {
306 aux.discard(extent - max);
307 }
308 }
309}
310
311// Conversions from remainder to character, in upper and lower case versions.
312// Really only useful for hexadecimal currently.

Callers 1

bwf_base.hFile · 0.85

Calls 5

extentMethod · 0.45
commitMethod · 0.45
copyMethod · 0.45
discardMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected