From f95e16bc80ba36d660da2004161f28198f78bcd3 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 4 Jun 2019 19:10:52 +0200 Subject: [PATCH] Remove readMultibyteTerminatedString*() functions --- io/binaryreader.cpp | 108 -------------------------------------------- io/binaryreader.h | 4 -- tests/iotests.cpp | 8 ---- 3 files changed, 120 deletions(-) diff --git a/io/binaryreader.cpp b/io/binaryreader.cpp index 16afb30..be8aff0 100644 --- a/io/binaryreader.cpp +++ b/io/binaryreader.cpp @@ -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 buff = make_unique(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 buff = make_unique(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. * diff --git a/io/binaryreader.h b/io/binaryreader.h index 7c426a5..830fa19 100644 --- a/io/binaryreader.h +++ b/io/binaryreader.h @@ -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(); diff --git a/tests/iotests.cpp b/tests/iotests.cpp index 9b5d829..f1cf3db 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -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(0x6600))); - testFile.seekg(-4, ios_base::cur); - CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(static_cast(0x0066))); CPPUNIT_ASSERT_THROW(reader.readLengthPrefixedString(), ConversionException); CPPUNIT_ASSERT_MESSAGE("pos in stream not advanced on conversion error", reader.readByte() == 0);