remove codecvt
Deprecated in C++17 Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
2e33dad1d1
commit
0fa22ed55d
@ -3,9 +3,7 @@
|
||||
#include "helper_functions.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <codecvt>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
#include <numeric>
|
||||
#include "enforce.hpp"
|
||||
|
||||
@ -17,17 +15,22 @@ std::string string_from_unterminated(const char* data, size_t data_length) {
|
||||
return {data, StringLength};
|
||||
}
|
||||
|
||||
namespace Exiv2 {
|
||||
|
||||
std::string utf16ToUtf8(const std::wstring& wstr) {
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX;
|
||||
|
||||
std::string str = converterX.to_bytes(wstr);
|
||||
namespace {
|
||||
std::string utf16ToUtf8(const std::u16string& wstr) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
auto str = std::string(wstr.begin(), wstr.end());
|
||||
#pragma warning(pop)
|
||||
#else
|
||||
auto str = std::string(wstr.begin(), wstr.end());
|
||||
#endif
|
||||
str.erase(std::remove(str.begin(), str.end(), '\0'), str.end());
|
||||
return str;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace Exiv2 {
|
||||
uint64_t readQWORDTag(const BasicIo::UniquePtr& io) {
|
||||
Internal::enforce(QWORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||
DataBuf FieldBuf = io->read(QWORD);
|
||||
@ -50,7 +53,7 @@ std::string readStringWcharTag(const BasicIo::UniquePtr& io, size_t length) {
|
||||
Internal::enforce(length <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||
DataBuf FieldBuf(length + 1);
|
||||
io->readOrThrow(FieldBuf.data(), length, ErrorCode::kerFailedToReadImageData);
|
||||
std::wstring wst(FieldBuf.begin(), FieldBuf.end());
|
||||
std::u16string wst(FieldBuf.begin(), FieldBuf.end());
|
||||
return utf16ToUtf8(wst);
|
||||
}
|
||||
|
||||
|
||||
@ -32,17 +32,6 @@ static constexpr size_t DWORD = 0x4;
|
||||
static constexpr size_t QWORD = 0x8;
|
||||
static constexpr size_t GUID = 0x10;
|
||||
|
||||
// @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(const Exiv2::BasicIo::UniquePtr& io);
|
||||
|
||||
[[nodiscard]] uint32_t readDWORDTag(const Exiv2::BasicIo::UniquePtr& io);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user