src/cx/string.h

changeset 1134
60edcd57d54c
parent 1127
1fd31909a3f8
equal deleted inserted replaced
1133:0aecb9fda851 1134:60edcd57d54c
832 * @return a duplicate of the string 832 * @return a duplicate of the string
833 * @see cx_strdup() 833 * @see cx_strdup()
834 */ 834 */
835 cx_attr_nodiscard 835 cx_attr_nodiscard
836 cx_attr_nonnull 836 cx_attr_nonnull
837 cxmutstr cx_strdup_a( 837 cxmutstr cx_strdup_a_(
838 const CxAllocator *allocator, 838 const CxAllocator *allocator,
839 cxstring string 839 cxstring string
840 ); 840 );
841
842 /**
843 * Creates a duplicate of the specified string.
844 *
845 * The new string will contain a copy allocated by @p allocator.
846 *
847 * @note The returned string is guaranteed to be zero-terminated.
848 *
849 * @param allocator (@c CxAllocator*) the allocator to use
850 * @param string the string to duplicate
851 * @return (@c cxmutstr) a duplicate of the string
852 * @see cx_strdup()
853 * @see cx_strfree_a()
854 */
855 #define cx_strdup_a(allocator, string) \
856 cx_strdup_a_((allocator), cx_strcast(string))
841 857
842 /** 858 /**
843 * Creates a duplicate of the specified string. 859 * Creates a duplicate of the specified string.
844 * 860 *
845 * The new string will contain a copy allocated by standard 861 * The new string will contain a copy allocated by standard
850 * @param string the string to duplicate 866 * @param string the string to duplicate
851 * @return (@c cxmutstr) a duplicate of the string 867 * @return (@c cxmutstr) a duplicate of the string
852 * @see cx_strdup_a() 868 * @see cx_strdup_a()
853 * @see cx_strfree() 869 * @see cx_strfree()
854 */ 870 */
855 #define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string) 871 #define cx_strdup(string) cx_strdup_a_(cxDefaultAllocator, string)
856 872
857 /** 873 /**
858 * Omits leading and trailing spaces. 874 * Omits leading and trailing spaces.
859 * 875 *
860 * @note the returned string references the same memory, thus you 876 * @note the returned string references the same memory, thus you
1051 * @param delim the delimiter (must not be empty) 1067 * @param delim the delimiter (must not be empty)
1052 * @param limit the maximum number of tokens that shall be returned 1068 * @param limit the maximum number of tokens that shall be returned
1053 * @return a new string tokenization context 1069 * @return a new string tokenization context
1054 */ 1070 */
1055 cx_attr_nodiscard 1071 cx_attr_nodiscard
1056 CxStrtokCtx cx_strtok( 1072 CxStrtokCtx cx_strtok_(
1057 cxstring str, 1073 cxstring str,
1058 cxstring delim, 1074 cxstring delim,
1059 size_t limit 1075 size_t limit
1060 ); 1076 );
1077
1078 /**
1079 * Creates a string tokenization context.
1080 *
1081 * @param str the string to tokenize
1082 * @param delim the delimiter string (must not be empty)
1083 * @param limit (@c size_t) the maximum number of tokens that shall be returned
1084 * @return (@c CxStrtokCtx) a new string tokenization context
1085 */
1086 #define cx_strtok(str, delim, limit) \
1087 cx_strtok_(cx_strcast(str), cx_strcast(delim), (limit))
1061 1088
1062 /** 1089 /**
1063 * Returns the next token. 1090 * Returns the next token.
1064 * 1091 *
1065 * The token will point to the source string. 1092 * The token will point to the source string.
1117 /* ------------------------------------------------------------------------- * 1144 /* ------------------------------------------------------------------------- *
1118 * string to number conversion functions * 1145 * string to number conversion functions *
1119 * ------------------------------------------------------------------------- */ 1146 * ------------------------------------------------------------------------- */
1120 1147
1121 /** 1148 /**
1122 * @copydoc cx_strtouz_lc() 1149 * Converts a string to a number.
1150 *
1151 * The function returns non-zero when conversion is not possible.
1152 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1153 * It sets errno to ERANGE when the target datatype is too small.
1154 *
1155 * @param str the string to convert
1156 * @param output a pointer to the integer variable where the result shall be stored
1157 * @param base 2, 8, 10, or 16
1158 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1159 * @retval zero success
1160 * @retval non-zero conversion was not possible
1123 */ 1161 */
1124 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1162 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1125 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep); 1163 int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep);
1126 /** 1164
1127 * @copydoc cx_strtouz_lc() 1165 /**
1166 * Converts a string to a number.
1167 *
1168 * The function returns non-zero when conversion is not possible.
1169 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1170 * It sets errno to ERANGE when the target datatype is too small.
1171 *
1172 * @param str the string to convert
1173 * @param output a pointer to the integer variable where the result shall be stored
1174 * @param base 2, 8, 10, or 16
1175 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1176 * @retval zero success
1177 * @retval non-zero conversion was not possible
1128 */ 1178 */
1129 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1179 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1130 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep); 1180 int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep);
1131 /** 1181
1132 * @copydoc cx_strtouz_lc() 1182 /**
1183 * Converts a string to a number.
1184 *
1185 * The function returns non-zero when conversion is not possible.
1186 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1187 * It sets errno to ERANGE when the target datatype is too small.
1188 *
1189 * @param str the string to convert
1190 * @param output a pointer to the integer variable where the result shall be stored
1191 * @param base 2, 8, 10, or 16
1192 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1193 * @retval zero success
1194 * @retval non-zero conversion was not possible
1133 */ 1195 */
1134 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1196 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1135 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep); 1197 int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep);
1136 /** 1198
1137 * @copydoc cx_strtouz_lc() 1199 /**
1200 * Converts a string to a number.
1201 *
1202 * The function returns non-zero when conversion is not possible.
1203 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1204 * It sets errno to ERANGE when the target datatype is too small.
1205 *
1206 * @param str the string to convert
1207 * @param output a pointer to the integer variable where the result shall be stored
1208 * @param base 2, 8, 10, or 16
1209 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1210 * @retval zero success
1211 * @retval non-zero conversion was not possible
1138 */ 1212 */
1139 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1213 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1140 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep); 1214 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep);
1141 /** 1215
1142 * @copydoc cx_strtouz_lc() 1216 /**
1217 * Converts a string to a number.
1218 *
1219 * The function returns non-zero when conversion is not possible.
1220 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1221 * It sets errno to ERANGE when the target datatype is too small.
1222 *
1223 * @param str the string to convert
1224 * @param output a pointer to the integer variable where the result shall be stored
1225 * @param base 2, 8, 10, or 16
1226 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1227 * @retval zero success
1228 * @retval non-zero conversion was not possible
1143 */ 1229 */
1144 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1230 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1145 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep); 1231 int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep);
1146 /** 1232
1147 * @copydoc cx_strtouz_lc() 1233 /**
1234 * Converts a string to a number.
1235 *
1236 * The function returns non-zero when conversion is not possible.
1237 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1238 * It sets errno to ERANGE when the target datatype is too small.
1239 *
1240 * @param str the string to convert
1241 * @param output a pointer to the integer variable where the result shall be stored
1242 * @param base 2, 8, 10, or 16
1243 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1244 * @retval zero success
1245 * @retval non-zero conversion was not possible
1148 */ 1246 */
1149 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1247 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1150 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep); 1248 int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep);
1151 /** 1249
1152 * @copydoc cx_strtouz_lc() 1250 /**
1251 * Converts a string to a number.
1252 *
1253 * The function returns non-zero when conversion is not possible.
1254 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1255 * It sets errno to ERANGE when the target datatype is too small.
1256 *
1257 * @param str the string to convert
1258 * @param output a pointer to the integer variable where the result shall be stored
1259 * @param base 2, 8, 10, or 16
1260 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1261 * @retval zero success
1262 * @retval non-zero conversion was not possible
1153 */ 1263 */
1154 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1264 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1155 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep); 1265 int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep);
1156 /** 1266
1157 * @copydoc cx_strtouz_lc() 1267 /**
1268 * Converts a string to a number.
1269 *
1270 * The function returns non-zero when conversion is not possible.
1271 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1272 * It sets errno to ERANGE when the target datatype is too small.
1273 *
1274 * @param str the string to convert
1275 * @param output a pointer to the integer variable where the result shall be stored
1276 * @param base 2, 8, 10, or 16
1277 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1278 * @retval zero success
1279 * @retval non-zero conversion was not possible
1158 */ 1280 */
1159 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1281 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1160 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep); 1282 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep);
1161 /** 1283
1162 * @copydoc cx_strtouz_lc() 1284 /**
1285 * Converts a string to a number.
1286 *
1287 * The function returns non-zero when conversion is not possible.
1288 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1289 * It sets errno to ERANGE when the target datatype is too small.
1290 *
1291 * @param str the string to convert
1292 * @param output a pointer to the integer variable where the result shall be stored
1293 * @param base 2, 8, 10, or 16
1294 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1295 * @retval zero success
1296 * @retval non-zero conversion was not possible
1163 */ 1297 */
1164 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1298 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1165 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep); 1299 int cx_strtoz_lc_(cxstring str, ssize_t *output, int base, const char *groupsep);
1166 /** 1300
1167 * @copydoc cx_strtouz_lc() 1301 /**
1302 * Converts a string to a number.
1303 *
1304 * The function returns non-zero when conversion is not possible.
1305 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1306 * It sets errno to ERANGE when the target datatype is too small.
1307 *
1308 * @param str the string to convert
1309 * @param output a pointer to the integer variable where the result shall be stored
1310 * @param base 2, 8, 10, or 16
1311 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1312 * @retval zero success
1313 * @retval non-zero conversion was not possible
1168 */ 1314 */
1169 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1315 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1170 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep); 1316 int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep);
1171 /** 1317
1172 * @copydoc cx_strtouz_lc() 1318 /**
1319 * Converts a string to a number.
1320 *
1321 * The function returns non-zero when conversion is not possible.
1322 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1323 * It sets errno to ERANGE when the target datatype is too small.
1324 *
1325 * @param str the string to convert
1326 * @param output a pointer to the integer variable where the result shall be stored
1327 * @param base 2, 8, 10, or 16
1328 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1329 * @retval zero success
1330 * @retval non-zero conversion was not possible
1173 */ 1331 */
1174 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1332 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1175 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep); 1333 int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep);
1176 /** 1334
1177 * @copydoc cx_strtouz_lc() 1335 /**
1336 * Converts a string to a number.
1337 *
1338 * The function returns non-zero when conversion is not possible.
1339 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1340 * It sets errno to ERANGE when the target datatype is too small.
1341 *
1342 * @param str the string to convert
1343 * @param output a pointer to the integer variable where the result shall be stored
1344 * @param base 2, 8, 10, or 16
1345 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1346 * @retval zero success
1347 * @retval non-zero conversion was not possible
1178 */ 1348 */
1179 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1349 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1180 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep); 1350 int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep);
1181 /** 1351
1182 * @copydoc cx_strtouz_lc() 1352 /**
1353 * Converts a string to a number.
1354 *
1355 * The function returns non-zero when conversion is not possible.
1356 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1357 * It sets errno to ERANGE when the target datatype is too small.
1358 *
1359 * @param str the string to convert
1360 * @param output a pointer to the integer variable where the result shall be stored
1361 * @param base 2, 8, 10, or 16
1362 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1363 * @retval zero success
1364 * @retval non-zero conversion was not possible
1183 */ 1365 */
1184 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1366 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1185 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep); 1367 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep);
1186 /** 1368
1187 * @copydoc cx_strtouz_lc() 1369 /**
1370 * Converts a string to a number.
1371 *
1372 * The function returns non-zero when conversion is not possible.
1373 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1374 * It sets errno to ERANGE when the target datatype is too small.
1375 *
1376 * @param str the string to convert
1377 * @param output a pointer to the integer variable where the result shall be stored
1378 * @param base 2, 8, 10, or 16
1379 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1380 * @retval zero success
1381 * @retval non-zero conversion was not possible
1188 */ 1382 */
1189 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1383 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1190 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep); 1384 int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep);
1191 /** 1385
1192 * @copydoc cx_strtouz_lc() 1386 /**
1387 * Converts a string to a number.
1388 *
1389 * The function returns non-zero when conversion is not possible.
1390 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1391 * It sets errno to ERANGE when the target datatype is too small.
1392 *
1393 * @param str the string to convert
1394 * @param output a pointer to the integer variable where the result shall be stored
1395 * @param base 2, 8, 10, or 16
1396 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1397 * @retval zero success
1398 * @retval non-zero conversion was not possible
1193 */ 1399 */
1194 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1400 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1195 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep); 1401 int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep);
1196 /** 1402
1197 * @copydoc cx_strtouz_lc() 1403 /**
1404 * Converts a string to a number.
1405 *
1406 * The function returns non-zero when conversion is not possible.
1407 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1408 * It sets errno to ERANGE when the target datatype is too small.
1409 *
1410 * @param str the string to convert
1411 * @param output a pointer to the integer variable where the result shall be stored
1412 * @param base 2, 8, 10, or 16
1413 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1414 * @retval zero success
1415 * @retval non-zero conversion was not possible
1198 */ 1416 */
1199 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1417 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1200 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep); 1418 int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep);
1201 /** 1419
1202 * @copydoc cx_strtouz_lc() 1420 /**
1421 * Converts a string to a number.
1422 *
1423 * The function returns non-zero when conversion is not possible.
1424 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1425 * It sets errno to ERANGE when the target datatype is too small.
1426 *
1427 * @param str the string to convert
1428 * @param output a pointer to the integer variable where the result shall be stored
1429 * @param base 2, 8, 10, or 16
1430 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1431 * @retval zero success
1432 * @retval non-zero conversion was not possible
1203 */ 1433 */
1204 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1434 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1205 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep); 1435 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep);
1206 1436
1207 /** 1437 /**
1208 * Converts a string to a number. 1438 * Converts a string to a number.
1209 * 1439 *
1210 * The function returns non-zero when conversion is not possible. 1440 * The function returns non-zero when conversion is not possible.
1217 * @param groupsep each character in this string is treated as group separator and ignored during conversion 1447 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1218 * @retval zero success 1448 * @retval zero success
1219 * @retval non-zero conversion was not possible 1449 * @retval non-zero conversion was not possible
1220 */ 1450 */
1221 cx_attr_access_w(2) cx_attr_nonnull_arg(2) 1451 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1222 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep); 1452 int cx_strtouz_lc_(cxstring str, size_t *output, int base, const char *groupsep);
1453
1454 /**
1455 * Converts a string to a single precision floating point number.
1456 *
1457 * The function returns non-zero when conversion is not possible.
1458 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1459 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1460 *
1461 * @param str the string to convert
1462 * @param output a pointer to the float variable where the result shall be stored
1463 * @param decsep the decimal separator
1464 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1465 * @retval zero success
1466 * @retval non-zero conversion was not possible
1467 */
1468 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1469 int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep);
1470
1471 /**
1472 * Converts a string to a double precision floating point number.
1473 *
1474 * The function returns non-zero when conversion is not possible.
1475 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1476 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1477 *
1478 * @param str the string to convert
1479 * @param output a pointer to the float variable where the result shall be stored
1480 * @param decsep the decimal separator
1481 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1482 * @retval zero success
1483 * @retval non-zero conversion was not possible
1484 */
1485 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1486 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep);
1487
1488 /**
1489 * Converts a string to a number.
1490 *
1491 * The function returns non-zero when conversion is not possible.
1492 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1493 * It sets errno to ERANGE when the target datatype is too small.
1494 *
1495 * @param str the string to convert
1496 * @param output a pointer to the integer variable where the result shall be stored
1497 * @param base 2, 8, 10, or 16
1498 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1499 * @retval zero success
1500 * @retval non-zero conversion was not possible
1501 */
1502 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep)
1503
1504 /**
1505 * Converts a string to a number.
1506 *
1507 * The function returns non-zero when conversion is not possible.
1508 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1509 * It sets errno to ERANGE when the target datatype is too small.
1510 *
1511 * @param str the string to convert
1512 * @param output a pointer to the integer variable where the result shall be stored
1513 * @param base 2, 8, 10, or 16
1514 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1515 * @retval zero success
1516 * @retval non-zero conversion was not possible
1517 */
1518 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep)
1519
1520 /**
1521 * Converts a string to a number.
1522 *
1523 * The function returns non-zero when conversion is not possible.
1524 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1525 * It sets errno to ERANGE when the target datatype is too small.
1526 *
1527 * @param str the string to convert
1528 * @param output a pointer to the integer variable where the result shall be stored
1529 * @param base 2, 8, 10, or 16
1530 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1531 * @retval zero success
1532 * @retval non-zero conversion was not possible
1533 */
1534 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep)
1535
1536 /**
1537 * Converts a string to a number.
1538 *
1539 * The function returns non-zero when conversion is not possible.
1540 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1541 * It sets errno to ERANGE when the target datatype is too small.
1542 *
1543 * @param str the string to convert
1544 * @param output a pointer to the integer variable where the result shall be stored
1545 * @param base 2, 8, 10, or 16
1546 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1547 * @retval zero success
1548 * @retval non-zero conversion was not possible
1549 */
1550 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep)
1551
1552 /**
1553 * Converts a string to a number.
1554 *
1555 * The function returns non-zero when conversion is not possible.
1556 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1557 * It sets errno to ERANGE when the target datatype is too small.
1558 *
1559 * @param str the string to convert
1560 * @param output a pointer to the integer variable where the result shall be stored
1561 * @param base 2, 8, 10, or 16
1562 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1563 * @retval zero success
1564 * @retval non-zero conversion was not possible
1565 */
1566 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep)
1567
1568 /**
1569 * Converts a string to a number.
1570 *
1571 * The function returns non-zero when conversion is not possible.
1572 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1573 * It sets errno to ERANGE when the target datatype is too small.
1574 *
1575 * @param str the string to convert
1576 * @param output a pointer to the integer variable where the result shall be stored
1577 * @param base 2, 8, 10, or 16
1578 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1579 * @retval zero success
1580 * @retval non-zero conversion was not possible
1581 */
1582 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep)
1583
1584 /**
1585 * Converts a string to a number.
1586 *
1587 * The function returns non-zero when conversion is not possible.
1588 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1589 * It sets errno to ERANGE when the target datatype is too small.
1590 *
1591 * @param str the string to convert
1592 * @param output a pointer to the integer variable where the result shall be stored
1593 * @param base 2, 8, 10, or 16
1594 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1595 * @retval zero success
1596 * @retval non-zero conversion was not possible
1597 */
1598 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep)
1599
1600 /**
1601 * Converts a string to a number.
1602 *
1603 * The function returns non-zero when conversion is not possible.
1604 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1605 * It sets errno to ERANGE when the target datatype is too small.
1606 *
1607 * @param str the string to convert
1608 * @param output a pointer to the integer variable where the result shall be stored
1609 * @param base 2, 8, 10, or 16
1610 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1611 * @retval zero success
1612 * @retval non-zero conversion was not possible
1613 */
1614 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep)
1615
1616 /**
1617 * Converts a string to a number.
1618 *
1619 * The function returns non-zero when conversion is not possible.
1620 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1621 * It sets errno to ERANGE when the target datatype is too small.
1622 *
1623 * @param str the string to convert
1624 * @param output a pointer to the integer variable where the result shall be stored
1625 * @param base 2, 8, 10, or 16
1626 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1627 * @retval zero success
1628 * @retval non-zero conversion was not possible
1629 */
1630 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep)
1631
1632 /**
1633 * Converts a string to a number.
1634 *
1635 * The function returns non-zero when conversion is not possible.
1636 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1637 * It sets errno to ERANGE when the target datatype is too small.
1638 *
1639 * @param str the string to convert
1640 * @param output a pointer to the integer variable where the result shall be stored
1641 * @param base 2, 8, 10, or 16
1642 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1643 * @retval zero success
1644 * @retval non-zero conversion was not possible
1645 */
1646 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep)
1647
1648 /**
1649 * Converts a string to a number.
1650 *
1651 * The function returns non-zero when conversion is not possible.
1652 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1653 * It sets errno to ERANGE when the target datatype is too small.
1654 *
1655 * @param str the string to convert
1656 * @param output a pointer to the integer variable where the result shall be stored
1657 * @param base 2, 8, 10, or 16
1658 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1659 * @retval zero success
1660 * @retval non-zero conversion was not possible
1661 */
1662 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep)
1663
1664 /**
1665 * Converts a string to a number.
1666 *
1667 * The function returns non-zero when conversion is not possible.
1668 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1669 * It sets errno to ERANGE when the target datatype is too small.
1670 *
1671 * @param str the string to convert
1672 * @param output a pointer to the integer variable where the result shall be stored
1673 * @param base 2, 8, 10, or 16
1674 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1675 * @retval zero success
1676 * @retval non-zero conversion was not possible
1677 */
1678 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep)
1679
1680 /**
1681 * Converts a string to a number.
1682 *
1683 * The function returns non-zero when conversion is not possible.
1684 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1685 * It sets errno to ERANGE when the target datatype is too small.
1686 *
1687 * @param str the string to convert
1688 * @param output a pointer to the integer variable where the result shall be stored
1689 * @param base 2, 8, 10, or 16
1690 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1691 * @retval zero success
1692 * @retval non-zero conversion was not possible
1693 */
1694 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep)
1695
1696 /**
1697 * Converts a string to a number.
1698 *
1699 * The function returns non-zero when conversion is not possible.
1700 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1701 * It sets errno to ERANGE when the target datatype is too small.
1702 *
1703 * @param str the string to convert
1704 * @param output a pointer to the integer variable where the result shall be stored
1705 * @param base 2, 8, 10, or 16
1706 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1707 * @retval zero success
1708 * @retval non-zero conversion was not possible
1709 */
1710 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep)
1711
1712 /**
1713 * Converts a string to a number.
1714 *
1715 * The function returns non-zero when conversion is not possible.
1716 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1717 * It sets errno to ERANGE when the target datatype is too small.
1718 *
1719 * @param str the string to convert
1720 * @param output a pointer to the integer variable where the result shall be stored
1721 * @param base 2, 8, 10, or 16
1722 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1723 * @retval zero success
1724 * @retval non-zero conversion was not possible
1725 */
1726 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep)
1727
1728 /**
1729 * Converts a string to a number.
1730 *
1731 * The function returns non-zero when conversion is not possible.
1732 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1733 * It sets errno to ERANGE when the target datatype is too small.
1734 *
1735 * @param str the string to convert
1736 * @param output a pointer to the integer variable where the result shall be stored
1737 * @param base 2, 8, 10, or 16
1738 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1739 * @retval zero success
1740 * @retval non-zero conversion was not possible
1741 */
1742 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep)
1743
1744 /**
1745 * Converts a string to a number.
1746 *
1747 * The function returns non-zero when conversion is not possible.
1748 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1749 * It sets errno to ERANGE when the target datatype is too small.
1750 *
1751 * @param str the string to convert
1752 * @param output a pointer to the integer variable where the result shall be stored
1753 * @param base 2, 8, 10, or 16
1754 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1755 * @retval zero success
1756 * @retval non-zero conversion was not possible
1757 */
1758 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep)
1759
1760 /**
1761 * Converts a string to a number.
1762 *
1763 * The function returns non-zero when conversion is not possible.
1764 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1765 * It sets errno to ERANGE when the target datatype is too small.
1766 *
1767 * @param str the string to convert
1768 * @param output a pointer to the integer variable where the result shall be stored
1769 * @param base 2, 8, 10, or 16
1770 * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
1771 * @retval zero success
1772 * @retval non-zero conversion was not possible
1773 */
1774 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc_(cx_strcast(str), output, base, groupsep)
1775
1776 /**
1777 * Converts a string to a number.
1778 *
1779 * The function returns non-zero when conversion is not possible.
1780 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1781 * It sets errno to ERANGE when the target datatype is too small.
1782 *
1783 * The comma character is treated as group separator and ignored during parsing.
1784 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1785 *
1786 * @param str the string to convert
1787 * @param output a pointer to the integer variable where the result shall be stored
1788 * @param base 2, 8, 10, or 16
1789 * @retval zero success
1790 * @retval non-zero conversion was not possible
1791 */
1792 #define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",")
1793
1794 /**
1795 * Converts a string to a number.
1796 *
1797 * The function returns non-zero when conversion is not possible.
1798 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1799 * It sets errno to ERANGE when the target datatype is too small.
1800 *
1801 * The comma character is treated as group separator and ignored during parsing.
1802 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1803 *
1804 * @param str the string to convert
1805 * @param output a pointer to the integer variable where the result shall be stored
1806 * @param base 2, 8, 10, or 16
1807 * @retval zero success
1808 * @retval non-zero conversion was not possible
1809 */
1810 #define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",")
1811
1812 /**
1813 * Converts a string to a number.
1814 *
1815 * The function returns non-zero when conversion is not possible.
1816 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1817 * It sets errno to ERANGE when the target datatype is too small.
1818 *
1819 * The comma character is treated as group separator and ignored during parsing.
1820 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1821 *
1822 * @param str the string to convert
1823 * @param output a pointer to the integer variable where the result shall be stored
1824 * @param base 2, 8, 10, or 16
1825 * @retval zero success
1826 * @retval non-zero conversion was not possible
1827 */
1828 #define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",")
1829
1830 /**
1831 * Converts a string to a number.
1832 *
1833 * The function returns non-zero when conversion is not possible.
1834 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1835 * It sets errno to ERANGE when the target datatype is too small.
1836 *
1837 * The comma character is treated as group separator and ignored during parsing.
1838 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1839 *
1840 * @param str the string to convert
1841 * @param output a pointer to the integer variable where the result shall be stored
1842 * @param base 2, 8, 10, or 16
1843 * @retval zero success
1844 * @retval non-zero conversion was not possible
1845 */
1846 #define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",")
1847
1848 /**
1849 * Converts a string to a number.
1850 *
1851 * The function returns non-zero when conversion is not possible.
1852 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1853 * It sets errno to ERANGE when the target datatype is too small.
1854 *
1855 * The comma character is treated as group separator and ignored during parsing.
1856 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1857 *
1858 * @param str the string to convert
1859 * @param output a pointer to the integer variable where the result shall be stored
1860 * @param base 2, 8, 10, or 16
1861 * @retval zero success
1862 * @retval non-zero conversion was not possible
1863 */
1864 #define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
1865
1866 /**
1867 * Converts a string to a number.
1868 *
1869 * The function returns non-zero when conversion is not possible.
1870 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1871 * It sets errno to ERANGE when the target datatype is too small.
1872 *
1873 * The comma character is treated as group separator and ignored during parsing.
1874 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1875 *
1876 * @param str the string to convert
1877 * @param output a pointer to the integer variable where the result shall be stored
1878 * @param base 2, 8, 10, or 16
1879 * @retval zero success
1880 * @retval non-zero conversion was not possible
1881 */
1882 #define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
1883
1884 /**
1885 * Converts a string to a number.
1886 *
1887 * The function returns non-zero when conversion is not possible.
1888 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1889 * It sets errno to ERANGE when the target datatype is too small.
1890 *
1891 * The comma character is treated as group separator and ignored during parsing.
1892 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1893 *
1894 * @param str the string to convert
1895 * @param output a pointer to the integer variable where the result shall be stored
1896 * @param base 2, 8, 10, or 16
1897 * @retval zero success
1898 * @retval non-zero conversion was not possible
1899 */
1900 #define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
1901
1902 /**
1903 * Converts a string to a number.
1904 *
1905 * The function returns non-zero when conversion is not possible.
1906 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1907 * It sets errno to ERANGE when the target datatype is too small.
1908 *
1909 * The comma character is treated as group separator and ignored during parsing.
1910 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1911 *
1912 * @param str the string to convert
1913 * @param output a pointer to the integer variable where the result shall be stored
1914 * @param base 2, 8, 10, or 16
1915 * @retval zero success
1916 * @retval non-zero conversion was not possible
1917 */
1918 #define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
1919
1920 /**
1921 * Converts a string to a number.
1922 *
1923 * The function returns non-zero when conversion is not possible.
1924 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1925 * It sets errno to ERANGE when the target datatype is too small.
1926 *
1927 * The comma character is treated as group separator and ignored during parsing.
1928 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1929 *
1930 * @param str the string to convert
1931 * @param output a pointer to the integer variable where the result shall be stored
1932 * @param base 2, 8, 10, or 16
1933 * @retval zero success
1934 * @retval non-zero conversion was not possible
1935 */
1936 #define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",")
1937
1938 /**
1939 * Converts a string to a number.
1940 *
1941 * The function returns non-zero when conversion is not possible.
1942 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1943 * It sets errno to ERANGE when the target datatype is too small.
1944 *
1945 * The comma character is treated as group separator and ignored during parsing.
1946 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1947 *
1948 * @param str the string to convert
1949 * @param output a pointer to the integer variable where the result shall be stored
1950 * @param base 2, 8, 10, or 16
1951 * @retval zero success
1952 * @retval non-zero conversion was not possible
1953 */
1954 #define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",")
1955
1956 /**
1957 * Converts a string to a number.
1958 *
1959 * The function returns non-zero when conversion is not possible.
1960 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1961 * It sets errno to ERANGE when the target datatype is too small.
1962 *
1963 * The comma character is treated as group separator and ignored during parsing.
1964 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1965 *
1966 * @param str the string to convert
1967 * @param output a pointer to the integer variable where the result shall be stored
1968 * @param base 2, 8, 10, or 16
1969 * @retval zero success
1970 * @retval non-zero conversion was not possible
1971 */
1972 #define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",")
1973
1974 /**
1975 * Converts a string to a number.
1976 *
1977 * The function returns non-zero when conversion is not possible.
1978 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1979 * It sets errno to ERANGE when the target datatype is too small.
1980 *
1981 * The comma character is treated as group separator and ignored during parsing.
1982 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1983 *
1984 * @param str the string to convert
1985 * @param output a pointer to the integer variable where the result shall be stored
1986 * @param base 2, 8, 10, or 16
1987 * @retval zero success
1988 * @retval non-zero conversion was not possible
1989 */
1990 #define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",")
1991
1992 /**
1993 * Converts a string to a number.
1994 *
1995 * The function returns non-zero when conversion is not possible.
1996 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1997 * It sets errno to ERANGE when the target datatype is too small.
1998 *
1999 * The comma character is treated as group separator and ignored during parsing.
2000 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2001 *
2002 * @param str the string to convert
2003 * @param output a pointer to the integer variable where the result shall be stored
2004 * @param base 2, 8, 10, or 16
2005 * @retval zero success
2006 * @retval non-zero conversion was not possible
2007 */
2008 #define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",")
2009
2010 /**
2011 * Converts a string to a number.
2012 *
2013 * The function returns non-zero when conversion is not possible.
2014 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2015 * It sets errno to ERANGE when the target datatype is too small.
2016 *
2017 * The comma character is treated as group separator and ignored during parsing.
2018 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2019 *
2020 * @param str the string to convert
2021 * @param output a pointer to the integer variable where the result shall be stored
2022 * @param base 2, 8, 10, or 16
2023 * @retval zero success
2024 * @retval non-zero conversion was not possible
2025 */
2026 #define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",")
2027
2028 /**
2029 * Converts a string to a number.
2030 *
2031 * The function returns non-zero when conversion is not possible.
2032 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2033 * It sets errno to ERANGE when the target datatype is too small.
2034 *
2035 * The comma character is treated as group separator and ignored during parsing.
2036 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2037 *
2038 * @param str the string to convert
2039 * @param output a pointer to the integer variable where the result shall be stored
2040 * @param base 2, 8, 10, or 16
2041 * @retval zero success
2042 * @retval non-zero conversion was not possible
2043 */
2044 #define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",")
2045
2046 /**
2047 * Converts a string to a number.
2048 *
2049 * The function returns non-zero when conversion is not possible.
2050 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2051 * It sets errno to ERANGE when the target datatype is too small.
2052 *
2053 * The comma character is treated as group separator and ignored during parsing.
2054 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2055 *
2056 * @param str the string to convert
2057 * @param output a pointer to the integer variable where the result shall be stored
2058 * @param base 2, 8, 10, or 16
2059 * @retval zero success
2060 * @retval non-zero conversion was not possible
2061 */
2062 #define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",")
2063
2064 /**
2065 * Converts a string to a number.
2066 *
2067 * The function returns non-zero when conversion is not possible.
2068 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2069 * It sets errno to ERANGE when the target datatype is too small.
2070 *
2071 * The comma character is treated as group separator and ignored during parsing.
2072 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2073 *
2074 * @param str the string to convert
2075 * @param output a pointer to the integer variable where the result shall be stored
2076 * @param base 2, 8, 10, or 16
2077 * @retval zero success
2078 * @retval non-zero conversion was not possible
2079 */
2080 #define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",")
2081
2082 /**
2083 * Converts a string to a number.
2084 *
2085 * The function returns non-zero when conversion is not possible.
2086 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
2087 * It sets errno to ERANGE when the target datatype is too small.
2088 *
2089 * The comma character is treated as group separator and ignored during parsing.
2090 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
2091 *
2092 * @param str the string to convert
2093 * @param output a pointer to the integer variable where the result shall be stored
2094 * @param base 2, 8, 10, or 16
2095 * @retval zero success
2096 * @retval non-zero conversion was not possible
2097 */
2098 #define cx_strtouz(str, output, base) cx_strtouz_lc_(cx_strcast(str), output, base, ",")
2099
2100 /**
2101 * Converts a string to a single precision floating point number.
2102 *
2103 * The function returns non-zero when conversion is not possible.
2104 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2105 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
2106 *
2107 * @param str the string to convert
2108 * @param output a pointer to the float variable where the result shall be stored
2109 * @param decsep the decimal separator
2110 * @param groupsep each character in this string is treated as group separator and ignored during conversion
2111 * @retval zero success
2112 * @retval non-zero conversion was not possible
2113 */
2114 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep)
2115
2116 /**
2117 * Converts a string to a double precision floating point number.
2118 *
2119 * The function returns non-zero when conversion is not possible.
2120 * In that case the function sets errno to EINVAL when the reason is an invalid character.
2121 *
2122 * @param str the string to convert
2123 * @param output a pointer to the double variable where the result shall be stored
2124 * @param decsep the decimal separator
2125 * @param groupsep each character in this string is treated as group separator and ignored during conversion
2126 * @retval zero success
2127 * @retval non-zero conversion was not possible
2128 */
2129 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep)
1223 2130
1224 /** 2131 /**
1225 * Converts a string to a single precision floating point number. 2132 * Converts a string to a single precision floating point number.
1226 * 2133 *
1227 * The function returns non-zero when conversion is not possible. 2134 * The function returns non-zero when conversion is not possible.
1232 * The comma character is treated as group separator and ignored during parsing. 2139 * 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(). 2140 * If you want to choose a different format, use cx_strtof_lc().
1234 * 2141 *
1235 * @param str the string to convert 2142 * @param str the string to convert
1236 * @param output a pointer to the float variable where the result shall be stored 2143 * @param output a pointer to the float variable where the result shall be stored
1237 * @param decsep the decimal separator 2144 * @retval zero success
1238 * @param groupsep each character in this string is treated as group separator and ignored during conversion 2145 * @retval non-zero conversion was not possible
1239 * @retval zero success 2146 */
1240 * @retval non-zero conversion was not possible 2147 #define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",")
1241 */
1242 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1243 int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep);
1244 2148
1245 /** 2149 /**
1246 * Converts a string to a double precision floating point number. 2150 * Converts a string to a double precision floating point number.
1247 * 2151 *
1248 * The function returns non-zero when conversion is not possible. 2152 * The function returns non-zero when conversion is not possible.
1249 * In that case the function sets errno to EINVAL when the reason is an invalid character. 2153 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1250 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1251 * 2154 *
1252 * The decimal separator is assumed to be a dot character. 2155 * The decimal separator is assumed to be a dot character.
1253 * The comma character is treated as group separator and ignored during parsing. 2156 * The comma character is treated as group separator and ignored during parsing.
1254 * If you want to choose a different format, use cx_strtof_lc(). 2157 * If you want to choose a different format, use cx_strtof_lc().
1255 * 2158 *
1256 * @param str the string to convert 2159 * @param str the string to convert
1257 * @param output a pointer to the float variable where the result shall be stored
1258 * @param decsep the decimal separator
1259 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1260 * @retval zero success
1261 * @retval non-zero conversion was not possible
1262 */
1263 cx_attr_access_w(2) cx_attr_nonnull_arg(2)
1264 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep);
1265
1266 #ifndef CX_STR_IMPLEMENTATION
1267 /**
1268 * @copydoc cx_strtouz_lc()
1269 */
1270 #define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep)
1271 /**
1272 * @copydoc cx_strtouz_lc()
1273 */
1274 #define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep)
1275 /**
1276 * @copydoc cx_strtouz_lc()
1277 */
1278 #define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep)
1279 /**
1280 * @copydoc cx_strtouz_lc()
1281 */
1282 #define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep)
1283 /**
1284 * @copydoc cx_strtouz_lc()
1285 */
1286 #define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep)
1287 /**
1288 * @copydoc cx_strtouz_lc()
1289 */
1290 #define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep)
1291 /**
1292 * @copydoc cx_strtouz_lc()
1293 */
1294 #define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep)
1295 /**
1296 * @copydoc cx_strtouz_lc()
1297 */
1298 #define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep)
1299 /**
1300 * @copydoc cx_strtouz_lc()
1301 */
1302 #define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep)
1303 /**
1304 * @copydoc cx_strtouz_lc()
1305 */
1306 #define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep)
1307 /**
1308 * @copydoc cx_strtouz_lc()
1309 */
1310 #define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep)
1311 /**
1312 * @copydoc cx_strtouz_lc()
1313 */
1314 #define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep)
1315 /**
1316 * @copydoc cx_strtouz_lc()
1317 */
1318 #define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep)
1319 /**
1320 * @copydoc cx_strtouz_lc()
1321 */
1322 #define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep)
1323 /**
1324 * @copydoc cx_strtouz_lc()
1325 */
1326 #define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep)
1327 /**
1328 * @copydoc cx_strtouz_lc()
1329 */
1330 #define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep)
1331 /**
1332 * @copydoc cx_strtouz_lc()
1333 */
1334 #define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep)
1335 /**
1336 * Converts a string to a number.
1337 *
1338 * The function returns non-zero when conversion is not possible.
1339 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1340 * It sets errno to ERANGE when the target datatype is too small.
1341 *
1342 * @param str the string to convert
1343 * @param output a pointer to the integer variable where the result shall be stored
1344 * @param base 2, 8, 10, or 16
1345 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1346 * @retval zero success
1347 * @retval non-zero conversion was not possible
1348 */
1349 #define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep)
1350
1351 /**
1352 * @copydoc cx_strtouz()
1353 */
1354 #define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",")
1355 /**
1356 * @copydoc cx_strtouz()
1357 */
1358 #define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",")
1359 /**
1360 * @copydoc cx_strtouz()
1361 */
1362 #define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",")
1363 /**
1364 * @copydoc cx_strtouz()
1365 */
1366 #define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",")
1367 /**
1368 * @copydoc cx_strtouz()
1369 */
1370 #define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",")
1371 /**
1372 * @copydoc cx_strtouz()
1373 */
1374 #define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",")
1375 /**
1376 * @copydoc cx_strtouz()
1377 */
1378 #define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",")
1379 /**
1380 * @copydoc cx_strtouz()
1381 */
1382 #define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",")
1383 /**
1384 * @copydoc cx_strtouz()
1385 */
1386 #define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",")
1387 /**
1388 * @copydoc cx_strtouz()
1389 */
1390 #define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",")
1391 /**
1392 * @copydoc cx_strtouz()
1393 */
1394 #define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",")
1395 /**
1396 * @copydoc cx_strtouz()
1397 */
1398 #define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",")
1399 /**
1400 * @copydoc cx_strtouz()
1401 */
1402 #define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",")
1403 /**
1404 * @copydoc cx_strtouz()
1405 */
1406 #define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",")
1407 /**
1408 * @copydoc cx_strtouz()
1409 */
1410 #define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",")
1411 /**
1412 * @copydoc cx_strtouz()
1413 */
1414 #define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",")
1415 /**
1416 * @copydoc cx_strtouz()
1417 */
1418 #define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",")
1419 /**
1420 * Converts a string to a number.
1421 *
1422 * The function returns non-zero when conversion is not possible.
1423 * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
1424 * It sets errno to ERANGE when the target datatype is too small.
1425 *
1426 * The comma character is treated as group separator and ignored during parsing.
1427 * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
1428 *
1429 * @param str the string to convert
1430 * @param output a pointer to the integer variable where the result shall be stored
1431 * @param base 2, 8, 10, or 16
1432 * @retval zero success
1433 * @retval non-zero conversion was not possible
1434 */
1435 #define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",")
1436
1437 /**
1438 * Converts a string to a single precision floating point number.
1439 *
1440 * The function returns non-zero when conversion is not possible.
1441 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1442 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1443 *
1444 * The decimal separator is assumed to be a dot character.
1445 * The comma character is treated as group separator and ignored during parsing.
1446 * If you want to choose a different format, use cx_strtof_lc().
1447 *
1448 * @param str the string to convert
1449 * @param output a pointer to the float variable where the result shall be stored
1450 * @param decsep the decimal separator
1451 * @param groupsep each character in this string is treated as group separator and ignored during conversion
1452 * @retval zero success
1453 * @retval non-zero conversion was not possible
1454 */
1455 #define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep)
1456 /**
1457 * Converts a string to a double precision floating point number.
1458 *
1459 * The function returns non-zero when conversion is not possible.
1460 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1461 *
1462 * The decimal separator is assumed to be a dot character.
1463 * The comma character is treated as group separator and ignored during parsing.
1464 * If you want to choose a different format, use cx_strtof_lc().
1465 *
1466 * @param str the string to convert
1467 * @param output a pointer to the double variable where the result shall be stored 2160 * @param output a pointer to the double variable where the result shall be stored
1468 * @param decsep the decimal separator 2161 * @retval zero success
1469 * @param groupsep each character in this string is treated as group separator and ignored during conversion 2162 * @retval non-zero conversion was not possible
1470 * @retval zero success 2163 */
1471 * @retval non-zero conversion was not possible 2164 #define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",")
1472 */
1473 #define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep)
1474
1475 /**
1476 * Converts a string to a single precision floating point number.
1477 *
1478 * The function returns non-zero when conversion is not possible.
1479 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1480 * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
1481 *
1482 * The decimal separator is assumed to be a dot character.
1483 * The comma character is treated as group separator and ignored during parsing.
1484 * If you want to choose a different format, use cx_strtof_lc().
1485 *
1486 * @param str the string to convert
1487 * @param output a pointer to the float variable where the result shall be stored
1488 * @retval zero success
1489 * @retval non-zero conversion was not possible
1490 */
1491 #define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",")
1492 /**
1493 * Converts a string to a double precision floating point number.
1494 *
1495 * The function returns non-zero when conversion is not possible.
1496 * In that case the function sets errno to EINVAL when the reason is an invalid character.
1497 *
1498 * The decimal separator is assumed to be a dot character.
1499 * The comma character is treated as group separator and ignored during parsing.
1500 * If you want to choose a different format, use cx_strtof_lc().
1501 *
1502 * @param str the string to convert
1503 * @param output a pointer to the double variable where the result shall be stored
1504 * @retval zero success
1505 * @retval non-zero conversion was not possible
1506 */
1507 #define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",")
1508
1509 /**
1510 * Creates a duplicate of the specified string.
1511 *
1512 * The new string will contain a copy allocated by @p allocator.
1513 *
1514 * @note The returned string is guaranteed to be zero-terminated.
1515 *
1516 * @param allocator (@c CxAllocator*) the allocator to use
1517 * @param string the string to duplicate
1518 * @return (@c cxmutstr) a duplicate of the string
1519 * @see cx_strdup()
1520 * @see cx_strfree_a()
1521 */
1522 #define cx_strdup_a(allocator, string) \
1523 cx_strdup_a((allocator), cx_strcast(string))
1524
1525 /**
1526 * Creates a string tokenization context.
1527 *
1528 * @param str the string to tokenize
1529 * @param delim the delimiter string (must not be empty)
1530 * @param limit (@c @size_t) the maximum number of tokens that shall be returned
1531 * @return (@c CxStrtokCtx) a new string tokenization context
1532 */
1533 #define cx_strtok(str, delim, limit) \
1534 cx_strtok(cx_strcast(str), cx_strcast(delim), (limit))
1535
1536 #endif
1537 2165
1538 #ifdef __cplusplus 2166 #ifdef __cplusplus
1539 } // extern "C" 2167 } // extern "C"
1540 #endif 2168 #endif
1541 2169

mercurial