| 27 | |
| 28 | |
| 29 | unsigned int hexStringToUInt(const std::wstring& s) |
| 30 | { |
| 31 | if(s.size() < 3) |
| 32 | return 0;//too short, parse error |
| 33 | else if(s.size() > 10) |
| 34 | return 0;//too long, parse error |
| 35 | |
| 36 | unsigned int i = 0; |
| 37 | unsigned int x = 0; |
| 38 | unsigned int nibble; |
| 39 | |
| 40 | //eat '0' |
| 41 | if(s[i++] != '0') |
| 42 | return 0;//parse error |
| 43 | |
| 44 | //eat 'x' |
| 45 | if(s[i++] != 'x') |
| 46 | return 0;//parse error |
| 47 | |
| 48 | while(i < s.size()) |
| 49 | { |
| 50 | if(s[i] >= '0' && s[i] <= '9') |
| 51 | nibble = s[i] - '0'; |
| 52 | else if(s[i] >= 'a' && s[i] <= 'f') |
| 53 | nibble = s[i] - 'a' + 10; |
| 54 | else if(s[i] >= 'A' && s[i] <= 'F') |
| 55 | nibble = s[i] - 'A' + 10; |
| 56 | else |
| 57 | return 0;//parse error |
| 58 | |
| 59 | x <<= 4; |
| 60 | x |= nibble;//set lower 4 bits to nibble |
| 61 | |
| 62 | i++; |
| 63 | } |
| 64 | |
| 65 | return x; |
| 66 | } |
| 67 | |
| 68 | unsigned long long hexStringTo64UInt(const std::wstring& s) |
| 69 | { |
nothing calls this directly
no outgoing calls
no test coverage detected