------------------------------------------------------------------------* * Parse string to extract numbers * *------------------------------------------------------------------------*/ ! * \brief parseStringForNumbers() * * \param[in] str string containing numbers; not changed * \param[in] seps string of characters that can be used between ints
| 1037 | * </pre> |
| 1038 | */ |
| 1039 | NUMA * |
| 1040 | parseStringForNumbers(const char *str, |
| 1041 | const char *seps) |
| 1042 | { |
| 1043 | char *newstr, *head; |
| 1044 | char *tail = NULL; |
| 1045 | l_float32 val; |
| 1046 | NUMA *na; |
| 1047 | |
| 1048 | PROCNAME("parseStringForNumbers"); |
| 1049 | |
| 1050 | if (!str) |
| 1051 | return (NUMA *)ERROR_PTR("str not defined", procName, NULL); |
| 1052 | |
| 1053 | newstr = stringNew(str); /* to enforce const-ness of str */ |
| 1054 | na = numaCreate(0); |
| 1055 | head = strtokSafe(newstr, seps, &tail); |
| 1056 | val = atof(head); |
| 1057 | numaAddNumber(na, val); |
| 1058 | LEPT_FREE(head); |
| 1059 | while ((head = strtokSafe(NULL, seps, &tail)) != NULL) { |
| 1060 | val = atof(head); |
| 1061 | numaAddNumber(na, val); |
| 1062 | LEPT_FREE(head); |
| 1063 | } |
| 1064 | |
| 1065 | LEPT_FREE(newstr); |
| 1066 | return na; |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | /*------------------------------------------------------------------------* |
no test coverage detected