comparison th_string.c @ 131:3896861974ac

Added th_get_hex_triplet().
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 17:02:35 +0300
parents f741718d13c5
children a1ee6c76ca1c
comparison
equal deleted inserted replaced
130:352ec3c300e4 131:3896861974ac
416 } while (didMatch && !isEnd); 416 } while (didMatch && !isEnd);
417 417
418 return didMatch; 418 return didMatch;
419 } 419 }
420 420
421
422 int th_get_hex_triplet(const char *str)
423 {
424 const char *p = str;
425 int len, val = 0;
426
427 for (len = 0; *p && len < 6; p++, len++) {
428 if (*p >= '0' && *p <= '9') {
429 val *= 16; val += (*p - '0');
430 } else if (*p >= 'A' && *p <= 'F') {
431 val *= 16; val += (*p - 'A') + 10;
432 } else if (*p >= 'a' && *p <= 'f') {
433 val *= 16; val += (*p - 'a') + 10;
434 } else
435 return -1;
436 }
437
438 return (len == 6) ? val : -1;
439 }
440
441