RF24Log  0.1.3
Unified logging library
FormatSpecifier.cpp
Go to the documentation of this file.
1 
15 #include "FormatSpecifier.h"
16 
17 /****************************************************************************/
18 
20 {
21  if (c == '0')
22  {
23  fill = '0';
24  }
25  return (bool)(c == '-' || c == '+' || c == ' ' || c == '0');
26 }
27 
28 /****************************************************************************/
29 
31 {
32  if (c == '.' || (c > 47 && c < 58))
33  {
34  if (c == '.')
35  {
36  precis = 0; // 0.0 value will not be output
37  }
38  else
39  {
40  if (precis >=0)
41  {
42  precis = (precis * 10) + (c - 48);
43  }
44  else
45  {
46  width = (width * 10) + (c - 48);
47  }
48  }
49  return true;
50  }
51  return false;
52 
53 }
54 
55 /****************************************************************************/
56 
58 {
59 
60  if (c == 's' ||
61  #ifdef ARDUINO_ARCH_AVR
62  c == 'S' ||
63  #endif
64  c == 'c' ||
65  c == 'D' ||
66  c == 'f' ||
67  c == 'F' ||
68  c == 'x' ||
69  c == 'X' ||
70  c == 'o' ||
71  c == 'u' ||
72  c == 'd' ||
73  c == 'i' ||
74  c == 'b')
75  {
76  if (c == 'u' || c == 'x' || c == 'X' || c == 'o' || c == 'b')
77  {
78  length |= 0x80;
79  }
80  specifier = c;
81  return false; // no second option supported
82  }
83  else if (c == 'l' || c == 'h')
84  {
85  if (length & 0x30) // second encountered length modifier
86  {
87  length = (length & 0x80) | (c == 'l' ? (length & 0x30) << 1 : (length & 0x30) >> 1);
88 
89  }
90  else // first encountered length modifier
91  {
92  length = (length & 0x80) | (c == 'l' ? 32 : 16);
93  }
94  return true; // can also support a second option (like 'u')
95  }
96  return false;
97 }
generic struct that allows customization of a printf-like parser
uint8_t length
bit-length of the data (only applies to integer numbers)
bool isPaddPrec(char c)
is a character a valid specifier padding/precision quantity
uint16_t width
The width of the padding.
char specifier
datatype specifier
bool isFlagged(char c)
is a character a valid specifier flag
bool isFmtOption(char c)
is a character a valid/supported specifier format option
int8_t precis
The number of decimal places. If negative, then default of 2 places is used.
char fill
The default character used as padding.