| 813 size_t count |
815 size_t count |
| 814 ) { |
816 ) { |
| 815 ctx->delim_more = delim; |
817 ctx->delim_more = delim; |
| 816 ctx->delim_more_count = count; |
818 ctx->delim_more_count = count; |
| 817 } |
819 } |
| |
820 |
| |
821 #define cx_strtoX_signed_impl(rtype, rmin, rmax) \ |
| |
822 int64_t result; \ |
| |
823 if (cx_strtoi64_lc(str, &result, base, groupsep)) { \ |
| |
824 return -1; \ |
| |
825 } \ |
| |
826 if (result < rmin || result > rmax) { \ |
| |
827 errno = ERANGE; \ |
| |
828 return -1; \ |
| |
829 } \ |
| |
830 *output = (rtype) result; \ |
| |
831 return 0 |
| |
832 |
| |
833 int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep) { |
| |
834 cx_strtoX_signed_impl(short, SHRT_MIN, SHRT_MAX); |
| |
835 } |
| |
836 |
| |
837 int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep) { |
| |
838 cx_strtoX_signed_impl(int, INT_MIN, INT_MAX); |
| |
839 } |
| |
840 |
| |
841 int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep) { |
| |
842 cx_strtoX_signed_impl(long, LONG_MIN, LONG_MAX); |
| |
843 } |
| |
844 |
| |
845 int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep) { |
| |
846 assert(sizeof(long long) == sizeof(int64_t)); // should be true on all platforms |
| |
847 return cx_strtoi64_lc(str, (int64_t*) output, base, groupsep); |
| |
848 } |
| |
849 |
| |
850 int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep) { |
| |
851 cx_strtoX_signed_impl(int8_t, INT8_MIN, INT8_MAX); |
| |
852 } |
| |
853 |
| |
854 int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep) { |
| |
855 cx_strtoX_signed_impl(int16_t, INT16_MIN, INT16_MAX); |
| |
856 } |
| |
857 |
| |
858 int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep) { |
| |
859 cx_strtoX_signed_impl(int32_t, INT32_MIN, INT32_MAX); |
| |
860 } |
| |
861 |
| |
862 int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep) { |
| |
863 // TODO: implement |
| |
864 return -1; |
| |
865 } |
| |
866 |
| |
867 int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep) { |
| |
868 #if CX_WORDSIZE == 32 |
| |
869 return cx_strtoi32_lc(str, output, base, groupsep); |
| |
870 #else |
| |
871 return cx_strtoi64_lc(str, output, base, groupsep); |
| |
872 #endif |
| |
873 } |
| |
874 |
| |
875 #define cx_strtoX_unsigned_impl(rtype, rmax) \ |
| |
876 uint64_t result; \ |
| |
877 if (cx_strtou64_lc(str, &result, base, groupsep)) { \ |
| |
878 return -1; \ |
| |
879 } \ |
| |
880 if (result > rmax) { \ |
| |
881 errno = ERANGE; \ |
| |
882 return -1; \ |
| |
883 } \ |
| |
884 *output = (rtype) result; \ |
| |
885 return 0 |
| |
886 |
| |
887 int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep) { |
| |
888 cx_strtoX_unsigned_impl(unsigned short, USHRT_MAX); |
| |
889 } |
| |
890 |
| |
891 int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep) { |
| |
892 cx_strtoX_unsigned_impl(unsigned int, UINT_MAX); |
| |
893 } |
| |
894 |
| |
895 int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep) { |
| |
896 cx_strtoX_unsigned_impl(unsigned long, ULONG_MAX); |
| |
897 } |
| |
898 |
| |
899 int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep) { |
| |
900 assert(sizeof(unsigned long long) == sizeof(uint64_t)); // should be true on all platforms |
| |
901 return cx_strtou64_lc(str, (uint64_t*) output, base, groupsep); |
| |
902 } |
| |
903 |
| |
904 int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep) { |
| |
905 cx_strtoX_unsigned_impl(uint8_t, UINT8_MAX); |
| |
906 } |
| |
907 |
| |
908 int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep) { |
| |
909 cx_strtoX_unsigned_impl(uint16_t, UINT16_MAX); |
| |
910 } |
| |
911 |
| |
912 int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep) { |
| |
913 cx_strtoX_unsigned_impl(uint32_t, UINT32_MAX); |
| |
914 } |
| |
915 |
| |
916 int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep) { |
| |
917 // TODO: implement |
| |
918 return -1; |
| |
919 } |
| |
920 |
| |
921 int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep) { |
| |
922 #if CX_WORDSIZE == 32 |
| |
923 return cx_strtou32_lc(str, output, base, groupsep); |
| |
924 #else |
| |
925 return cx_strtou64_lc(str, output, base, groupsep); |
| |
926 #endif |
| |
927 } |
| |
928 |
| |
929 int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep) { |
| |
930 // TODO: impl |
| |
931 return -1; |
| |
932 } |
| |
933 |
| |
934 int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep) { |
| |
935 // TODO: impl |
| |
936 return -1; |
| |
937 } |