* @brief Converts the content of a String object to a double-precision floating-point number. * * This function converts the content of the given String object to a double-precision floating-point number (double). * If the String object is NULL or empty, the function logs an error and returns 0.0. * * @param str The String object to convert. Must not be NULL. * @return The double value of th
| 2491 | * @return The double value of the String object's content, or 0.0 if the String object is NULL or empty. |
| 2492 | */ |
| 2493 | double string_to_double(const String* str) { |
| 2494 | STRING_LOG("[string_to_double]: Function start."); |
| 2495 | |
| 2496 | if (str == NULL) { |
| 2497 | STRING_LOG("[string_to_double]: Error - Null String object."); |
| 2498 | return 0.0; |
| 2499 | } |
| 2500 | if (string_empty(str)) { |
| 2501 | STRING_LOG("[string_to_double]: Error - Empty string."); |
| 2502 | return 0.0; |
| 2503 | } |
| 2504 | |
| 2505 | double result = strtod(str->dataStr, NULL); |
| 2506 | STRING_LOG("[string_to_double]: Converted '%s' to double %lf.", str->dataStr, result); |
| 2507 | STRING_LOG("[string_to_double]: Function end."); |
| 2508 | |
| 2509 | return result; |
| 2510 | } |
| 2511 | |
| 2512 | |
| 2513 | /** |
nothing calls this directly
no test coverage detected