* @brief Converts the content of a String object to a floating-point number. * * This function converts the content of the given String object to a floating-point number (float). * If the String object is NULL or empty, the function logs an error and returns 0.0f. * * @param str The String object to convert. Must not be NULL. * @return The floating-point value of the String object's content,
| 2462 | * @return The floating-point value of the String object's content, or 0.0f if the String object is NULL or empty. |
| 2463 | */ |
| 2464 | float string_to_float(const String *str) { |
| 2465 | STRING_LOG("[string_to_float]: Function start."); |
| 2466 | |
| 2467 | if (str == NULL) { |
| 2468 | STRING_LOG("[string_to_float]: Error - Null String object."); |
| 2469 | return 0.0f; |
| 2470 | } |
| 2471 | if (string_empty(str)) { |
| 2472 | STRING_LOG("[string_to_float]: Error - Empty string."); |
| 2473 | return 0.0f; |
| 2474 | } |
| 2475 | |
| 2476 | float result = atof(str->dataStr); |
| 2477 | STRING_LOG("[string_to_float]: Converted '%s' to float %f.", str->dataStr, result); |
| 2478 | STRING_LOG("[string_to_float]: Function end."); |
| 2479 | |
| 2480 | return result; |
| 2481 | } |
| 2482 | |
| 2483 | |
| 2484 | /** |
nothing calls this directly
no test coverage detected