RF24Log
0.1.3
Unified logging library
src
RF24LogParts
FormatSpecifier.cpp
Go to the documentation of this file.
1
15
#include "
FormatSpecifier.h
"
16
17
/****************************************************************************/
18
19
bool
FormatSpecifier::isFlagged
(
char
c)
20
{
21
if
(c ==
'0'
)
22
{
23
fill
=
'0'
;
24
}
25
return
(
bool
)(c ==
'-'
|| c ==
'+'
|| c ==
' '
|| c ==
'0'
);
26
}
27
28
/****************************************************************************/
29
30
bool
FormatSpecifier::isPaddPrec
(
char
c)
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
57
bool
FormatSpecifier::isFmtOption
(
char
c)
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
}
FormatSpecifier.h
generic struct that allows customization of a printf-like parser
FormatSpecifier::length
uint8_t length
bit-length of the data (only applies to integer numbers)
Definition:
FormatSpecifier.h:63
FormatSpecifier::isPaddPrec
bool isPaddPrec(char c)
is a character a valid specifier padding/precision quantity
Definition:
FormatSpecifier.cpp:30
FormatSpecifier::width
uint16_t width
The width of the padding.
Definition:
FormatSpecifier.h:54
FormatSpecifier::specifier
char specifier
datatype specifier
Definition:
FormatSpecifier.h:65
FormatSpecifier::isFlagged
bool isFlagged(char c)
is a character a valid specifier flag
Definition:
FormatSpecifier.cpp:19
FormatSpecifier::isFmtOption
bool isFmtOption(char c)
is a character a valid/supported specifier format option
Definition:
FormatSpecifier.cpp:57
FormatSpecifier::precis
int8_t precis
The number of decimal places. If negative, then default of 2 places is used.
Definition:
FormatSpecifier.h:56
FormatSpecifier::fill
char fill
The default character used as padding.
Definition:
FormatSpecifier.h:52
Generated by
1.9.1