Remove readMultibyteTerminatedString*() functions

This commit is contained in:
Martchus 2019-06-04 19:10:52 +02:00
parent 6d2544b908
commit f95e16bc80
3 changed files with 0 additions and 120 deletions

View File

@ -165,114 +165,6 @@ string BinaryReader::readTerminatedString(std::size_t maxBytesToRead, std::uint8
return string(buff.get(), maxBytesToRead);
}
/*!
* \brief Reads a multibyte-terminated string from the current stream.
*
* Advances the current position of the stream by the string length plus two bytes.
*
* \param termination Specifies the two byte sized big endian value to be recognized as termination.
*
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringBE(std::uint16_t termination)
{
stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
ss.exceptions(ios_base::badbit | ios_base::failbit);
char *delimChars = m_buffer, *buff = m_buffer + 2;
ConversionUtilities::BE::getBytes(termination, delimChars);
m_stream->get(buff[0]);
m_stream->get(buff[1]);
while (!((buff[0] == delimChars[0]) && (buff[1] == delimChars[1]))) {
ss.put(buff[0]);
ss.put(buff[1]);
m_stream->get(buff[0]);
m_stream->get(buff[1]);
}
return ss.str();
}
/*!
* \brief Reads a multibyte-terminated string from the current stream.
*
* Advances the current position of the stream by the string length plus two bytes.
*
* \param termination Specifies the two byte sized little endian value to be recognized as termination.
*
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringLE(std::uint16_t termination)
{
stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
ss.exceptions(ios_base::badbit | ios_base::failbit);
char *delimChars = m_buffer, *buff = m_buffer + 2;
ConversionUtilities::LE::getBytes(termination, delimChars);
m_stream->get(buff[0]);
m_stream->get(buff[1]);
while (!((buff[0] == delimChars[0]) && (buff[1] == delimChars[1]))) {
ss.put(buff[0]);
ss.put(buff[1]);
m_stream->get(buff[0]);
m_stream->get(buff[1]);
}
return ss.str();
}
/*!
* \brief Reads a terminated string from the current stream.
*
* Advances the current position of the stream by the string length plus two bytes
* but maximal by \a maxBytesToRead.
*
* \param maxBytesToRead The maximal number of bytes to read.
* \param termination The two byte sized big endian value to be recognized as termination.
*
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, std::uint16_t termination)
{
unique_ptr<char[]> buff = make_unique<char[]>(maxBytesToRead);
char *delimChars = m_buffer;
ConversionUtilities::BE::getBytes(termination, delimChars);
for (char *i = buff.get(), *end = i + maxBytesToRead; (i + 1) < end; i += 2) {
m_stream->get(*i);
m_stream->get(*(i + 1));
if ((*i == delimChars[0]) && (*(i + 1) == delimChars[1])) {
return string(buff.get(), i - buff.get());
}
}
return string(buff.get(), maxBytesToRead);
}
/*!
* \brief Reads a terminated string from the current stream.
*
* Advances the current position of the stream by the string length plus two bytes
* but maximal by \a maxBytesToRead.
*
* \param maxBytesToRead The maximal number of bytes to read.
* \param termination The two byte sized little endian value to be recognized as termination.
*
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, std::uint16_t termination)
{
unique_ptr<char[]> buff = make_unique<char[]>(maxBytesToRead);
char *delimChars = m_buffer;
ConversionUtilities::LE::getBytes(termination, delimChars);
for (char *i = buff.get(), *end = i + maxBytesToRead; (i + 1) < end; i += 2) {
m_stream->get(*i);
m_stream->get(*(i + 1));
if ((*i == delimChars[0]) && (*(i + 1) == delimChars[1])) {
return string(buff.get(), i - buff.get());
}
}
return string(buff.get(), maxBytesToRead);
}
/*!
* \brief Reads \a length bytes from the stream and computes the CRC-32 for that block of data.
*

View File

@ -66,10 +66,6 @@ public:
std::string readString(std::size_t length);
std::string readTerminatedString(std::uint8_t termination = 0);
std::string readTerminatedString(std::size_t maxBytesToRead, std::uint8_t termination = 0);
std::string readMultibyteTerminatedStringBE(std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringLE(std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, std::uint16_t termination = 0);
std::uint32_t readSynchsafeUInt32BE();
float readFixed8BE();
float readFixed16BE();

View File

@ -135,14 +135,6 @@ void IoTests::testBinaryReader()
CPPUNIT_ASSERT_EQUAL("def"s, reader.readTerminatedString());
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("def"s, reader.readTerminatedString(5, 0));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(5, 0x6600));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(5, 0x0066));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(static_cast<std::uint16_t>(0x6600)));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(static_cast<std::uint16_t>(0x0066)));
CPPUNIT_ASSERT_THROW(reader.readLengthPrefixedString(), ConversionException);
CPPUNIT_ASSERT_MESSAGE("pos in stream not advanced on conversion error", reader.readByte() == 0);