kiba-engine
options.c
1 #include <kiba/format/options.h>
2 
3 format_options format_default_format_options(void) {
4  return (format_options){
5  .width = 0,
6  .alignment = FORMAT_ALIGN_RIGHT,
7  .precision = 0,
8  };
9 }
10 
11 void format_calculate_padding(format_options options, usize data_length, usize *left_pad, usize *right_pad) {
12  *left_pad = 0;
13  *right_pad = 0;
14  if (options.width > data_length) {
15  usize diff = options.width - data_length;
16  switch (options.alignment) {
17  case FORMAT_ALIGN_RIGHT:
18  *left_pad = diff;
19  break;
20  case FORMAT_ALIGN_LEFT:
21  *right_pad = diff;
22  break;
23  case FORMAT_ALIGN_CENTER:
24  *right_pad = diff / 2;
25  *left_pad = diff - *right_pad;
26  break;
27  }
28  }
29 }