MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / internal_str2dec

Function internal_str2dec

strings/decimal.c:796–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794*/
795
796int
797internal_str2dec(const char *from, decimal_t *to, char **end, my_bool fixed)
798{
799 const char *s= from, *s1, *endp, *end_of_string= *end;
800 int i, intg, frac, error, intg1, frac1;
801 dec1 x,*buf;
802 sanity(to);
803
804 error= E_DEC_BAD_NUM; /* In case of bad number */
805 while (s < end_of_string && my_isspace(&my_charset_latin1, *s))
806 s++;
807 if (s == end_of_string)
808 goto fatal_error;
809
810 if ((to->sign= (*s == '-')))
811 s++;
812 else if (*s == '+')
813 s++;
814
815 s1=s;
816 while (s < end_of_string && my_isdigit(&my_charset_latin1, *s))
817 s++;
818 intg= (int) (s-s1);
819 if (s < end_of_string && *s=='.')
820 {
821 endp= s+1;
822 while (endp < end_of_string && my_isdigit(&my_charset_latin1, *endp))
823 endp++;
824 frac= (int) (endp - s - 1);
825 }
826 else
827 {
828 frac= 0;
829 endp= s;
830 }
831
832 *end= (char*) endp;
833
834 if (frac+intg == 0)
835 goto fatal_error;
836
837 error= 0;
838 if (fixed)
839 {
840 if (frac > to->frac)
841 {
842 error=E_DEC_TRUNCATED;
843 frac=to->frac;
844 }
845 if (intg > to->intg)
846 {
847 error=E_DEC_OVERFLOW;
848 intg=to->intg;
849 }
850 intg1=ROUND_UP(intg);
851 frac1=ROUND_UP(frac);
852 if (intg1+frac1 > to->len)
853 {

Callers

nothing calls this directly

Calls 2

my_strtoll10Function · 0.85
decimal_shiftFunction · 0.85

Tested by

no test coverage detected