src/string.c

changeset 1162
e3bb67b72d33
parent 1161
747c4baed44f
equal deleted inserted replaced
1161:747c4baed44f 1162:e3bb67b72d33
686 } while (searchstr.length > 0 && found < replmax); 686 } while (searchstr.length > 0 && found < replmax);
687 687
688 // Allocate result string 688 // Allocate result string
689 cxmutstr result; 689 cxmutstr result;
690 { 690 {
691 ssize_t adjlen = (ssize_t) replacement.length - (ssize_t) pattern.length; 691 long long adjlen = (long long) replacement.length - (long long) pattern.length;
692 size_t rcount = 0; 692 size_t rcount = 0;
693 curbuf = &ibuf; 693 curbuf = &ibuf;
694 do { 694 do {
695 rcount += curbuf->len; 695 rcount += curbuf->len;
696 curbuf = curbuf->next; 696 curbuf = curbuf->next;
897 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep) { 897 int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep) {
898 assert(sizeof(long long) == sizeof(int64_t)); // should be true on all platforms 898 assert(sizeof(long long) == sizeof(int64_t)); // should be true on all platforms
899 return cx_strtoll_lc(str, (long long*) output, base, groupsep); 899 return cx_strtoll_lc(str, (long long*) output, base, groupsep);
900 } 900 }
901 901
902 int cx_strtoz_lc_(cxstring str, ssize_t *output, int base, const char *groupsep) {
903 #if SSIZE_MAX == INT32_MAX
904 return cx_strtoi32_lc_(str, (int32_t*) output, base, groupsep);
905 #elif SSIZE_MAX == INT64_MAX
906 return cx_strtoll_lc_(str, (long long*) output, base, groupsep);
907 #else
908 #error "unsupported ssize_t size"
909 #endif
910 }
911
912 #define cx_strtoX_unsigned_impl(rtype, rmax) \ 902 #define cx_strtoX_unsigned_impl(rtype, rmax) \
913 uint64_t result; \ 903 uint64_t result; \
914 if (cx_strtou64_lc(str, &result, base, groupsep)) { \ 904 if (cx_strtou64_lc(str, &result, base, groupsep)) { \
915 return -1; \ 905 return -1; \
916 } \ 906 } \
1027 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep) { 1017 int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep) {
1028 assert(sizeof(unsigned long long) == sizeof(uint64_t)); // should be true on all platforms 1018 assert(sizeof(unsigned long long) == sizeof(uint64_t)); // should be true on all platforms
1029 return cx_strtoull_lc(str, (unsigned long long*) output, base, groupsep); 1019 return cx_strtoull_lc(str, (unsigned long long*) output, base, groupsep);
1030 } 1020 }
1031 1021
1032 int cx_strtouz_lc_(cxstring str, size_t *output, int base, const char *groupsep) { 1022 int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep) {
1033 #if SIZE_MAX == UINT32_MAX 1023 #if SIZE_MAX == UINT32_MAX
1034 return cx_strtou32_lc_(str, (uint32_t*) output, base, groupsep); 1024 return cx_strtou32_lc_(str, (uint32_t*) output, base, groupsep);
1035 #elif SIZE_MAX == UINT64_MAX 1025 #elif SIZE_MAX == UINT64_MAX
1036 return cx_strtoull_lc_(str, (unsigned long long *) output, base, groupsep); 1026 return cx_strtoull_lc_(str, (unsigned long long *) output, base, groupsep);
1037 #else 1027 #else

mercurial