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

Function util_ConvertUnicode

src/twparser/parserhelper.cpp:905–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903}
904
905int util_ConvertUnicode(const char* const cpsz, int* const pnCharsRead)
906{
907 ASSERT(util_AsciiCharsActLikeTheyShould());
908 ASSERT(cpsz && pnCharsRead);
909
910 if (*cpsz == 0 || !std::isxdigit<TCHAR>(*cpsz, std::locale()))
911 throw eParserBadHex(cStringUtil::StrToTstr(cpsz));
912
913 int iValue;
914 const char* psz = cpsz;
915 for (*pnCharsRead = 0, iValue = 0; *pnCharsRead < 4; psz++, (*pnCharsRead)++)
916 {
917 // we require 4 chars for unicode escapes
918 if (*psz == 0 || !std::isxdigit<TCHAR>(*psz, std::locale()))
919 throw eParserBadHex(cStringUtil::StrToTstr(cpsz));
920
921 iValue *= 0x10;
922
923 if (std::isdigit<TCHAR>(*psz, std::locale()))
924 {
925 iValue += (*psz - '0');
926 }
927 else
928 {
929 if (std::islower<TCHAR>(*psz, std::locale()))
930 iValue += (*psz - 'a' + 10); // so that A=10, B=11, ..., F=15
931 else // is uppercase
932 iValue += (*psz - 'A' + 10); // so that a=10, a=11, ..., f=15
933 }
934 }
935
936 return iValue;
937}
938
939// only 3 octal chars allowed
940int util_ConvertOctal(const char* psz, int* const pnCharsRead)

Callers 1

Calls 1

Tested by

no test coverage detected