1117 |
1117 |
1118 /* ------------------------------------------------------------------------- * |
1118 /* ------------------------------------------------------------------------- * |
1119 * string to number conversion functions * |
1119 * string to number conversion functions * |
1120 * ------------------------------------------------------------------------- */ |
1120 * ------------------------------------------------------------------------- */ |
1121 |
1121 |
1122 |
1122 /** |
1123 /** |
1123 * \copydoc cx_strtouz_lc() |
1124 * \copydoc cx_strtouz_lc() |
1124 */ |
1125 */ |
1125 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1126 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); |
1126 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); |
1127 /** |
1127 /** |
1128 * \copydoc cx_strtouz_lc() |
1128 * \copydoc cx_strtouz_lc() |
1129 */ |
1129 */ |
|
1130 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1130 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); |
1131 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); |
1131 /** |
1132 /** |
1132 * \copydoc cx_strtouz_lc() |
1133 * \copydoc cx_strtouz_lc() |
1133 */ |
1134 */ |
|
1135 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1134 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); |
1136 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); |
1135 /** |
1137 /** |
1136 * \copydoc cx_strtouz_lc() |
1138 * \copydoc cx_strtouz_lc() |
1137 */ |
1139 */ |
|
1140 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1138 int cx_strtoll_lc(cxstring str, long int *output, int base, const char *groupsep); |
1141 int cx_strtoll_lc(cxstring str, long int *output, int base, const char *groupsep); |
1139 /** |
1142 /** |
1140 * \copydoc cx_strtouz_lc() |
1143 * \copydoc cx_strtouz_lc() |
1141 */ |
1144 */ |
|
1145 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1142 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); |
1146 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); |
1143 /** |
1147 /** |
1144 * \copydoc cx_strtouz_lc() |
1148 * \copydoc cx_strtouz_lc() |
1145 */ |
1149 */ |
|
1150 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1146 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); |
1151 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); |
1147 /** |
1152 /** |
1148 * \copydoc cx_strtouz_lc() |
1153 * \copydoc cx_strtouz_lc() |
1149 */ |
1154 */ |
|
1155 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1150 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); |
1156 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); |
1151 /** |
1157 /** |
1152 * \copydoc cx_strtouz_lc() |
1158 * \copydoc cx_strtouz_lc() |
1153 */ |
1159 */ |
|
1160 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1154 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); |
1161 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); |
1155 /** |
1162 /** |
1156 * \copydoc cx_strtouz_lc() |
1163 * \copydoc cx_strtouz_lc() |
1157 */ |
1164 */ |
|
1165 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1158 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); |
1166 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); |
1159 /** |
1167 /** |
1160 * \copydoc cx_strtouz_lc() |
1168 * \copydoc cx_strtouz_lc() |
1161 */ |
1169 */ |
|
1170 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1162 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); |
1171 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); |
1163 /** |
1172 /** |
1164 * \copydoc cx_strtouz_lc() |
1173 * \copydoc cx_strtouz_lc() |
1165 */ |
1174 */ |
|
1175 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1166 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); |
1176 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); |
1167 /** |
1177 /** |
1168 * \copydoc cx_strtouz_lc() |
1178 * \copydoc cx_strtouz_lc() |
1169 */ |
1179 */ |
|
1180 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1170 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); |
1181 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); |
1171 /** |
1182 /** |
1172 * \copydoc cx_strtouz_lc() |
1183 * \copydoc cx_strtouz_lc() |
1173 */ |
1184 */ |
|
1185 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1174 int cx_strtoull_lc(cxstring str, unsigned long int *output, int base, const char *groupsep); |
1186 int cx_strtoull_lc(cxstring str, unsigned long int *output, int base, const char *groupsep); |
1175 /** |
1187 /** |
1176 * \copydoc cx_strtouz_lc() |
1188 * \copydoc cx_strtouz_lc() |
1177 */ |
1189 */ |
|
1190 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1178 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); |
1191 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); |
1179 /** |
1192 /** |
1180 * \copydoc cx_strtouz_lc() |
1193 * \copydoc cx_strtouz_lc() |
1181 */ |
1194 */ |
|
1195 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1182 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); |
1196 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); |
1183 /** |
1197 /** |
1184 * \copydoc cx_strtouz_lc() |
1198 * \copydoc cx_strtouz_lc() |
1185 */ |
1199 */ |
|
1200 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1186 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); |
1201 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); |
1187 /** |
1202 /** |
1188 * \copydoc cx_strtouz_lc() |
1203 * \copydoc cx_strtouz_lc() |
1189 */ |
1204 */ |
|
1205 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1190 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); |
1206 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); |
1191 |
1207 |
1192 /** |
1208 /** |
1193 * Converts a string to a number. |
1209 * Converts a string to a number. |
1194 * |
1210 * |
1200 * @param output a pointer to the integer variable where the result shall be stored |
1216 * @param output a pointer to the integer variable where the result shall be stored |
1201 * @param base 2, 8, 10, or 16 |
1217 * @param base 2, 8, 10, or 16 |
1202 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1218 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
1203 * @return zero on success, non-zero if conversion was not possible |
1219 * @return zero on success, non-zero if conversion was not possible |
1204 */ |
1220 */ |
|
1221 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
1205 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep); |
1222 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep); |
1206 |
1223 |
|
1224 /** |
|
1225 * Converts a string to a single precision floating point number. |
|
1226 * |
|
1227 * The function returns non-zero when conversion is not possible. |
|
1228 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
|
1229 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
1230 * |
|
1231 * The decimal separator is assumed to be a dot character. |
|
1232 * The comma character is treated as group separator and ignored during parsing. |
|
1233 * If you want to choose a different format, use cx_strtof_lc(). |
|
1234 * |
|
1235 * @param str the string to convert |
|
1236 * @param output a pointer to the float variable where the result shall be stored |
|
1237 * @param decsep the decimal separator |
|
1238 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
|
1239 * @return zero on success, non-zero if conversion was not possible |
|
1240 */ |
|
1241 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
|
1242 int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep); |
|
1243 |
|
1244 /** |
|
1245 * Converts a string to a double precision floating point number. |
|
1246 * |
|
1247 * The function returns non-zero when conversion is not possible. |
|
1248 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
|
1249 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
1250 * |
|
1251 * The decimal separator is assumed to be a dot character. |
|
1252 * The comma character is treated as group separator and ignored during parsing. |
|
1253 * If you want to choose a different format, use cx_strtof_lc(). |
|
1254 * |
|
1255 * @param str the string to convert |
|
1256 * @param output a pointer to the float variable where the result shall be stored |
|
1257 * @param decsep the decimal separator |
|
1258 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
|
1259 * @return zero on success, non-zero if conversion was not possible |
|
1260 */ |
|
1261 cx_attr_access_w(2) cx_attr_nonnull_arg(2) |
|
1262 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep); |
|
1263 |
|
1264 #ifndef CX_STR_IMPLEMENTATION |
1207 /** |
1265 /** |
1208 * \copydoc cx_strtouz_lc() |
1266 * \copydoc cx_strtouz_lc() |
1209 */ |
1267 */ |
1210 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep) |
1268 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep) |
1211 /** |
1269 /** |
1421 * The comma character is treated as group separator and ignored during parsing. |
1478 * The comma character is treated as group separator and ignored during parsing. |
1422 * If you want to choose a different format, use cx_strtof_lc(). |
1479 * If you want to choose a different format, use cx_strtof_lc(). |
1423 * |
1480 * |
1424 * @param str the string to convert |
1481 * @param str the string to convert |
1425 * @param output a pointer to the float variable where the result shall be stored |
1482 * @param output a pointer to the float variable where the result shall be stored |
1426 * @param decsep the decimal separator |
|
1427 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
|
1428 * @return zero on success, non-zero if conversion was not possible |
1483 * @return zero on success, non-zero if conversion was not possible |
1429 */ |
1484 */ |
1430 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep) |
1485 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",") |
1431 /** |
1486 /** |
1432 * Converts a string to a double precision floating point number. |
1487 * Converts a string to a double precision floating point number. |
1433 * |
1488 * |
1434 * The function returns non-zero when conversion is not possible. |
1489 * The function returns non-zero when conversion is not possible. |
1435 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
1490 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
1439 * The comma character is treated as group separator and ignored during parsing. |
1494 * The comma character is treated as group separator and ignored during parsing. |
1440 * If you want to choose a different format, use cx_strtof_lc(). |
1495 * If you want to choose a different format, use cx_strtof_lc(). |
1441 * |
1496 * |
1442 * @param str the string to convert |
1497 * @param str the string to convert |
1443 * @param output a pointer to the float variable where the result shall be stored |
1498 * @param output a pointer to the float variable where the result shall be stored |
1444 * @param decsep the decimal separator |
|
1445 * @param groupsep each character in this string is treated as group separator and ignored during conversion |
|
1446 * @return zero on success, non-zero if conversion was not possible |
1499 * @return zero on success, non-zero if conversion was not possible |
1447 */ |
1500 */ |
1448 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep) |
|
1449 |
|
1450 /** |
|
1451 * Converts a string to a single precision floating point number. |
|
1452 * |
|
1453 * The function returns non-zero when conversion is not possible. |
|
1454 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
|
1455 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
1456 * |
|
1457 * The decimal separator is assumed to be a dot character. |
|
1458 * The comma character is treated as group separator and ignored during parsing. |
|
1459 * If you want to choose a different format, use cx_strtof_lc(). |
|
1460 * |
|
1461 * @param str the string to convert |
|
1462 * @param output a pointer to the float variable where the result shall be stored |
|
1463 * @return zero on success, non-zero if conversion was not possible |
|
1464 */ |
|
1465 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",") |
|
1466 /** |
|
1467 * Converts a string to a double precision floating point number. |
|
1468 * |
|
1469 * The function returns non-zero when conversion is not possible. |
|
1470 * In that case the function sets errno to EINVAL when the reason is an invalid character. |
|
1471 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h. |
|
1472 * |
|
1473 * The decimal separator is assumed to be a dot character. |
|
1474 * The comma character is treated as group separator and ignored during parsing. |
|
1475 * If you want to choose a different format, use cx_strtof_lc(). |
|
1476 * |
|
1477 * @param str the string to convert |
|
1478 * @param output a pointer to the float variable where the result shall be stored |
|
1479 * @return zero on success, non-zero if conversion was not possible |
|
1480 */ |
|
1481 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",") |
1501 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",") |
|
1502 |
|
1503 #endif |
1482 |
1504 |
1483 #ifdef __cplusplus |
1505 #ifdef __cplusplus |
1484 } // extern "C" |
1506 } // extern "C" |
1485 #endif |
1507 #endif |
1486 |
1508 |