src/string.c

changeset 1155
b77d56a27e9c
parent 1137
61939929030a
child 1161
747c4baed44f
equal deleted inserted replaced
1154:afd12f31d28a 1155:b77d56a27e9c
845 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep) { 845 int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep) {
846 // strategy: parse as unsigned, check range, negate if required 846 // strategy: parse as unsigned, check range, negate if required
847 bool neg = false; 847 bool neg = false;
848 size_t start_unsigned = 0; 848 size_t start_unsigned = 0;
849 849
850 // trim already, to search for a sign character 850 // emptiness check
851 str = cx_strtrim(str);
852 if (str.length == 0) { 851 if (str.length == 0) {
853 errno = EINVAL; 852 errno = EINVAL;
854 return -1; 853 return -1;
855 } 854 }
856 855
939 cx_strtoX_unsigned_impl(unsigned long, ULONG_MAX); 938 cx_strtoX_unsigned_impl(unsigned long, ULONG_MAX);
940 } 939 }
941 940
942 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep) { 941 int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep) {
943 // some sanity checks 942 // some sanity checks
944 str = cx_strtrim(str);
945 if (str.length == 0) { 943 if (str.length == 0) {
946 errno = EINVAL; 944 errno = EINVAL;
947 return -1; 945 return -1;
948 } 946 }
949 if (!(base == 2 || base == 8 || base == 10 || base == 16)) { 947 if (!(base == 2 || base == 8 || base == 10 || base == 16)) {
1068 1066
1069 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep) { 1067 int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep) {
1070 // TODO: overflow check 1068 // TODO: overflow check
1071 // TODO: increase precision 1069 // TODO: increase precision
1072 1070
1073 // trim and check 1071 // emptiness check
1074 str = cx_strtrim(str);
1075 if (str.length == 0) { 1072 if (str.length == 0) {
1076 errno = EINVAL; 1073 errno = EINVAL;
1077 return -1; 1074 return -1;
1078 } 1075 }
1079 1076

mercurial