longlong my_strtoll10(constchar *nptr, char **endptr, int *error)
{ constchar *s, *end, *start, *n_end, *true_end; char *dummy;
uchar c; unsignedlong i, j, k;
ulonglong li; int negative;
ulong cutoff, cutoff2, cutoff3;
s= nptr; /* If fixed length string */ if (endptr)
{
end= *endptr; /* Skip leading spaces */ for ( ; s < end && my_isspace(&my_charset_latin1, *s) ; )
s++;
if (s == end) goto no_conv;
} else
{
endptr= &dummy; /* Easier end test */ /* Skip leading spaces */ for ( ; ; s++)
{ if (!*s) goto no_conv; if (!my_isspace(&my_charset_latin1, *s)) break;
}
/* This number must be big to guard against a lot of pre-zeros */
end= s+65535; /* Can't be longer than this */
}
/* Check for a sign. */
negative= 0; if (*s == '-')
{
*error= -1; /* Mark as negative number */
negative= 1; if (++s == end) goto no_conv;
cutoff= MAX_NEGATIVE_NUMBER / LFACTOR2;
cutoff2= (MAX_NEGATIVE_NUMBER % LFACTOR2) / 100;
cutoff3= MAX_NEGATIVE_NUMBER % 100;
} else
{
*error= 0; if (*s == '+')
{ if (++s == end) goto no_conv;
}
cutoff= ULONGLONG_MAX / LFACTOR2;
cutoff2= ULONGLONG_MAX % LFACTOR2 / 100;
cutoff3= ULONGLONG_MAX % 100;
}
/* Handle case where we have a lot of pre-zero */ if (*s == '0')
{
i= 0; do
{ if (++s == end) goto end_i; /* Return 0 */
} while (*s == '0');
n_end= s+ INIT_CNT;
} else
{ /* Read first digit to check that it's a valid number */ if ((c= (*s-'0')) > 9) goto no_conv;
i= c;
n_end= ++s+ INIT_CNT-1;
}
/* Handle first 9 digits and store them in i */ if (n_end > end)
n_end= end; for (; s != n_end ; s++)
{ if ((c= (*s-'0')) > 9) goto end_i;
i= i*10+c;
} if (s == end) goto end_i;
/* Handle next 9 digits and store them in j */
j= 0;
start= s; /* Used to know how much to shift i */
n_end= true_end= s + INIT_CNT; if (n_end > end)
n_end= end; do
{ if ((c= (*s-'0')) > 9) goto end_i_and_j;
j= j*10+c;
} while (++s != n_end); if (s == end)
{ if (s != true_end) goto end_i_and_j; goto end3;
} if ((c= (*s-'0')) > 9) goto end3;
/* Handle the next 1 or 2 digits and store them in k */
k=c; if (++s == end || (c= (*s-'0')) > 9) goto end4;
k= k*10+c;
*endptr= (char*) ++s;
/* number string should have ended here */ if (s != end && (c= (*s-'0')) <= 9) goto overflow;
/* Check that we didn't get an overflow with the last digit */ if (i > cutoff || (i == cutoff && (j > cutoff2 || (j == cutoff2 &&
k > cutoff3)))) goto overflow;
li=i*LFACTOR2+ (ulonglong) j*100 + k; return (longlong) li;
overflow: /* *endptr is set here */
*error= MY_ERRNO_ERANGE; return negative ? LONGLONG_MIN : (longlong) ULONGLONG_MAX;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.