ByteString CPDF_StreamParser::ReadHexString() { if (!PositionIsInBounds()) return ByteString(); std::ostringstream buf; bool bFirst = true; int code = 0; while (PositionIsInBounds()) { int ch = m_pBuf[m_Pos++]; if (ch == '>') break; if (!std::isxdigit(ch)) continue; int val = FXSYS_HexCharToInt(ch); if (bFirst) { code = val * 16; } else { code += val; buf << static_cast<uint8_t>(code); } bFirst = !bFirst; } if (!bFirst) buf << static_cast<char>(code); if (buf.tellp() <= 0) return ByteString(); return ByteString( buf.str().c_str(), std::min(static_cast<size_t>(buf.tellp()), kMaxStringLength)); }
TEST(fxcrt, FXSYS_HexCharToInt) { EXPECT_EQ(10, FXSYS_HexCharToInt('a')); EXPECT_EQ(10, FXSYS_HexCharToInt('A')); EXPECT_EQ(7, FXSYS_HexCharToInt('7')); EXPECT_EQ(0, FXSYS_HexCharToInt('i')); }