00001
00002
00003
00004
00005
00006
00007 #include "common.h"
00008 #include "sqlNum.h"
00009
00010 static char const rcsid[] = "$Id: sqlNum.c,v 1.16 2005/12/09 22:39:36 hiram Exp $";
00011
00012 unsigned sqlUnsigned(char *s)
00013
00014
00015
00016 {
00017 unsigned res = 0;
00018 char *p = s;
00019 char c;
00020
00021 while (((c = *(p++)) >= '0') && (c <= '9'))
00022 {
00023 res *= 10;
00024 res += c - '0';
00025 }
00026 if (c != '\0')
00027 errAbort("invalid unsigned number: \"%s\"", s);
00028 return res;
00029 }
00030
00031 unsigned long sqlUnsignedLong(char *s)
00032
00033
00034
00035 {
00036 unsigned long res = 0;
00037 char *p = s;
00038 char c;
00039
00040 while (((c = *(p++)) >= '0') && (c <= '9'))
00041 {
00042 res *= 10;
00043 res += c - '0';
00044 }
00045 if (c != '\0')
00046 errAbort("invalid unsigned number: \"%s\"", s);
00047 return res;
00048 }
00049
00050 int sqlSigned(char *s)
00051
00052
00053 {
00054 int res = 0;
00055 char *p, *p0 = s;
00056
00057 if (*p0 == '-')
00058 p0++;
00059 p = p0;
00060 while ((*p >= '0') && (*p <= '9'))
00061 {
00062 res *= 10;
00063 res += *p - '0';
00064 p++;
00065 }
00066
00067 if ((*p != '\0') || (p == p0))
00068 errAbort("invalid signed number: \"%s\"", s);
00069 if (*s == '-')
00070 return -res;
00071 else
00072 return res;
00073 }
00074
00075 long long sqlLongLong(char *s)
00076
00077
00078 {
00079 long long res = 0;
00080 char *p, *p0 = s;
00081
00082 if (*p0 == '-')
00083 p0++;
00084 p = p0;
00085 while ((*p >= '0') && (*p <= '9'))
00086 {
00087 res *= 10;
00088 res += *p - '0';
00089 p++;
00090 }
00091
00092 if ((*p != '\0') || (p == p0))
00093 errAbort("invalid signed number: \"%s\"", s);
00094 if (*s == '-')
00095 return -res;
00096 else
00097 return res;
00098 }
00099
00100 float sqlFloat(char *s)
00101
00102
00103 {
00104 char* end;
00105
00106
00107
00108
00109 float val = (float) strtod(s, &end);
00110
00111 if ((end == s) || (*end != '\0'))
00112 errAbort("invalid float: %s", s);
00113 return val;
00114 }
00115
00116 double sqlDouble(char *s)
00117
00118
00119 {
00120 char* end;
00121 double val = strtod(s, &end);
00122
00123 if ((end == s) || (*end != '\0'))
00124 errAbort("invalid double: %s", s);
00125 return val;
00126 }