add test/data for video support : rework readStringWcharTag method
This commit is contained in:
parent
e388ba523f
commit
579cae8e77
@ -3,7 +3,9 @@
|
||||
#include "helper_functions.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <codecvt>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
#include "enforce.hpp"
|
||||
|
||||
std::string string_from_unterminated(const char* data, size_t data_length) {
|
||||
@ -21,20 +23,13 @@ char returnHex(int n) {
|
||||
return static_cast<char>(n + 55);
|
||||
}
|
||||
|
||||
std::string toString16(Exiv2::DataBuf& buf) {
|
||||
std::ostringstream os;
|
||||
char t;
|
||||
std::string utf16ToUtf8(const std::wstring& wstr) {
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||
|
||||
for (size_t i = 0; i < buf.size(); i += 2) {
|
||||
t = buf.data()[i] + 16 * buf.data()[i + 1];
|
||||
if (t == 0) {
|
||||
if (i)
|
||||
os << '\0';
|
||||
break;
|
||||
}
|
||||
os << t;
|
||||
}
|
||||
return os.str();
|
||||
std::string str = converterX.to_bytes(wstr);
|
||||
str.erase(std::remove(str.begin(), str.end(), NULL), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
uint64_t readQWORDTag(BasicIo::UniquePtr& io) {
|
||||
@ -57,8 +52,10 @@ uint16_t readWORDTag(BasicIo::UniquePtr& io) {
|
||||
|
||||
std::string readStringWcharTag(BasicIo::UniquePtr& io, size_t length) {
|
||||
Internal::enforce(length <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||
DataBuf FieldBuf = io->read(length);
|
||||
return toString16(FieldBuf);
|
||||
DataBuf FieldBuf(length + 1);
|
||||
io->readOrThrow(FieldBuf.data(), length, ErrorCode::kerFailedToReadImageData);
|
||||
std::wstring wst(FieldBuf.begin(), FieldBuf.end());
|
||||
return utf16ToUtf8(wst);
|
||||
}
|
||||
|
||||
std::string readStringTag(BasicIo::UniquePtr& io, size_t length) {
|
||||
|
||||
@ -32,13 +32,6 @@ namespace Exiv2 {
|
||||
*/
|
||||
char returnHex(int n);
|
||||
|
||||
/*!
|
||||
@brief Function used to read data from data buffer, reads 16-bit character
|
||||
array and stores it in std::string object.
|
||||
@param buf Exiv2 data buffer, which stores the information
|
||||
@return Returns std::string object .
|
||||
*/
|
||||
|
||||
static constexpr size_t BYTE = 0x1;
|
||||
static constexpr size_t WCHAR = 0x2;
|
||||
static constexpr size_t WORD = 0X2;
|
||||
@ -46,7 +39,16 @@ static constexpr size_t DWORD = 0x4;
|
||||
static constexpr size_t QWORD = 0x8;
|
||||
static constexpr size_t GUID = 0x10;
|
||||
|
||||
std::string toString16(Exiv2::DataBuf& buf);
|
||||
// @brief
|
||||
|
||||
/*!
|
||||
@brief The function utf16ToUtf8 takes a wide string wstr as input and converts it to a narrow string
|
||||
The conversion is performed using the std::wstring_convert class template and a std::codecvt_utf8 facet, which
|
||||
implements conversion between UTF-8 and wide characters.
|
||||
@param wstr : wide string
|
||||
@return Returns std::string object
|
||||
*/
|
||||
std::string utf16ToUtf8(const std::wstring& wstr);
|
||||
|
||||
[[nodiscard]] uint64_t readQWORDTag(Exiv2::BasicIo::UniquePtr& io);
|
||||
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user