summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/utils/hexa.cc
diff options
context:
space:
mode:
Diffstat (limited to '2004/i/nono/src/utils/hexa.cc')
-rw-r--r--2004/i/nono/src/utils/hexa.cc51
1 files changed, 29 insertions, 22 deletions
diff --git a/2004/i/nono/src/utils/hexa.cc b/2004/i/nono/src/utils/hexa.cc
index fbcf4e9..236342b 100644
--- a/2004/i/nono/src/utils/hexa.cc
+++ b/2004/i/nono/src/utils/hexa.cc
@@ -28,24 +28,25 @@
static const char *digit2hexTbl_ = "0123456789abcdef";
// Table de conversion depuis l'hexa.
+#define hI hexInvalid
static const int hex2digitTbl_[] =
{
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 0-15 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 16-31 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 32-47 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, /* 48-63 */
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 64-79 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-95 */
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 96-111 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 112-127 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 128-143 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 144-159 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 160-175 */
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 176-191 */
- -1,-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I,hI,hI, /* 208-223 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 224-239 */
+ hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI,hI, /* 240-255 */
};
/// Converti un caractère hexa (0-9a-f) en chiffre (0-15).
@@ -66,17 +67,23 @@ digit2hex (int d)
int
hexSignedChar2int (const char *s)
{
- return (signed char) (hex2digit (s[0]) << 4
- | hex2digit (s[1]) << 0);
+ int h1 = hex2digit (s[0]);
+ int h0 = hex2digit (s[1]);
+ if (h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (signed char) (h1 << 4 | h0);
}
/// Décode un mot signé (2 octets).
int
hexSignedShort2int (const char *s)
{
- return (short) (hex2digit (s[0]) << 12
- | hex2digit (s[1]) << 8
- | hex2digit (s[2]) << 4
- | hex2digit (s[3]));
+ int h3 = hex2digit (s[0]);
+ int h2 = hex2digit (s[1]);
+ int h1 = hex2digit (s[2]);
+ int h0 = hex2digit (s[3]);
+ if (h3 == hexInvalid || h2 == hexInvalid || h1 == hexInvalid || h0 == hexInvalid)
+ return hexInvalid;
+ return (short) (h3 << 12 | h2 << 8 | h1 << 4 | h0);
}