|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#ifndef HELPER_FUNCTIONS_HPP
|
|
|
|
#define HELPER_FUNCTIONS_HPP
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "basicio.hpp"
|
|
|
|
#include "types.hpp"
|
|
|
|
/*!
|
|
|
|
@brief Convert a (potentially not null terminated) array into a
|
|
|
|
std::string.
|
|
|
|
|
|
|
|
Convert a C style string that may or may not be null terminated safely
|
|
|
|
into a std::string. The string's termination is either set at the first \0
|
|
|
|
or after data_length characters.
|
|
|
|
|
|
|
|
@param[in] data A c-string from which the std::string shall be
|
|
|
|
constructed. Does not need to be null terminated.
|
|
|
|
@param[in] data_length An upper bound for the string length (must be at most
|
|
|
|
the allocated length of `buffer`). If no null terminator is found in data,
|
|
|
|
then the resulting std::string will be null terminated at `data_length`.
|
|
|
|
|
|
|
|
*/
|
|
|
|
std::string string_from_unterminated(const char* data, size_t data_length);
|
|
|
|
|
|
|
|
namespace Exiv2 {
|
|
|
|
|
|
|
|
static constexpr size_t BYTE = 0x1;
|
|
|
|
static constexpr size_t WCHAR = 0x2;
|
|
|
|
static constexpr size_t WORD = 0X2;
|
|
|
|
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(Exiv2::BasicIo::UniquePtr& io);
|
|
|
|
|
|
|
|
[[nodiscard]] uint32_t readDWORDTag(Exiv2::BasicIo::UniquePtr& io);
|
|
|
|
|
|
|
|
[[nodiscard]] uint16_t readWORDTag(Exiv2::BasicIo::UniquePtr& io);
|
|
|
|
|
|
|
|
[[nodiscard]] std::string readStringWcharTag(Exiv2::BasicIo::UniquePtr& io, size_t length);
|
|
|
|
|
|
|
|
[[nodiscard]] std::string readStringTag(Exiv2::BasicIo::UniquePtr& io, size_t length = DWORD);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@brief Calculates Aspect Ratio of a video
|
|
|
|
*/
|
|
|
|
[[nodiscard]] std::string getAspectRatio(size_t width, size_t height);
|
|
|
|
|
|
|
|
} // namespace Exiv2
|
|
|
|
#endif // HELPER_FUNCTIONS_HPP
|