67 {
68 if (!
strcmp (val_str,
"true")) {
69 *res_ptr = 1;
70 return true;
71 }
72 if (!
strcmp (val_str,
"false")) {
73 *res_ptr = 0;
74 return true;
75 }
77 char const *
p = val_str;
79 if (ch == '-') {
82 }
83 if (!isdigit (ch))
84 return false;
85 const unsigned max = -(unsigned) INT_MIN;
86 unsigned res = ch - '0';
87 while (isdigit ((ch = *
p++))) {
88 if (max / 10 < res)
89 return false;
90 res *= 10;
91 const unsigned digit = ch - '0';
92 if (max - digit < res)
93 return false;
94 res += digit;
95 if (!res)
96 return false;
97 }
98 if (ch == 'e')
99 {
100 if (!isdigit ((ch = *
p++)))
101 return false;
102 if (res) {
104 return false;
105 const unsigned digit = ch - '0';
106 for (unsigned i = 0; i < digit; i++) {
107 if (max / 10 < res)
108 return false;
109 res *= 10;
110 }
111 } else
112 {
113 while (isdigit (ch = *
p++))
114 ;
115 if (ch)
116 return false;
117 }
118 } else if (ch == '^')
119 {
120 const unsigned base = res;
121 if (!isdigit ((ch = *
p++)))
122 return false;
123 unsigned exp = ch - '0';
124 if (base < 2)
125 {
126 while (isdigit (ch = *
p++))
127 ;
128 if (ch)
129 return false;
130 }
else if (isdigit (ch = *
p++))
131 {
133 return false;
134 exp *= 10;
135 const unsigned digit = ch - '0';
136 exp += digit;
137 if (!exp)
138 return false;
139 } else if (ch)
140 return false;
141 if (exp)
142 for (unsigned i = 1; i < exp; i++) {
143 if (max / base < res)
144 return false;
145 res *= base;
146 }
147 else if (base)
148 res = 1;
149 else
150 return false;
151 } else if (ch)
152 return false;
154 if (sign > 0 && res == max)
155 return false;
157 *res_ptr = res;
158 return true;
159}