MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / isValidHex

Method isValidHex

KittyMemoryEx/KittyUtils.cpp:217–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215 }
216
217 bool String::isValidHex(const std::string &hex)
218 {
219 if (hex.empty())
220 return false;
221
222 const char *data = hex.c_str();
223 size_t len = hex.length();
224 size_t i = 0;
225
226 while (i < len && ::isspace(static_cast<unsigned char>(data[i])))
227 {
228 i++;
229 }
230
231 if (i + 2 <= len && data[i] == '0' && (data[i + 1] == 'x' || data[i + 1] == 'X'))
232 {
233 i += 2;
234 }
235
236 size_t digitCount = 0;
237
238 for (; i < len; ++i)
239 {
240 unsigned char c = static_cast<unsigned char>(data[i]);
241
242 if (::isspace(c))
243 {
244 continue;
245 }
246
247 if (!::isxdigit(c))
248 {
249 return false;
250 }
251
252 digitCount++;
253 }
254
255 return (digitCount > 0 && (digitCount % 2 == 0));
256 }
257
258 bool String::validateHex(std::string &hex)
259 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected