Commit 4ed8b71f authored by EXT Arnaud Clère's avatar EXT Arnaud Clère

Fixed QByteArray decoding from text representation

parent 9cd59427
......@@ -748,9 +748,9 @@ protected:
const QByteArray& bytes = s.utf8();
if (!bytes.startsWith("0x") || s.size()%2==1) return false;
b.reserve((s.size()-2)/2);
auto toHex = [](char a) -> char { return '0'<=a && a<='9' ? a-'0' : 'A'<=a && a<='F' ? a-'A' : 'a'<=a && a<='f' ? a-'a' : -1; };
auto fromHex = [](char a) -> char { return '0'<=a && a<='9' ? a-'0' : 'A'<=a && a<='F' ? a-'A'+10 : 'a'<=a && a<='f' ? a-'a'+10 : -1; };
for (int i=0; i < b.size(); i++) {
char highDigit=toHex(bytes[2+2*i]), lowDigit=toHex(bytes[2+2*i+1]);
char highDigit=fromHex(bytes[2+2*i]), lowDigit=fromHex(bytes[2+2*i+1]);
if (highDigit<0 || lowDigit<0)
return false;
b.append(char(highDigit<<4)+lowDigit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment