FastLED 3.9.15
Loading...
Searching...
No Matches

◆ atoff()

static float fl::string_functions::atoff ( const char * str,
size_t len )
static

Definition at line 100 of file str.cpp.

100 {
101 float result = 0.0f; // The resulting number
102 float sign = 1.0f; // Positive or negative
103 float fraction = 0.0f; // Fractional part
104 float divisor = 1.0f; // Divisor for the fractional part
105 int isFractional = 0; // Whether the current part is fractional
106
107 size_t pos = 0; // Current position in the string
108
109 // Handle empty input
110 if (len == 0) {
111 return 0.0f;
112 }
113
114 // Skip leading whitespace (manual check instead of isspace)
115 while (pos < len &&
116 (str[pos] == ' ' || str[pos] == '\t' || str[pos] == '\n' ||
117 str[pos] == '\r' || str[pos] == '\f' || str[pos] == '\v')) {
118 pos++;
119 }
120
121 // Handle optional sign
122 if (pos < len && str[pos] == '-') {
123 sign = -1.0f;
124 pos++;
125 } else if (pos < len && str[pos] == '+') {
126 pos++;
127 }
128
129 // Main parsing loop
130 while (pos < len) {
131 if (str[pos] >= '0' && str[pos] <= '9') {
132 if (isFractional) {
133 divisor *= 10.0f;
134 fraction += (str[pos] - '0') / divisor;
135 } else {
136 result = result * 10.0f + (str[pos] - '0');
137 }
138 } else if (str[pos] == '.' && !isFractional) {
139 isFractional = 1;
140 } else {
141 // Stop parsing at invalid characters
142 break;
143 }
144 pos++;
145 }
146
147 // Combine integer and fractional parts
148 result = result + fraction;
149
150 // Apply the sign
151 return sign * result;
152}
uint8_t pos
Definition Blur.ino:11

References pos.

Referenced by fl::StringFormatter::parseFloat().

+ Here is the caller graph for this function: