MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / util_ConvertHex

Function util_ConvertHex

src/twparser/parserhelper.cpp:874–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

872//=========================================================================
873
874int util_ConvertHex(const char* const cpsz, int* const pnCharsRead)
875{
876 ASSERT(util_AsciiCharsActLikeTheyShould());
877 ASSERT(cpsz && pnCharsRead);
878
879 if (*cpsz == 0 || !std::isxdigit<TCHAR>(*cpsz, std::locale()))
880 throw eParserBadHex(cStringUtil::StrToTstr(cpsz));
881
882 int iValue;
883 const char* psz = cpsz;
884 for (*pnCharsRead = 0, iValue = 0; *psz && std::isxdigit<TCHAR>(*psz, std::locale()) && (*pnCharsRead < 2);
885 psz++, (*pnCharsRead)++)
886 {
887 iValue *= 0x10;
888
889 if (std::isdigit<TCHAR>(*psz, std::locale()))
890 {
891 iValue += (*psz - '0');
892 }
893 else
894 {
895 if (std::islower<TCHAR>(*psz, std::locale()))
896 iValue += (*psz - 'a' + 10); // so that A=10, B=11, ..., F=15
897 else // is uppercase
898 iValue += (*psz - 'A' + 10); // so that a=10, a=11, ..., f=15
899 }
900 }
901
902 return iValue;
903}
904
905int util_ConvertUnicode(const char* const cpsz, int* const pnCharsRead)
906{

Callers 1

Calls 1

Tested by

no test coverage detected