Use std::string_view where it makes sense

This commit is contained in:
Martchus 2021-01-30 21:53:06 +01:00
parent 49154905b1
commit 64d98f5530
60 changed files with 512 additions and 498 deletions

View File

@ -100,7 +100,7 @@ void StreamDataBlock::copyTo(ostream &stream) const
* *
* \throws Throws ios_base::failure when an IO error occurs. * \throws Throws ios_base::failure when an IO error occurs.
*/ */
FileDataBlock::FileDataBlock(const string &path, Diagnostics &diag) FileDataBlock::FileDataBlock(std::string_view path, Diagnostics &diag)
: m_fileInfo(make_unique<MediaFileInfo>()) : m_fileInfo(make_unique<MediaFileInfo>())
{ {
m_fileInfo->setPath(path); m_fileInfo->setPath(path);
@ -167,7 +167,7 @@ void AbstractAttachment::clear()
* *
* When such an exception is thrown, the attachment remains unchanged. * When such an exception is thrown, the attachment remains unchanged.
*/ */
void AbstractAttachment::setFile(const std::string &path, Diagnostics &diag) void AbstractAttachment::setFile(string_view path, Diagnostics &diag)
{ {
m_data.reset(); m_data.reset();
auto file = make_unique<FileDataBlock>(path, diag); auto file = make_unique<FileDataBlock>(path, diag);
@ -175,8 +175,8 @@ void AbstractAttachment::setFile(const std::string &path, Diagnostics &diag)
if (!fileName.empty()) { if (!fileName.empty()) {
m_name = fileName; m_name = fileName;
} }
const char *mimeType = file->fileInfo()->mimeType(); const auto mimeType = file->fileInfo()->mimeType();
if (*mimeType) { if (!mimeType.empty()) {
m_mimeType = mimeType; m_mimeType = mimeType;
} }
m_data = move(file); m_data = move(file);

View File

@ -89,7 +89,7 @@ inline void StreamDataBlock::discardBuffer()
class TAG_PARSER_EXPORT FileDataBlock : public StreamDataBlock { class TAG_PARSER_EXPORT FileDataBlock : public StreamDataBlock {
public: public:
FileDataBlock(const std::string &path, Diagnostics &diag); FileDataBlock(std::string_view path, Diagnostics &diag);
~FileDataBlock(); ~FileDataBlock();
const MediaFileInfo *fileInfo() const; const MediaFileInfo *fileInfo() const;
@ -105,16 +105,16 @@ inline const MediaFileInfo *FileDataBlock::fileInfo() const
class TAG_PARSER_EXPORT AbstractAttachment { class TAG_PARSER_EXPORT AbstractAttachment {
public: public:
const std::string &description() const; const std::string &description() const;
void setDescription(const std::string &description); void setDescription(std::string_view description);
const std::string &name() const; const std::string &name() const;
void setName(const std::string &name); void setName(std::string_view name);
const std::string &mimeType() const; const std::string &mimeType() const;
void setMimeType(const std::string &mimeType); void setMimeType(std::string_view mimeType);
std::uint64_t id() const; std::uint64_t id() const;
void setId(const std::uint64_t &id); void setId(std::uint64_t id);
const StreamDataBlock *data() const; const StreamDataBlock *data() const;
void setData(std::unique_ptr<StreamDataBlock> &&data); void setData(std::unique_ptr<StreamDataBlock> &&data);
void setFile(const std::string &path, Diagnostics &diag); void setFile(std::string_view path, Diagnostics &diag);
bool isDataFromFile() const; bool isDataFromFile() const;
std::string label() const; std::string label() const;
void clear(); void clear();
@ -156,7 +156,7 @@ inline const std::string &AbstractAttachment::description() const
/*! /*!
* \brief Sets a description of the attachment. * \brief Sets a description of the attachment.
*/ */
inline void AbstractAttachment::setDescription(const std::string &description) inline void AbstractAttachment::setDescription(std::string_view description)
{ {
m_description = description; m_description = description;
} }
@ -172,7 +172,7 @@ inline const std::string &AbstractAttachment::name() const
/*! /*!
* \brief Sets the (file) name of the attachment. * \brief Sets the (file) name of the attachment.
*/ */
inline void AbstractAttachment::setName(const std::string &name) inline void AbstractAttachment::setName(std::string_view name)
{ {
m_name = name; m_name = name;
} }
@ -188,7 +188,7 @@ inline const std::string &AbstractAttachment::mimeType() const
/*! /*!
* \brief Sets the MIME-type of the attachment. * \brief Sets the MIME-type of the attachment.
*/ */
inline void AbstractAttachment::setMimeType(const std::string &mimeType) inline void AbstractAttachment::setMimeType(std::string_view mimeType)
{ {
m_mimeType = mimeType; m_mimeType = mimeType;
} }
@ -204,7 +204,7 @@ inline std::uint64_t AbstractAttachment::id() const
/*! /*!
* \brief Sets the ID of the attachment. * \brief Sets the ID of the attachment.
*/ */
inline void AbstractAttachment::setId(const std::uint64_t &id) inline void AbstractAttachment::setId(uint64_t id)
{ {
m_id = id; m_id = id;
} }

View File

@ -76,7 +76,7 @@ public:
std::uint64_t doctypeVersion() const; std::uint64_t doctypeVersion() const;
std::uint64_t doctypeReadVersion() const; std::uint64_t doctypeReadVersion() const;
const std::vector<std::string> &titles() const; const std::vector<std::string> &titles() const;
void setTitle(const std::string &title, std::size_t segmentIndex = 0); void setTitle(std::string_view title, std::size_t segmentIndex = 0);
virtual bool supportsTitle() const; virtual bool supportsTitle() const;
virtual std::size_t segmentCount() const; virtual std::size_t segmentCount() const;
CppUtilities::TimeSpan duration() const; CppUtilities::TimeSpan duration() const;
@ -265,7 +265,7 @@ inline const std::vector<std::string> &AbstractContainer::titles() const
* \throws Throws out_of_range if the segment does not exist. * \throws Throws out_of_range if the segment does not exist.
* \sa titles() * \sa titles()
*/ */
inline void AbstractContainer::setTitle(const std::string &title, std::size_t segmentIndex) inline void AbstractContainer::setTitle(std::string_view title, std::size_t segmentIndex)
{ {
m_titles.at(segmentIndex) = title; m_titles.at(segmentIndex) = title;
} }

View File

@ -53,7 +53,6 @@ AbstractTrack::AbstractTrack(istream &inputStream, ostream &outputStream, std::u
, m_quality(0) , m_quality(0)
, m_depth(0) , m_depth(0)
, m_fps(0) , m_fps(0)
, m_chromaFormat(nullptr)
, m_timeScale(0) , m_timeScale(0)
, m_colorSpace(0) , m_colorSpace(0)
{ {
@ -81,16 +80,16 @@ AbstractTrack::~AbstractTrack()
/*! /*!
* \brief Returns a string with the channel configuration if available; otherwise returns nullptr. * \brief Returns a string with the channel configuration if available; otherwise returns nullptr.
*/ */
const char *AbstractTrack::channelConfigString() const std::string_view AbstractTrack::channelConfigString() const
{ {
switch (m_format.general) { switch (m_format.general) {
case GeneralMediaFormat::Aac: case GeneralMediaFormat::Aac:
return m_channelConfig ? Mpeg4ChannelConfigs::channelConfigString(m_channelConfig) : nullptr; return m_channelConfig ? Mpeg4ChannelConfigs::channelConfigString(m_channelConfig) : std::string_view();
case GeneralMediaFormat::Mpeg1Audio: case GeneralMediaFormat::Mpeg1Audio:
case GeneralMediaFormat::Mpeg2Audio: case GeneralMediaFormat::Mpeg2Audio:
return mpegChannelModeString(static_cast<MpegChannelMode>(m_channelConfig)); return mpegChannelModeString(static_cast<MpegChannelMode>(m_channelConfig));
default: default:
return nullptr; return std::string_view();
} }
} }
@ -105,13 +104,13 @@ std::uint8_t AbstractTrack::extensionChannelConfig() const
/*! /*!
* \brief Returns a string with the extension channel configuration if available; otherwise returns nullptr. * \brief Returns a string with the extension channel configuration if available; otherwise returns nullptr.
*/ */
const char *AbstractTrack::extensionChannelConfigString() const std::string_view AbstractTrack::extensionChannelConfigString() const
{ {
switch (m_format.general) { switch (m_format.general) {
case GeneralMediaFormat::Aac: case GeneralMediaFormat::Aac:
return m_extensionChannelConfig ? Mpeg4ChannelConfigs::channelConfigString(m_extensionChannelConfig) : nullptr; return m_extensionChannelConfig ? Mpeg4ChannelConfigs::channelConfigString(m_extensionChannelConfig) : std::string_view();
default: default:
return nullptr; return std::string_view();
} }
} }
@ -140,15 +139,15 @@ string AbstractTrack::makeDescription(bool verbose) const
{ {
// use abbreviated format // use abbreviated format
const auto format = MediaFormat(m_format.general, verbose ? m_format.sub : 0, verbose ? m_format.extension : 0); const auto format = MediaFormat(m_format.general, verbose ? m_format.sub : 0, verbose ? m_format.extension : 0);
const char *formatName = format.shortAbbreviation(); auto formatName = format.shortAbbreviation();
if (!formatName || !*formatName) { if (formatName.empty()) {
// fall back to media type name if no abbreviation available // fall back to media type name if no abbreviation available
formatName = mediaTypeName(); formatName = mediaTypeName();
} }
// find additional info and level // find additional info and level
const char *additionalInfoRef = nullptr; auto additionalInfoRef = std::string_view();
string level; auto level = std::string();
switch (m_mediaType) { switch (m_mediaType) {
case MediaType::Video: case MediaType::Video:
if (!displaySize().isNull()) { if (!displaySize().isNull()) {
@ -178,13 +177,13 @@ string AbstractTrack::makeDescription(bool verbose) const
return argsToString(formatName, '-', channelCount(), 'c', 'h'); return argsToString(formatName, '-', channelCount(), 'c', 'h');
} }
} else if (const auto &localeName = locale().someAbbreviatedName(); !localeName.empty()) { } else if (const auto &localeName = locale().someAbbreviatedName(); !localeName.empty()) {
additionalInfoRef = localeName.data(); additionalInfoRef = localeName;
} }
break; break;
default:; default:;
} }
if (additionalInfoRef) { if (!additionalInfoRef.empty()) {
return argsToString(formatName, level, '-', additionalInfoRef); return argsToString(formatName, level, '-', additionalInfoRef);
} }
return argsToString(formatName, level); return argsToString(formatName, level);

View File

@ -16,6 +16,7 @@
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -79,18 +80,18 @@ public:
TrackFlags flags() const; TrackFlags flags() const;
MediaFormat format() const; MediaFormat format() const;
double version() const; double version() const;
const char *formatName() const; std::string_view formatName() const;
const char *formatAbbreviation() const; std::string_view formatAbbreviation() const;
const std::string &formatId() const; const std::string &formatId() const;
MediaType mediaType() const; MediaType mediaType() const;
const char *mediaTypeName() const; std::string_view mediaTypeName() const;
std::uint64_t size() const; std::uint64_t size() const;
std::uint32_t trackNumber() const; std::uint32_t trackNumber() const;
void setTrackNumber(std::uint32_t trackNumber); void setTrackNumber(std::uint32_t trackNumber);
std::uint64_t id() const; std::uint64_t id() const;
void setId(std::uint64_t id); void setId(std::uint64_t id);
const std::string name() const; const std::string name() const;
void setName(const std::string &name); void setName(std::string_view name);
const CppUtilities::TimeSpan &duration() const; const CppUtilities::TimeSpan &duration() const;
double bitrate() const; double bitrate() const;
double maxBitrate() const; double maxBitrate() const;
@ -103,19 +104,19 @@ public:
std::uint16_t bitsPerSample() const; std::uint16_t bitsPerSample() const;
std::uint16_t channelCount() const; std::uint16_t channelCount() const;
std::uint8_t channelConfig() const; std::uint8_t channelConfig() const;
const char *channelConfigString() const; std::string_view channelConfigString() const;
std::uint8_t extensionChannelConfig() const; std::uint8_t extensionChannelConfig() const;
const char *extensionChannelConfigString() const; std::string_view extensionChannelConfigString() const;
std::uint64_t sampleCount() const; std::uint64_t sampleCount() const;
int quality() const; int quality() const;
const Size &pixelSize() const; const Size &pixelSize() const;
const Size &displaySize() const; const Size &displaySize() const;
const Size &resolution() const; const Size &resolution() const;
const std::string &compressorName() const; const std::string &compressorName() const;
void setCompressorName(const std::string &compressorName); void setCompressorName(std::string_view compressorName);
std::uint16_t depth() const; std::uint16_t depth() const;
std::uint32_t fps() const; std::uint32_t fps() const;
const char *chromaFormat() const; std::string_view chromaFormat() const;
const AspectRatio &pixelAspectRatio() const; const AspectRatio &pixelAspectRatio() const;
bool isInterlaced() const; bool isInterlaced() const;
std::uint32_t timeScale() const; std::uint32_t timeScale() const;
@ -178,7 +179,7 @@ protected:
std::string m_compressorName; std::string m_compressorName;
std::uint16_t m_depth; std::uint16_t m_depth;
std::uint32_t m_fps; std::uint32_t m_fps;
const char *m_chromaFormat; std::string_view m_chromaFormat;
AspectRatio m_pixelAspectRatio; AspectRatio m_pixelAspectRatio;
std::uint32_t m_timeScale; std::uint32_t m_timeScale;
std::uint32_t m_colorSpace; std::uint32_t m_colorSpace;
@ -293,22 +294,21 @@ inline double AbstractTrack::version() const
* \brief Returns the format of the track as C-style string if known; otherwise * \brief Returns the format of the track as C-style string if known; otherwise
* returns the format abbreviation or an empty string. * returns the format abbreviation or an empty string.
* \remarks * \remarks
* - The caller must not free the returned string.
* - The string might get invalidated when the track is (re)parsed. * - The string might get invalidated when the track is (re)parsed.
*/ */
inline const char *AbstractTrack::formatName() const inline std::string_view AbstractTrack::formatName() const
{ {
return m_format || m_formatName.empty() ? m_format.name() : m_formatName.c_str(); return m_format || m_formatName.empty() ? m_format.name() : m_formatName;
} }
/*! /*!
* \brief Returns the a more or less common abbreviation for the format of the track * \brief Returns the a more or less common abbreviation for the format of the track
* as C-style string if known; otherwise returns an empty string. * if known; otherwise returns an empty string.
*/ */
inline const char *AbstractTrack::formatAbbreviation() const inline std::string_view AbstractTrack::formatAbbreviation() const
{ {
const char *abbr = m_format.abbreviation(); const auto abbr = m_format.abbreviation();
return *abbr || m_formatId.empty() ? m_format.abbreviation() : m_formatId.c_str(); return !abbr.empty() || m_formatId.empty() ? abbr : m_formatId;
} }
/*! /*!
@ -331,7 +331,7 @@ inline MediaType AbstractTrack::mediaType() const
/*! /*!
* \brief Returns the string representation of the media type of the track. * \brief Returns the string representation of the media type of the track.
*/ */
inline const char *AbstractTrack::mediaTypeName() const inline std::string_view AbstractTrack::mediaTypeName() const
{ {
return ::TagParser::mediaTypeName(m_mediaType); return ::TagParser::mediaTypeName(m_mediaType);
} }
@ -390,7 +390,7 @@ inline const std::string AbstractTrack::name() const
* \brief Sets the name. * \brief Sets the name.
* \remarks Whether the new value is applied when saving changes depends on the implementation. * \remarks Whether the new value is applied when saving changes depends on the implementation.
*/ */
inline void AbstractTrack::setName(const std::string &name) inline void AbstractTrack::setName(std::string_view name)
{ {
m_name = name; m_name = name;
} }
@ -560,7 +560,7 @@ inline const std::string &AbstractTrack::compressorName() const
* \brief Returns the compressor name if known; otherwise returns an empty string. * \brief Returns the compressor name if known; otherwise returns an empty string.
* \remarks Whether the new value is applied when saving changes depends on the implementation. * \remarks Whether the new value is applied when saving changes depends on the implementation.
*/ */
inline void AbstractTrack::setCompressorName(const std::string &compressorName) inline void AbstractTrack::setCompressorName(std::string_view compressorName)
{ {
m_compressorName = compressorName; m_compressorName = compressorName;
} }
@ -588,7 +588,7 @@ inline std::uint32_t AbstractTrack::fps() const
* *
* This value only makes sense for video tracks. * This value only makes sense for video tracks.
*/ */
inline const char *AbstractTrack::chromaFormat() const inline std::string_view AbstractTrack::chromaFormat() const
{ {
return m_chromaFormat; return m_chromaFormat;
} }

View File

@ -68,7 +68,7 @@ void restoreOriginalFileFromBackupFile(
} }
// remove original file and restore backup // remove original file and restore backup
std::remove(originalPath.c_str()); std::remove(originalPath.c_str());
if (std::rename(BasicFileInfo::pathForOpen(backupPath), BasicFileInfo::pathForOpen(originalPath)) == 0) { if (std::rename(BasicFileInfo::pathForOpen(backupPath).data(), BasicFileInfo::pathForOpen(originalPath).data()) == 0) {
return; return;
} }
// can't rename/move the file (maybe backup dir on another partition) -> make a copy instead // can't rename/move the file (maybe backup dir on another partition) -> make a copy instead
@ -154,10 +154,10 @@ void createBackupFile(const std::string &backupDir, const std::string &originalP
// test whether the backup path is still unused; otherwise continue loop // test whether the backup path is still unused; otherwise continue loop
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
if (GetFileAttributes(BasicFileInfo::pathForOpen(backupPath)) == INVALID_FILE_ATTRIBUTES) { if (GetFileAttributes(BasicFileInfo::pathForOpen(backupPath).data()) == INVALID_FILE_ATTRIBUTES) {
#else #else
struct stat backupStat; struct stat backupStat;
if (stat(BasicFileInfo::pathForOpen(backupPath), &backupStat)) { if (stat(BasicFileInfo::pathForOpen(backupPath).data(), &backupStat)) {
#endif #endif
break; break;
} }
@ -169,7 +169,7 @@ void createBackupFile(const std::string &backupDir, const std::string &originalP
} }
// rename original file // rename original file
if (std::rename(BasicFileInfo::pathForOpen(originalPath), BasicFileInfo::pathForOpen(backupPath))) { if (std::rename(BasicFileInfo::pathForOpen(originalPath).data(), BasicFileInfo::pathForOpen(backupPath).data())) {
// can't rename/move the file (maybe backup dir on another partition) -> make a copy instead // can't rename/move the file (maybe backup dir on another partition) -> make a copy instead
try { try {
backupStream.exceptions(ios_base::failbit | ios_base::badbit); backupStream.exceptions(ios_base::failbit | ios_base::badbit);
@ -178,9 +178,9 @@ void createBackupFile(const std::string &backupDir, const std::string &originalP
if (backupStream.is_open()) { if (backupStream.is_open()) {
backupStream.close(); backupStream.close();
} }
backupStream.open(BasicFileInfo::pathForOpen(backupPath), ios_base::out | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(backupPath).data(), ios_base::out | ios_base::binary);
// ensure originalStream is opened with read permissions // ensure originalStream is opened with read permissions
originalStream.open(BasicFileInfo::pathForOpen(originalPath), ios_base::in | ios_base::binary); originalStream.open(BasicFileInfo::pathForOpen(originalPath).data(), ios_base::in | ios_base::binary);
// do the actual copying // do the actual copying
backupStream << originalStream.rdbuf(); backupStream << originalStream.rdbuf();
backupStream.flush(); backupStream.flush();
@ -203,11 +203,11 @@ void createBackupFile(const std::string &backupDir, const std::string &originalP
} }
// open backup stream // open backup stream
backupStream.exceptions(ios_base::failbit | ios_base::badbit); backupStream.exceptions(ios_base::failbit | ios_base::badbit);
backupStream.open(BasicFileInfo::pathForOpen(backupPath), ios_base::in | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(backupPath).data(), ios_base::in | ios_base::binary);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
// can't open the new file // can't open the new file
// -> try to re-rename backup file in the error case to restore previous state // -> try to re-rename backup file in the error case to restore previous state
if (std::rename(BasicFileInfo::pathForOpen(backupPath), BasicFileInfo::pathForOpen(originalPath))) { if (std::rename(BasicFileInfo::pathForOpen(backupPath).data(), BasicFileInfo::pathForOpen(originalPath).data())) {
throw std::ios_base::failure("Unable to restore original file from backup file \"" % backupPath % "\" after failure: " + failure.what()); throw std::ios_base::failure("Unable to restore original file from backup file \"" % backupPath % "\" after failure: " + failure.what());
} else { } else {
throw std::ios_base::failure(argsToString("Unable to open backup file: ", failure.what())); throw std::ios_base::failure(argsToString("Unable to open backup file: ", failure.what()));

View File

@ -20,7 +20,7 @@ namespace TagParser {
* *
* \param path Specifies the absolute or relative path of the file. * \param path Specifies the absolute or relative path of the file.
*/ */
BasicFileInfo::BasicFileInfo(const std::string &path) BasicFileInfo::BasicFileInfo(std::string_view path)
: m_path(path) : m_path(path)
, m_size(0) , m_size(0)
, m_readOnly(false) , m_readOnly(false)
@ -59,7 +59,8 @@ void BasicFileInfo::open(bool readOnly)
void BasicFileInfo::reopen(bool readOnly) void BasicFileInfo::reopen(bool readOnly)
{ {
invalidated(); invalidated();
m_file.open(pathForOpen(path()), (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary); m_file.open(
pathForOpen(path()).data(), (m_readOnly = readOnly) ? ios_base::in | ios_base::binary : ios_base::in | ios_base::out | ios_base::binary);
m_file.seekg(0, ios_base::end); m_file.seekg(0, ios_base::end);
m_size = static_cast<std::uint64_t>(m_file.tellg()); m_size = static_cast<std::uint64_t>(m_file.tellg());
m_file.seekg(0, ios_base::beg); m_file.seekg(0, ios_base::beg);
@ -91,7 +92,7 @@ void BasicFileInfo::invalidate()
* *
* \param path Specifies the absolute or relative path of the file to be set. * \param path Specifies the absolute or relative path of the file to be set.
*/ */
void BasicFileInfo::setPath(const string &path) void BasicFileInfo::setPath(std::string_view path)
{ {
if (path != m_path) { if (path != m_path) {
invalidated(); invalidated();
@ -138,13 +139,13 @@ string BasicFileInfo::fileName(bool cutExtension) const
* *
* \param path Specifies the path of the file. * \param path Specifies the path of the file.
*/ */
string BasicFileInfo::extension(const string &path) std::string BasicFileInfo::extension(std::string_view path)
{ {
size_t lastPoint = path.rfind('.'); std::size_t lastPoint = path.rfind('.');
if (lastPoint == string::npos) { if (lastPoint == std::string::npos) {
return string(); return std::string();
} else { } else {
return path.substr(lastPoint); return std::string(path.data() + lastPoint, path.size() - lastPoint);
} }
} }

View File

@ -14,7 +14,7 @@ namespace TagParser {
class TAG_PARSER_EXPORT BasicFileInfo { class TAG_PARSER_EXPORT BasicFileInfo {
public: public:
// constructor, destructor // constructor, destructor
explicit BasicFileInfo(const std::string &path = std::string()); explicit BasicFileInfo(std::string_view path = std::string_view());
BasicFileInfo(const BasicFileInfo &) = delete; BasicFileInfo(const BasicFileInfo &) = delete;
BasicFileInfo &operator=(const BasicFileInfo &) = delete; BasicFileInfo &operator=(const BasicFileInfo &) = delete;
virtual ~BasicFileInfo(); virtual ~BasicFileInfo();
@ -31,16 +31,16 @@ public:
// methods to get, set path (components) // methods to get, set path (components)
const std::string &path() const; const std::string &path() const;
void setPath(const std::string &path); void setPath(std::string_view path);
static std::string fileName(const std::string &path, bool cutExtension = false); static std::string fileName(const std::string &path, bool cutExtension = false);
std::string fileName(bool cutExtension = false) const; std::string fileName(bool cutExtension = false) const;
static std::string extension(const std::string &path); static std::string extension(std::string_view path);
std::string extension() const; std::string extension() const;
static std::string pathWithoutExtension(const std::string &fullPath); static std::string pathWithoutExtension(const std::string &fullPath);
std::string pathWithoutExtension() const; std::string pathWithoutExtension() const;
static std::string containingDirectory(const std::string &path); static std::string containingDirectory(const std::string &path);
std::string containingDirectory() const; std::string containingDirectory() const;
static const char *pathForOpen(const std::string &url); static std::string_view pathForOpen(const std::string &url);
// methods to get, set the file size // methods to get, set the file size
std::uint64_t size() const; std::uint64_t size() const;
@ -137,7 +137,7 @@ inline void BasicFileInfo::reportPathChanged(const std::string &newPath)
* \remarks If \a url is already a plain path it won't changed. * \remarks If \a url is already a plain path it won't changed.
* \returns Returns a pointer the URL data itself. No copy is made. * \returns Returns a pointer the URL data itself. No copy is made.
*/ */
inline const char *BasicFileInfo::pathForOpen(const std::string &url) inline std::string_view BasicFileInfo::pathForOpen(const std::string &url)
{ {
return CppUtilities::startsWith(url, "file:/") ? url.data() + 6 : url.data(); return CppUtilities::startsWith(url, "file:/") ? url.data() + 6 : url.data();
} }

View File

@ -32,6 +32,10 @@ struct TAG_PARSER_EXPORT CaseInsensitiveStringComparer {
{ {
return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), CaseInsensitiveCharComparer()); return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), CaseInsensitiveCharComparer());
} }
bool operator()(std::string_view lhs, std::string_view rhs) const
{
return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), CaseInsensitiveCharComparer());
}
}; };
} // namespace TagParser } // namespace TagParser

View File

@ -19,7 +19,7 @@ namespace TagParser {
/*! /*!
* \brief Returns the string representation of the specified \a diagLevel. * \brief Returns the string representation of the specified \a diagLevel.
*/ */
const char *diagLevelName(DiagLevel diagLevel) std::string_view diagLevelName(DiagLevel diagLevel)
{ {
switch (diagLevel) { switch (diagLevel) {
case DiagLevel::Information: case DiagLevel::Information:
@ -32,7 +32,7 @@ const char *diagLevelName(DiagLevel diagLevel)
return "debug"; return "debug";
case DiagLevel::None: case DiagLevel::None:
default: default:
return ""; return std::string_view();
} }
} }

View File

@ -25,7 +25,7 @@ enum class DiagLevel {
/// \brief The worst diag level. /// \brief The worst diag level.
constexpr auto worstDiagLevel = DiagLevel::Fatal; constexpr auto worstDiagLevel = DiagLevel::Fatal;
TAG_PARSER_EXPORT const char *diagLevelName(DiagLevel diagLevel); TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel);
/*! /*!
* \brief Sets \a lhs to \a rhs if \a rhs is more critical than \a lhs and returns \a lhs. * \brief Sets \a lhs to \a rhs if \a rhs is more critical than \a lhs and returns \a lhs.
@ -46,7 +46,7 @@ public:
DiagMessage(DiagLevel level, std::string &&message, std::string &&context); DiagMessage(DiagLevel level, std::string &&message, std::string &&context);
DiagLevel level() const; DiagLevel level() const;
const char *levelName() const; std::string_view levelName() const;
const std::string &message() const; const std::string &message() const;
const std::string &context() const; const std::string &context() const;
const CppUtilities::DateTime &creationTime() const; const CppUtilities::DateTime &creationTime() const;
@ -116,7 +116,7 @@ inline DiagLevel DiagMessage::level() const
/*! /*!
* \brief Returns the string representation of the level(). * \brief Returns the string representation of the level().
*/ */
inline const char *DiagMessage::levelName() const inline std::string_view DiagMessage::levelName() const
{ {
return diagLevelName(m_level); return diagLevelName(m_level);
} }

View File

@ -39,7 +39,7 @@ public:
FieldMapBasedTag(); FieldMapBasedTag();
TagType type() const; TagType type() const;
const char *typeName() const; std::string_view typeName() const;
TagTextEncoding proposedTextEncoding() const; TagTextEncoding proposedTextEncoding() const;
const TagValue &value(const IdentifierType &id) const; const TagValue &value(const IdentifierType &id) const;
const TagValue &value(KnownField field) const; const TagValue &value(KnownField field) const;
@ -107,7 +107,7 @@ template <class ImplementationType> TagType FieldMapBasedTag<ImplementationType>
return ImplementationType::tagType; return ImplementationType::tagType;
} }
template <class ImplementationType> const char *FieldMapBasedTag<ImplementationType>::typeName() const template <class ImplementationType> std::string_view FieldMapBasedTag<ImplementationType>::typeName() const
{ {
return ImplementationType::tagName; return ImplementationType::tagName;
} }

View File

@ -26,11 +26,11 @@ namespace TagParser {
* \brief Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified \a iterator. * \brief Parses the FLAC "METADATA_BLOCK_HEADER" which is read using the specified \a iterator.
* \remarks The specified \a buffer must be at least 4 bytes long. * \remarks The specified \a buffer must be at least 4 bytes long.
*/ */
void FlacMetaDataBlockHeader::parseHeader(const char *buffer) void FlacMetaDataBlockHeader::parseHeader(std::string_view buffer)
{ {
m_last = *buffer & 0x80; m_last = buffer[0] & 0x80;
m_type = *buffer & (0x80 - 1); m_type = buffer[0] & (0x80 - 1);
m_dataSize = BE::toUInt24(buffer + 1); m_dataSize = BE::toUInt24(buffer.data() + 1);
} }
/*! /*!
@ -55,9 +55,9 @@ void FlacMetaDataBlockHeader::makeHeader(std::ostream &outputStream)
* \brief Parses the FLAC "METADATA_BLOCK_STREAMINFO" which is read using the specified \a iterator. * \brief Parses the FLAC "METADATA_BLOCK_STREAMINFO" which is read using the specified \a iterator.
* \remarks The specified \a buffer must be at least 0x22 bytes long. * \remarks The specified \a buffer must be at least 0x22 bytes long.
*/ */
void FlacMetaDataBlockStreamInfo::parse(const char *buffer) void FlacMetaDataBlockStreamInfo::parse(std::string_view buffer)
{ {
BitReader reader(buffer, 0x22); auto reader = BitReader(buffer.data(), 0x22);
m_minBlockSize = reader.readBits<std::uint16_t>(16); m_minBlockSize = reader.readBits<std::uint16_t>(16);
m_maxBlockSize = reader.readBits<std::uint16_t>(16); m_maxBlockSize = reader.readBits<std::uint16_t>(16);
m_minFrameSize = reader.readBits<std::uint32_t>(24); m_minFrameSize = reader.readBits<std::uint32_t>(24);
@ -66,7 +66,7 @@ void FlacMetaDataBlockStreamInfo::parse(const char *buffer)
m_channelCount = reader.readBits<std::uint8_t>(3) + 1; m_channelCount = reader.readBits<std::uint8_t>(3) + 1;
m_bitsPerSample = reader.readBits<std::uint8_t>(5) + 1; m_bitsPerSample = reader.readBits<std::uint8_t>(5) + 1;
m_totalSampleCount = reader.readBits<std::uint64_t>(36); m_totalSampleCount = reader.readBits<std::uint64_t>(36);
memcpy(m_md5Sum, buffer + 0x22 - sizeof(m_md5Sum), sizeof(m_md5Sum)); std::memcpy(m_md5Sum, buffer.data() + 0x22 - sizeof(m_md5Sum), sizeof(m_md5Sum));
} }
/*! /*!

View File

@ -29,7 +29,7 @@ class TAG_PARSER_EXPORT FlacMetaDataBlockHeader {
public: public:
constexpr FlacMetaDataBlockHeader(); constexpr FlacMetaDataBlockHeader();
void parseHeader(const char *buffer); void parseHeader(std::string_view buffer);
void makeHeader(std::ostream &outputStream); void makeHeader(std::ostream &outputStream);
constexpr std::uint8_t isLast() const; constexpr std::uint8_t isLast() const;
@ -110,7 +110,7 @@ class TAG_PARSER_EXPORT FlacMetaDataBlockStreamInfo {
public: public:
constexpr FlacMetaDataBlockStreamInfo(); constexpr FlacMetaDataBlockStreamInfo();
void parse(const char *buffer); void parse(std::string_view buffer);
constexpr std::uint16_t minBlockSize() const; constexpr std::uint16_t minBlockSize() const;
constexpr std::uint16_t maxBlockSize() const; constexpr std::uint16_t maxBlockSize() const;

View File

@ -12,9 +12,9 @@ namespace TagParser {
/*! /*!
* \brief Returns all known genre names. * \brief Returns all known genre names.
*/ */
const char *const *Id3Genres::genreNames() const std::string_view *Id3Genres::genreNames()
{ {
static const char *const names[] = { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", static const std::string_view names[] = { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal",
"New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks",
"Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House",
"Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock",
@ -39,12 +39,12 @@ const char *const *Id3Genres::genreNames()
* \brief Returns the numerical denotation of the specified \a genre or -1 if \a genre is unknown. * \brief Returns the numerical denotation of the specified \a genre or -1 if \a genre is unknown.
* \remarks If \a string is empty, the non-standard Id3Genres::emptyGenreIndex() is returned. * \remarks If \a string is empty, the non-standard Id3Genres::emptyGenreIndex() is returned.
*/ */
int Id3Genres::indexFromString(const string &genre) int Id3Genres::indexFromString(std::string_view genre)
{ {
if (genre.empty()) { if (genre.empty()) {
return emptyGenreIndex(); return emptyGenreIndex();
} }
const char *const *ptr = genreNames(); const string_view *ptr = genreNames();
for (int index = 0; index < genreCount(); ++ptr, ++index) { for (int index = 0; index < genreCount(); ++ptr, ++index) {
if (genre == *ptr) { if (genre == *ptr) {
return index; return index;

View File

@ -4,29 +4,29 @@
#include "../global.h" #include "../global.h"
#include <cstdint> #include <cstdint>
#include <string> #include <string_view>
namespace TagParser { namespace TagParser {
class TAG_PARSER_EXPORT Id3Genres { class TAG_PARSER_EXPORT Id3Genres {
public: public:
static inline const char *stringFromIndex(int index); static inline std::string_view stringFromIndex(int index);
static int indexFromString(const std::string &genre); static int indexFromString(std::string_view genre);
static constexpr int genreCount(); static constexpr int genreCount();
static constexpr int emptyGenreIndex(); static constexpr int emptyGenreIndex();
static constexpr bool isEmptyGenre(int index); static constexpr bool isEmptyGenre(int index);
static constexpr bool isIndexSupported(int index); static constexpr bool isIndexSupported(int index);
private: private:
static const char *const *genreNames(); static const std::string_view *genreNames();
}; };
/*! /*!
* \brief Returns the genre name for the specified numerical denotation as C-style string. * \brief Returns the genre name for the specified numerical denotation as C-style string.
*/ */
inline const char *Id3Genres::stringFromIndex(int index) inline std::string_view Id3Genres::stringFromIndex(int index)
{ {
return isIndexSupported(index) ? genreNames()[index] : nullptr; return isIndexSupported(index) ? genreNames()[index] : std::string_view();
} }
/*! /*!

View File

@ -32,7 +32,7 @@ TagType Id3v1Tag::type() const
return TagType::Id3v1Tag; return TagType::Id3v1Tag;
} }
const char *Id3v1Tag::typeName() const std::string_view Id3v1Tag::typeName() const
{ {
return tagName; return tagName;
} }

View File

@ -12,9 +12,9 @@ public:
Id3v1Tag(); Id3v1Tag();
static constexpr TagType tagType = TagType::Id3v1Tag; static constexpr TagType tagType = TagType::Id3v1Tag;
static constexpr const char *tagName = "ID3v1 tag"; static constexpr std::string_view tagName = "ID3v1 tag";
TagType type() const override; TagType type() const override;
const char *typeName() const override; std::string_view typeName() const override;
bool canEncodingBeUsed(TagTextEncoding encoding) const override; bool canEncodingBeUsed(TagTextEncoding encoding) const override;
const TagValue &value(KnownField value) const override; const TagValue &value(KnownField value) const override;
bool setValue(KnownField field, const TagValue &value) override; bool setValue(KnownField field, const TagValue &value) override;

View File

@ -140,7 +140,7 @@ public:
static void makeComment( static void makeComment(
std::unique_ptr<char[]> &buffer, std::uint32_t &bufferSize, const TagValue &comment, std::uint8_t version, Diagnostics &diag); std::unique_ptr<char[]> &buffer, std::uint32_t &bufferSize, const TagValue &comment, std::uint8_t version, Diagnostics &diag);
static IdentifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static IdentifierType fieldIdFromString(std::string_view idString);
static std::string fieldIdToString(IdentifierType id); static std::string fieldIdToString(IdentifierType id);
private: private:
@ -332,13 +332,13 @@ inline bool Id3v2Frame::supportsNestedFields() const
/*! /*!
* \brief Converts the specified ID string representation to an actual ID. * \brief Converts the specified ID string representation to an actual ID.
*/ */
inline Id3v2Frame::IdentifierType Id3v2Frame::fieldIdFromString(const char *idString, std::size_t idStringSize) inline Id3v2Frame::IdentifierType Id3v2Frame::fieldIdFromString(std::string_view idString)
{ {
switch (idStringSize != std::string::npos ? idStringSize : std::strlen(idString)) { switch (idString.size()) {
case 3: case 3:
return CppUtilities::BE::toUInt24(idString); return CppUtilities::BE::toUInt24(idString.data());
case 4: case 4:
return CppUtilities::BE::toUInt32(idString); return CppUtilities::BE::toUInt32(idString.data());
default: default:
throw CppUtilities::ConversionException("ID3v2 ID must be 3 or 4 chars"); throw CppUtilities::ConversionException("ID3v2 ID must be 3 or 4 chars");
} }

View File

@ -66,7 +66,7 @@ public:
Id3v2Tag(); Id3v2Tag();
static constexpr TagType tagType = TagType::Id3v2Tag; static constexpr TagType tagType = TagType::Id3v2Tag;
static constexpr const char *tagName = "ID3v2 tag"; static constexpr std::string_view tagName = "ID3v2 tag";
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf16LittleEndian; static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf16LittleEndian;
TagTextEncoding proposedTextEncoding() const override; TagTextEncoding proposedTextEncoding() const override;
bool canEncodingBeUsed(TagTextEncoding encoding) const override; bool canEncodingBeUsed(TagTextEncoding encoding) const override;

View File

@ -528,31 +528,14 @@ void EbmlElement::makeSimpleElement(ostream &stream, IdentifierType id, std::uin
* \param id Specifies the element ID. * \param id Specifies the element ID.
* \param content Specifies the value of the element as string. * \param content Specifies the value of the element as string.
*/ */
void EbmlElement::makeSimpleElement(std::ostream &stream, GenericFileElement::IdentifierType id, const std::string &content) void EbmlElement::makeSimpleElement(std::ostream &stream, GenericFileElement::IdentifierType id, string_view content)
{ {
char buff1[8]; char buff1[8];
std::uint8_t sizeLength = EbmlElement::makeId(id, buff1); std::uint8_t sizeLength = EbmlElement::makeId(id, buff1);
stream.write(buff1, sizeLength); stream.write(buff1, sizeLength);
sizeLength = EbmlElement::makeSizeDenotation(content.size(), buff1); sizeLength = EbmlElement::makeSizeDenotation(content.size(), buff1);
stream.write(buff1, sizeLength); stream.write(buff1, sizeLength);
stream.write(content.c_str(), content.size()); stream.write(content.data(), content.size());
}
/*!
* \brief Makes a simple EBML element.
* \param stream Specifies the stream to write the data to.
* \param id Specifies the element ID.
* \param data Specifies the data of the element.
* \param dataSize Specifies the size of \a data.
*/
void EbmlElement::makeSimpleElement(ostream &stream, GenericFileElement::IdentifierType id, const char *data, std::size_t dataSize)
{
char buff1[8];
std::uint8_t sizeLength = EbmlElement::makeId(id, buff1);
stream.write(buff1, sizeLength);
sizeLength = EbmlElement::makeSizeDenotation(dataSize, buff1);
stream.write(buff1, sizeLength);
stream.write(data, dataSize);
} }
} // namespace TagParser } // namespace TagParser

View File

@ -12,6 +12,7 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -51,8 +52,7 @@ public:
static std::uint8_t makeUInteger(std::uint64_t value, char *buff); static std::uint8_t makeUInteger(std::uint64_t value, char *buff);
static std::uint8_t makeUInteger(std::uint64_t value, char *buff, std::uint8_t minBytes); static std::uint8_t makeUInteger(std::uint64_t value, char *buff, std::uint8_t minBytes);
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content); static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content);
static void makeSimpleElement(std::ostream &stream, IdentifierType id, const std::string &content); static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::string_view content);
static void makeSimpleElement(std::ostream &stream, IdentifierType id, const char *data, std::size_t dataSize);
static std::uint64_t bytesToBeSkipped; static std::uint64_t bytesToBeSkipped;
protected: protected:
@ -71,8 +71,7 @@ private:
inline std::string EbmlElement::idToString() const inline std::string EbmlElement::idToString() const
{ {
using namespace CppUtilities; using namespace CppUtilities;
const char *const name = matroskaIdName(id()); if (const auto name = matroskaIdName(id()); !name.empty()) {
if (*name) {
return argsToString('0', 'x', numberToString(id(), 16), ' ', '\"', name, '\"'); return argsToString('0', 'x', numberToString(id(), 16), ' ', '\"', name, '\"');
} else { } else {
return "0x" + numberToString(id(), 16); return "0x" + numberToString(id(), 16);

View File

@ -923,13 +923,12 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
const std::uint64_t ebmlHeaderSize = 4 + EbmlElement::calculateSizeDenotationLength(ebmlHeaderDataSize) + ebmlHeaderDataSize; const std::uint64_t ebmlHeaderSize = 4 + EbmlElement::calculateSizeDenotationLength(ebmlHeaderDataSize) + ebmlHeaderDataSize;
// calculate size of "WritingLib"-element // calculate size of "WritingLib"-element
constexpr const char muxingAppName[] = APP_NAME " v" APP_VERSION; constexpr std::string_view muxingAppName = APP_NAME " v" APP_VERSION;
constexpr std::uint64_t muxingAppElementDataSize = sizeof(muxingAppName) - 1; constexpr std::uint64_t muxingAppElementTotalSize = 2 + 1 + muxingAppName.size();
constexpr std::uint64_t muxingAppElementTotalSize = 2 + 1 + muxingAppElementDataSize;
// calculate size of "WritingApp"-element // calculate size of "WritingApp"-element
const std::uint64_t writingAppElementDataSize const std::uint64_t writingAppElementDataSize
= fileInfo().writingApplication().empty() ? muxingAppElementDataSize : fileInfo().writingApplication().size() - 1; = fileInfo().writingApplication().empty() ? muxingAppName.size() : fileInfo().writingApplication().size();
const std::uint64_t writingAppElementTotalSize = 2 + 1 + writingAppElementDataSize; const std::uint64_t writingAppElementTotalSize = 2 + 1 + writingAppElementDataSize;
try { try {
@ -1496,7 +1495,7 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
try { try {
BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, outputStream, backupStream); BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, outputStream, backupStream);
// recreate original file, define buffer variables // recreate original file, define buffer variables
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back( diag.emplace_back(
DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context); DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context);
@ -1506,9 +1505,9 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
// open the current file as backupStream and create a new outputStream at the specified "save file path" // open the current file as backupStream and create a new outputStream at the specified "save file path"
try { try {
backupStream.exceptions(ios_base::badbit | ios_base::failbit); backupStream.exceptions(ios_base::badbit | ios_base::failbit);
backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::in | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::binary);
fileInfo().close(); fileInfo().close();
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().saveFilePath()), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().saveFilePath()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context); diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context);
throw; throw;
@ -1618,9 +1617,9 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee
} }
} }
// -> write "MuxingApp"- and "WritingApp"-element // -> write "MuxingApp"- and "WritingApp"-element
EbmlElement::makeSimpleElement(outputStream, MatroskaIds::MuxingApp, muxingAppName, muxingAppElementDataSize); EbmlElement::makeSimpleElement(outputStream, MatroskaIds::MuxingApp, muxingAppName);
EbmlElement::makeSimpleElement(outputStream, MatroskaIds::WrittingApp, EbmlElement::makeSimpleElement(outputStream, MatroskaIds::WrittingApp,
fileInfo().writingApplication().empty() ? muxingAppName : fileInfo().writingApplication().data(), writingAppElementDataSize); fileInfo().writingApplication().empty() ? muxingAppName : fileInfo().writingApplication());
} }
// write "Tracks"-element // write "Tracks"-element

View File

@ -19,7 +19,7 @@ namespace MatroskaTrackType {
* \brief Returns a string for the specified \a matroskaId * \brief Returns a string for the specified \a matroskaId
* if known; otherwise returns an empty string. * if known; otherwise returns an empty string.
*/ */
const char *matroskaIdName(std::uint32_t matroskaId) std::string_view matroskaIdName(std::uint32_t matroskaId)
{ {
using namespace EbmlIds; using namespace EbmlIds;
using namespace MatroskaIds; using namespace MatroskaIds;
@ -518,7 +518,7 @@ const char *matroskaIdName(std::uint32_t matroskaId)
return "reference time code"; return "reference time code";
default: default:
return ""; return std::string_view();
} }
} }

View File

@ -4,6 +4,7 @@
#include "../global.h" #include "../global.h"
#include <cstdint> #include <cstdint>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -448,7 +449,7 @@ constexpr bool operator<=(MatroskaElementLevel lhs, MatroskaElementLevel rhs)
return lhs == rhs || lhs < rhs; return lhs == rhs || lhs < rhs;
} }
TAG_PARSER_EXPORT const char *matroskaIdName(std::uint32_t matroskaId); TAG_PARSER_EXPORT std::string_view matroskaIdName(std::uint32_t matroskaId);
TAG_PARSER_EXPORT MatroskaElementLevel matroskaIdLevel(std::uint32_t matroskaId); TAG_PARSER_EXPORT MatroskaElementLevel matroskaIdLevel(std::uint32_t matroskaId);
} // namespace TagParser } // namespace TagParser

View File

@ -4,8 +4,8 @@
#include "../diagnostics.h" #include "../diagnostics.h"
#include <initializer_list> #include <initializer_list>
#include <map>
#include <stdexcept> #include <stdexcept>
#include <unordered_map>
using namespace std; using namespace std;
using namespace CppUtilities; using namespace CppUtilities;
@ -22,59 +22,59 @@ MatroskaTag::IdentifierType MatroskaTag::internallyGetFieldId(KnownField field)
using namespace MatroskaTagIds; using namespace MatroskaTagIds;
switch (field) { switch (field) {
case KnownField::Artist: case KnownField::Artist:
return artist(); return std::string(artist());
case KnownField::Album: case KnownField::Album:
return album(); return std::string(album());
case KnownField::Comment: case KnownField::Comment:
return comment(); return std::string(comment());
case KnownField::RecordDate: case KnownField::RecordDate:
case KnownField::Year: case KnownField::Year:
return dateRecorded(); return std::string(dateRecorded());
case KnownField::ReleaseDate: case KnownField::ReleaseDate:
return dateRelease(); return std::string(dateRelease());
case KnownField::Title: case KnownField::Title:
return title(); return std::string(title());
case KnownField::Genre: case KnownField::Genre:
return genre(); return std::string(genre());
case KnownField::PartNumber: case KnownField::PartNumber:
return partNumber(); return std::string(partNumber());
case KnownField::TotalParts: case KnownField::TotalParts:
return totalParts(); return std::string(totalParts());
case KnownField::Encoder: case KnownField::Encoder:
return encoder(); return std::string(encoder());
case KnownField::EncoderSettings: case KnownField::EncoderSettings:
return encoderSettings(); return std::string(encoderSettings());
case KnownField::Bpm: case KnownField::Bpm:
return bpm(); return std::string(bpm());
case KnownField::Bps: case KnownField::Bps:
return bps(); return std::string(bps());
case KnownField::Rating: case KnownField::Rating:
return rating(); return std::string(rating());
case KnownField::Description: case KnownField::Description:
return description(); return std::string(description());
case KnownField::Lyrics: case KnownField::Lyrics:
return lyrics(); return std::string(lyrics());
case KnownField::RecordLabel: case KnownField::RecordLabel:
return label(); return std::string(label());
case KnownField::Performers: case KnownField::Performers:
return actor(); return std::string(actor());
case KnownField::Lyricist: case KnownField::Lyricist:
return lyricist(); return std::string(lyricist());
case KnownField::Composer: case KnownField::Composer:
return composer(); return std::string(composer());
case KnownField::Length: case KnownField::Length:
return duration(); return std::string(duration());
case KnownField::Language: case KnownField::Language:
return language(); return std::string(language());
default: default:
return string(); return std::string();
} }
} }
KnownField MatroskaTag::internallyGetKnownField(const IdentifierType &id) const KnownField MatroskaTag::internallyGetKnownField(const IdentifierType &id) const
{ {
using namespace MatroskaTagIds; using namespace MatroskaTagIds;
static const map<string, KnownField> fieldMap({ static const std::unordered_map<std::string_view, KnownField> fieldMap({
{ artist(), KnownField::Artist }, { artist(), KnownField::Artist },
{ album(), KnownField::Album }, { album(), KnownField::Album },
{ comment(), KnownField::Comment }, { comment(), KnownField::Comment },

View File

@ -62,7 +62,7 @@ public:
MatroskaTag(); MatroskaTag();
static constexpr TagType tagType = TagType::MatroskaTag; static constexpr TagType tagType = TagType::MatroskaTag;
static constexpr const char *tagName = "Matroska tag"; static constexpr std::string_view tagName = "Matroska tag";
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8; static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
bool canEncodingBeUsed(TagTextEncoding encoding) const override; bool canEncodingBeUsed(TagTextEncoding encoding) const override;
bool supportsTarget() const override; bool supportsTarget() const override;

View File

@ -77,7 +77,7 @@ public:
bool isAdditionalTypeInfoUsed() const; bool isAdditionalTypeInfoUsed() const;
bool supportsNestedFields() const; bool supportsNestedFields() const;
static typename std::string fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static typename std::string fieldIdFromString(std::string_view idString);
static std::string fieldIdToString(const std::string &id); static std::string fieldIdToString(const std::string &id);
}; };
@ -101,9 +101,9 @@ inline bool MatroskaTagField::supportsNestedFields() const
* \brief Converts the specified ID string representation to an actual ID. * \brief Converts the specified ID string representation to an actual ID.
* \remarks As Matroska field IDs are text strings the string is just passed. * \remarks As Matroska field IDs are text strings the string is just passed.
*/ */
inline std::string MatroskaTagField::fieldIdFromString(const char *idString, std::size_t idStringSize) inline std::string MatroskaTagField::fieldIdFromString(std::string_view idString)
{ {
return idStringSize != std::string::npos ? std::string(idString, idStringSize) : std::string(idString); return std::string(idString);
} }
/*! /*!

View File

@ -3,469 +3,471 @@
#include "../tagtarget.h" #include "../tagtarget.h"
#include <string_view>
namespace TagParser { namespace TagParser {
namespace MatroskaTagIds { namespace MatroskaTagIds {
constexpr TAG_PARSER_EXPORT const char *original() constexpr TAG_PARSER_EXPORT std::string_view original()
{ {
return "ORIGINAL"; return "ORIGINAL";
} }
constexpr TAG_PARSER_EXPORT const char *sample() constexpr TAG_PARSER_EXPORT std::string_view sample()
{ {
return "SAMPLE"; return "SAMPLE";
} }
constexpr TAG_PARSER_EXPORT const char *country() constexpr TAG_PARSER_EXPORT std::string_view country()
{ {
return "COUNTRY"; return "COUNTRY";
} }
constexpr TAG_PARSER_EXPORT const char *totalParts() constexpr TAG_PARSER_EXPORT std::string_view totalParts()
{ {
return "TOTAL_PARTS"; return "TOTAL_PARTS";
} }
constexpr TAG_PARSER_EXPORT const char *partNumber() constexpr TAG_PARSER_EXPORT std::string_view partNumber()
{ {
return "PART_NUMBER"; return "PART_NUMBER";
} }
constexpr TAG_PARSER_EXPORT const char *partOffset() constexpr TAG_PARSER_EXPORT std::string_view partOffset()
{ {
return "PART_OFFSET"; return "PART_OFFSET";
} }
constexpr TAG_PARSER_EXPORT const char *title() constexpr TAG_PARSER_EXPORT std::string_view title()
{ {
return "TITLE"; return "TITLE";
} }
constexpr TAG_PARSER_EXPORT const char *subtitle() constexpr TAG_PARSER_EXPORT std::string_view subtitle()
{ {
return "SUBTITLE"; return "SUBTITLE";
} }
constexpr TAG_PARSER_EXPORT const char *url() constexpr TAG_PARSER_EXPORT std::string_view url()
{ {
return "URL"; return "URL";
} }
constexpr TAG_PARSER_EXPORT const char *sortWith() constexpr TAG_PARSER_EXPORT std::string_view sortWith()
{ {
return "SORT_WITH"; return "SORT_WITH";
} }
constexpr TAG_PARSER_EXPORT const char *instruments() constexpr TAG_PARSER_EXPORT std::string_view instruments()
{ {
return "INSTRUMENTS"; return "INSTRUMENTS";
} }
constexpr TAG_PARSER_EXPORT const char *email() constexpr TAG_PARSER_EXPORT std::string_view email()
{ {
return "EMAIL"; return "EMAIL";
} }
constexpr TAG_PARSER_EXPORT const char *address() constexpr TAG_PARSER_EXPORT std::string_view address()
{ {
return "ADDRESS"; return "ADDRESS";
} }
constexpr TAG_PARSER_EXPORT const char *fax() constexpr TAG_PARSER_EXPORT std::string_view fax()
{ {
return "FAX"; return "FAX";
} }
constexpr TAG_PARSER_EXPORT const char *phone() constexpr TAG_PARSER_EXPORT std::string_view phone()
{ {
return "PHONE"; return "PHONE";
} }
constexpr TAG_PARSER_EXPORT const char *artist() constexpr TAG_PARSER_EXPORT std::string_view artist()
{ {
return "ARTIST"; return "ARTIST";
} }
constexpr TAG_PARSER_EXPORT const char *album() constexpr TAG_PARSER_EXPORT std::string_view album()
{ {
return "ALBUM"; return "ALBUM";
} }
constexpr TAG_PARSER_EXPORT const char *leadPerformer() constexpr TAG_PARSER_EXPORT std::string_view leadPerformer()
{ {
return "LEAD_PERFORMER"; return "LEAD_PERFORMER";
} }
constexpr TAG_PARSER_EXPORT const char *accompaniment() constexpr TAG_PARSER_EXPORT std::string_view accompaniment()
{ {
return "ACCOMPANIMENT"; return "ACCOMPANIMENT";
} }
constexpr TAG_PARSER_EXPORT const char *composer() constexpr TAG_PARSER_EXPORT std::string_view composer()
{ {
return "COMPOSER"; return "COMPOSER";
} }
constexpr TAG_PARSER_EXPORT const char *arranger() constexpr TAG_PARSER_EXPORT std::string_view arranger()
{ {
return "ARRANGER"; return "ARRANGER";
} }
constexpr TAG_PARSER_EXPORT const char *lyrics() constexpr TAG_PARSER_EXPORT std::string_view lyrics()
{ {
return "LYRICS"; return "LYRICS";
} }
constexpr TAG_PARSER_EXPORT const char *lyricist() constexpr TAG_PARSER_EXPORT std::string_view lyricist()
{ {
return "LYRICIST"; return "LYRICIST";
} }
constexpr TAG_PARSER_EXPORT const char *conductor() constexpr TAG_PARSER_EXPORT std::string_view conductor()
{ {
return "CONDUCTOR"; return "CONDUCTOR";
} }
constexpr TAG_PARSER_EXPORT const char *director() constexpr TAG_PARSER_EXPORT std::string_view director()
{ {
return "DIRECTOR"; return "DIRECTOR";
} }
constexpr TAG_PARSER_EXPORT const char *assistantDirector() constexpr TAG_PARSER_EXPORT std::string_view assistantDirector()
{ {
return "ASSISTANT_DIRECTOR"; return "ASSISTANT_DIRECTOR";
} }
constexpr TAG_PARSER_EXPORT const char *directorOfPhotography() constexpr TAG_PARSER_EXPORT std::string_view directorOfPhotography()
{ {
return "DIRECTOR_OF_PHOTOGRAPHY"; return "DIRECTOR_OF_PHOTOGRAPHY";
} }
constexpr TAG_PARSER_EXPORT const char *soundEngineer() constexpr TAG_PARSER_EXPORT std::string_view soundEngineer()
{ {
return "SOUND_ENGINEER"; return "SOUND_ENGINEER";
} }
constexpr TAG_PARSER_EXPORT const char *artDirector() constexpr TAG_PARSER_EXPORT std::string_view artDirector()
{ {
return "ART_DIRECTOR"; return "ART_DIRECTOR";
} }
constexpr TAG_PARSER_EXPORT const char *productionDesigner() constexpr TAG_PARSER_EXPORT std::string_view productionDesigner()
{ {
return "PRODUCTION_DESIGNER"; return "PRODUCTION_DESIGNER";
} }
constexpr TAG_PARSER_EXPORT const char *choregrapher() constexpr TAG_PARSER_EXPORT std::string_view choregrapher()
{ {
return "CHOREGRAPHER"; return "CHOREGRAPHER";
} }
constexpr TAG_PARSER_EXPORT const char *costumeDesigner() constexpr TAG_PARSER_EXPORT std::string_view costumeDesigner()
{ {
return "COSTUME_DESIGNER"; return "COSTUME_DESIGNER";
} }
constexpr TAG_PARSER_EXPORT const char *actor() constexpr TAG_PARSER_EXPORT std::string_view actor()
{ {
return "ACTOR"; return "ACTOR";
} }
constexpr TAG_PARSER_EXPORT const char *character() constexpr TAG_PARSER_EXPORT std::string_view character()
{ {
return "CHARACTER"; return "CHARACTER";
} }
constexpr TAG_PARSER_EXPORT const char *writtenBy() constexpr TAG_PARSER_EXPORT std::string_view writtenBy()
{ {
return "WRITTEN_BY"; return "WRITTEN_BY";
} }
constexpr TAG_PARSER_EXPORT const char *screenplayBy() constexpr TAG_PARSER_EXPORT std::string_view screenplayBy()
{ {
return "SCREENPLAY_BY"; return "SCREENPLAY_BY";
} }
constexpr TAG_PARSER_EXPORT const char *editedBy() constexpr TAG_PARSER_EXPORT std::string_view editedBy()
{ {
return "EDITED_BY"; return "EDITED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *producer() constexpr TAG_PARSER_EXPORT std::string_view producer()
{ {
return "PRODUCER"; return "PRODUCER";
} }
constexpr TAG_PARSER_EXPORT const char *coproducer() constexpr TAG_PARSER_EXPORT std::string_view coproducer()
{ {
return "COPRODUCER"; return "COPRODUCER";
} }
constexpr TAG_PARSER_EXPORT const char *executiveProducer() constexpr TAG_PARSER_EXPORT std::string_view executiveProducer()
{ {
return "EXECUTIVE_PRODUCER"; return "EXECUTIVE_PRODUCER";
} }
constexpr TAG_PARSER_EXPORT const char *distributedBy() constexpr TAG_PARSER_EXPORT std::string_view distributedBy()
{ {
return "DISTRIBUTED_BY"; return "DISTRIBUTED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *masteredBy() constexpr TAG_PARSER_EXPORT std::string_view masteredBy()
{ {
return "MASTERED_BY"; return "MASTERED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *encodedBy() constexpr TAG_PARSER_EXPORT std::string_view encodedBy()
{ {
return "ENCODED_BY"; return "ENCODED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *mixedBy() constexpr TAG_PARSER_EXPORT std::string_view mixedBy()
{ {
return "MIXED_BY"; return "MIXED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *remixedBy() constexpr TAG_PARSER_EXPORT std::string_view remixedBy()
{ {
return "REMIXED_BY"; return "REMIXED_BY";
} }
constexpr TAG_PARSER_EXPORT const char *productionStudio() constexpr TAG_PARSER_EXPORT std::string_view productionStudio()
{ {
return "PRODUCTION_STUDIO"; return "PRODUCTION_STUDIO";
} }
constexpr TAG_PARSER_EXPORT const char *thanksTo() constexpr TAG_PARSER_EXPORT std::string_view thanksTo()
{ {
return "THANKS_TO"; return "THANKS_TO";
} }
constexpr TAG_PARSER_EXPORT const char *publisher() constexpr TAG_PARSER_EXPORT std::string_view publisher()
{ {
return "PUBLISHER"; return "PUBLISHER";
} }
constexpr TAG_PARSER_EXPORT const char *label() constexpr TAG_PARSER_EXPORT std::string_view label()
{ {
return "LABEL"; return "LABEL";
} }
constexpr TAG_PARSER_EXPORT const char *genre() constexpr TAG_PARSER_EXPORT std::string_view genre()
{ {
return "GENRE"; return "GENRE";
} }
constexpr TAG_PARSER_EXPORT const char *mood() constexpr TAG_PARSER_EXPORT std::string_view mood()
{ {
return "MOOD"; return "MOOD";
} }
constexpr TAG_PARSER_EXPORT const char *originalMediaType() constexpr TAG_PARSER_EXPORT std::string_view originalMediaType()
{ {
return "ORIGINAL_TAG_PARSER_TYPE"; return "ORIGINAL_TAG_PARSER_TYPE";
} }
constexpr TAG_PARSER_EXPORT const char *contentType() constexpr TAG_PARSER_EXPORT std::string_view contentType()
{ {
return "CONTENT_TYPE"; return "CONTENT_TYPE";
} }
constexpr TAG_PARSER_EXPORT const char *subject() constexpr TAG_PARSER_EXPORT std::string_view subject()
{ {
return "SUBJECT"; return "SUBJECT";
} }
constexpr TAG_PARSER_EXPORT const char *description() constexpr TAG_PARSER_EXPORT std::string_view description()
{ {
return "DESCRIPTION"; return "DESCRIPTION";
} }
constexpr TAG_PARSER_EXPORT const char *keywords() constexpr TAG_PARSER_EXPORT std::string_view keywords()
{ {
return "KEYWORDS"; return "KEYWORDS";
} }
constexpr TAG_PARSER_EXPORT const char *summary() constexpr TAG_PARSER_EXPORT std::string_view summary()
{ {
return "SUMMARY"; return "SUMMARY";
} }
constexpr TAG_PARSER_EXPORT const char *synopsis() constexpr TAG_PARSER_EXPORT std::string_view synopsis()
{ {
return "SYNOPSIS"; return "SYNOPSIS";
} }
constexpr TAG_PARSER_EXPORT const char *initialKey() constexpr TAG_PARSER_EXPORT std::string_view initialKey()
{ {
return "INITIAL_KEY"; return "INITIAL_KEY";
} }
constexpr TAG_PARSER_EXPORT const char *period() constexpr TAG_PARSER_EXPORT std::string_view period()
{ {
return "PERIOD"; return "PERIOD";
} }
constexpr TAG_PARSER_EXPORT const char *lawRating() constexpr TAG_PARSER_EXPORT std::string_view lawRating()
{ {
return "LAW_RATING"; return "LAW_RATING";
} }
constexpr TAG_PARSER_EXPORT const char *icra() constexpr TAG_PARSER_EXPORT std::string_view icra()
{ {
return "ICRA"; return "ICRA";
} }
constexpr TAG_PARSER_EXPORT const char *dateRelease() constexpr TAG_PARSER_EXPORT std::string_view dateRelease()
{ {
return "DATE_RELEASED"; return "DATE_RELEASED";
} }
constexpr TAG_PARSER_EXPORT const char *dateRecorded() constexpr TAG_PARSER_EXPORT std::string_view dateRecorded()
{ {
return "DATE_RECORDED"; return "DATE_RECORDED";
} }
constexpr TAG_PARSER_EXPORT const char *dateEncoded() constexpr TAG_PARSER_EXPORT std::string_view dateEncoded()
{ {
return "DATE_ENCODED"; return "DATE_ENCODED";
} }
constexpr TAG_PARSER_EXPORT const char *dateTagged() constexpr TAG_PARSER_EXPORT std::string_view dateTagged()
{ {
return "DATE_TAGGED"; return "DATE_TAGGED";
} }
constexpr TAG_PARSER_EXPORT const char *dateDigitized() constexpr TAG_PARSER_EXPORT std::string_view dateDigitized()
{ {
return "DATE_DIGITIZED"; return "DATE_DIGITIZED";
} }
constexpr TAG_PARSER_EXPORT const char *dateWritten() constexpr TAG_PARSER_EXPORT std::string_view dateWritten()
{ {
return "DATE_WRITTEN"; return "DATE_WRITTEN";
} }
constexpr TAG_PARSER_EXPORT const char *datePurchased() constexpr TAG_PARSER_EXPORT std::string_view datePurchased()
{ {
return "DATE_PURCHASED"; return "DATE_PURCHASED";
} }
constexpr TAG_PARSER_EXPORT const char *recordingLocation() constexpr TAG_PARSER_EXPORT std::string_view recordingLocation()
{ {
return "RECORDING_LOCATION"; return "RECORDING_LOCATION";
} }
constexpr TAG_PARSER_EXPORT const char *compositionLocation() constexpr TAG_PARSER_EXPORT std::string_view compositionLocation()
{ {
return "COMPOSITION_LOCATION"; return "COMPOSITION_LOCATION";
} }
constexpr TAG_PARSER_EXPORT const char *composerNationality() constexpr TAG_PARSER_EXPORT std::string_view composerNationality()
{ {
return "COMPOSER_NATIONALITY"; return "COMPOSER_NATIONALITY";
} }
constexpr TAG_PARSER_EXPORT const char *comment() constexpr TAG_PARSER_EXPORT std::string_view comment()
{ {
return "COMMENT"; return "COMMENT";
} }
constexpr TAG_PARSER_EXPORT const char *playCounter() constexpr TAG_PARSER_EXPORT std::string_view playCounter()
{ {
return "PLAY_COUNTER"; return "PLAY_COUNTER";
} }
constexpr TAG_PARSER_EXPORT const char *rating() constexpr TAG_PARSER_EXPORT std::string_view rating()
{ {
return "RATING"; return "RATING";
} }
constexpr TAG_PARSER_EXPORT const char *encoder() constexpr TAG_PARSER_EXPORT std::string_view encoder()
{ {
return "ENCODER"; return "ENCODER";
} }
constexpr TAG_PARSER_EXPORT const char *encoderSettings() constexpr TAG_PARSER_EXPORT std::string_view encoderSettings()
{ {
return "ENCODER_SETTINGS"; return "ENCODER_SETTINGS";
} }
constexpr TAG_PARSER_EXPORT const char *bps() constexpr TAG_PARSER_EXPORT std::string_view bps()
{ {
return "BPS"; return "BPS";
} }
constexpr TAG_PARSER_EXPORT const char *fps() constexpr TAG_PARSER_EXPORT std::string_view fps()
{ {
return "FPS"; return "FPS";
} }
constexpr TAG_PARSER_EXPORT const char *bpm() constexpr TAG_PARSER_EXPORT std::string_view bpm()
{ {
return "BPM"; return "BPM";
} }
constexpr TAG_PARSER_EXPORT const char *duration() constexpr TAG_PARSER_EXPORT std::string_view duration()
{ {
return "DURATION"; return "DURATION";
} }
constexpr TAG_PARSER_EXPORT const char *language() constexpr TAG_PARSER_EXPORT std::string_view language()
{ {
return "LANGUAGE"; return "LANGUAGE";
} }
constexpr TAG_PARSER_EXPORT const char *numberOfFrames() constexpr TAG_PARSER_EXPORT std::string_view numberOfFrames()
{ {
return "NUMBER_OF_FRAMES"; return "NUMBER_OF_FRAMES";
} }
constexpr TAG_PARSER_EXPORT const char *numberOfBytes() constexpr TAG_PARSER_EXPORT std::string_view numberOfBytes()
{ {
return "NUMBER_OF_BYTES"; return "NUMBER_OF_BYTES";
} }
constexpr TAG_PARSER_EXPORT const char *measure() constexpr TAG_PARSER_EXPORT std::string_view measure()
{ {
return "MEASURE"; return "MEASURE";
} }
constexpr TAG_PARSER_EXPORT const char *tuning() constexpr TAG_PARSER_EXPORT std::string_view tuning()
{ {
return "TUNING"; return "TUNING";
} }
constexpr TAG_PARSER_EXPORT const char *replaygainGain() constexpr TAG_PARSER_EXPORT std::string_view replaygainGain()
{ {
return "REPLAYGAIN_GAIN"; return "REPLAYGAIN_GAIN";
} }
constexpr TAG_PARSER_EXPORT const char *replaygainPeak() constexpr TAG_PARSER_EXPORT std::string_view replaygainPeak()
{ {
return "REPLAYGAIN_PEAK"; return "REPLAYGAIN_PEAK";
} }
constexpr TAG_PARSER_EXPORT const char *identifiers() constexpr TAG_PARSER_EXPORT std::string_view identifiers()
{ {
return "Identifiers"; return "Identifiers";
} }
constexpr TAG_PARSER_EXPORT const char *isrc() constexpr TAG_PARSER_EXPORT std::string_view isrc()
{ {
return "ISRC"; return "ISRC";
} }
constexpr TAG_PARSER_EXPORT const char *mcdi() constexpr TAG_PARSER_EXPORT std::string_view mcdi()
{ {
return "MCDI"; return "MCDI";
} }
constexpr TAG_PARSER_EXPORT const char *isbn() constexpr TAG_PARSER_EXPORT std::string_view isbn()
{ {
return "ISBN"; return "ISBN";
} }
constexpr TAG_PARSER_EXPORT const char *barcode() constexpr TAG_PARSER_EXPORT std::string_view barcode()
{ {
return "BARCODE"; return "BARCODE";
} }
constexpr TAG_PARSER_EXPORT const char *catalogNumber() constexpr TAG_PARSER_EXPORT std::string_view catalogNumber()
{ {
return "CATALOG_NUMBER"; return "CATALOG_NUMBER";
} }
constexpr TAG_PARSER_EXPORT const char *labelCode() constexpr TAG_PARSER_EXPORT std::string_view labelCode()
{ {
return "LABEL_CODE"; return "LABEL_CODE";
} }
constexpr TAG_PARSER_EXPORT const char *lccn() constexpr TAG_PARSER_EXPORT std::string_view lccn()
{ {
return "LCCN"; return "LCCN";
} }
constexpr TAG_PARSER_EXPORT const char *purchaseItem() constexpr TAG_PARSER_EXPORT std::string_view purchaseItem()
{ {
return "PURCHASE_ITEM"; return "PURCHASE_ITEM";
} }
constexpr TAG_PARSER_EXPORT const char *purchaseInfo() constexpr TAG_PARSER_EXPORT std::string_view purchaseInfo()
{ {
return "PURCHASE_INFO"; return "PURCHASE_INFO";
} }
constexpr TAG_PARSER_EXPORT const char *purchaseOwner() constexpr TAG_PARSER_EXPORT std::string_view purchaseOwner()
{ {
return "PURCHASE_OWNER"; return "PURCHASE_OWNER";
} }
constexpr TAG_PARSER_EXPORT const char *purchasePrice() constexpr TAG_PARSER_EXPORT std::string_view purchasePrice()
{ {
return "PURCHASE_PRICE"; return "PURCHASE_PRICE";
} }
constexpr TAG_PARSER_EXPORT const char *purchaseCurrency() constexpr TAG_PARSER_EXPORT std::string_view purchaseCurrency()
{ {
return "PURCHASE_CURRENCY"; return "PURCHASE_CURRENCY";
} }
constexpr TAG_PARSER_EXPORT const char *copyright() constexpr TAG_PARSER_EXPORT std::string_view copyright()
{ {
return "COPYRIGHT"; return "COPYRIGHT";
} }
constexpr TAG_PARSER_EXPORT const char *productionCopyright() constexpr TAG_PARSER_EXPORT std::string_view productionCopyright()
{ {
return "PRODUCTION_COPYRIGHT"; return "PRODUCTION_COPYRIGHT";
} }
constexpr TAG_PARSER_EXPORT const char *license() constexpr TAG_PARSER_EXPORT std::string_view license()
{ {
return "LICENSE"; return "LICENSE";
} }
constexpr TAG_PARSER_EXPORT const char *termsOfUse() constexpr TAG_PARSER_EXPORT std::string_view termsOfUse()
{ {
return "TERMS_OF_USE"; return "TERMS_OF_USE";
} }
namespace TrackSpecific { namespace TrackSpecific {
constexpr TAG_PARSER_EXPORT const char *numberOfBytes() constexpr TAG_PARSER_EXPORT std::string_view numberOfBytes()
{ {
return "NUMBER_OF_BYTES"; return "NUMBER_OF_BYTES";
} }
constexpr TAG_PARSER_EXPORT const char *numberOfFrames() constexpr TAG_PARSER_EXPORT std::string_view numberOfFrames()
{ {
return "NUMBER_OF_FRAMES"; return "NUMBER_OF_FRAMES";
} }
constexpr TAG_PARSER_EXPORT const char *duration() constexpr TAG_PARSER_EXPORT std::string_view duration()
{ {
return "DURATION"; return "DURATION";
} }
/// \brief The track's bit rate in bits per second. /// \brief The track's bit rate in bits per second.
constexpr TAG_PARSER_EXPORT const char *bitrate() constexpr TAG_PARSER_EXPORT std::string_view bitrate()
{ {
return "BPS"; return "BPS";
} }
constexpr TAG_PARSER_EXPORT const char *writingApp() constexpr TAG_PARSER_EXPORT std::string_view writingApp()
{ {
return "_STATISTICS_WRITING_APP"; return "_STATISTICS_WRITING_APP";
} }
constexpr TAG_PARSER_EXPORT const char *writingDate() constexpr TAG_PARSER_EXPORT std::string_view writingDate()
{ {
return "_STATISTICS_WRITING_DATE_UTC"; return "_STATISTICS_WRITING_DATE_UTC";
} }
constexpr TAG_PARSER_EXPORT const char *statisticsTags() constexpr TAG_PARSER_EXPORT std::string_view statisticsTags()
{ {
return "_STATISTICS_TAGS"; return "_STATISTICS_TAGS";
} }

View File

@ -212,10 +212,10 @@ MediaFormat MatroskaTrack::codecIdToMediaFormat(const string &codecId)
/// \cond /// \cond
template <typename PropertyType, typename ConversionFunction> template <typename PropertyType, typename ConversionFunction>
void MatroskaTrack::assignPropertyFromTagValue(const std::unique_ptr<MatroskaTag> &tag, const char *fieldId, PropertyType &property, void MatroskaTrack::assignPropertyFromTagValue(const std::unique_ptr<MatroskaTag> &tag, std::string_view fieldId, PropertyType &property,
const ConversionFunction &conversionFunction, Diagnostics &diag) const ConversionFunction &conversionFunction, Diagnostics &diag)
{ {
const TagValue &value = tag->value(fieldId); const TagValue &value = tag->value(std::string(fieldId));
if (!value.isEmpty()) { if (!value.isEmpty()) {
try { try {
property = conversionFunction(value); property = conversionFunction(value);

View File

@ -65,7 +65,7 @@ protected:
private: private:
template <typename PropertyType, typename ConversionFunction> template <typename PropertyType, typename ConversionFunction>
void assignPropertyFromTagValue(const std::unique_ptr<MatroskaTag> &tag, const char *fieldId, PropertyType &integer, void assignPropertyFromTagValue(const std::unique_ptr<MatroskaTag> &tag, std::string_view fieldId, PropertyType &integer,
const ConversionFunction &conversionFunction, Diagnostics &diag); const ConversionFunction &conversionFunction, Diagnostics &diag);
EbmlElement *m_trackElement; EbmlElement *m_trackElement;

View File

@ -734,7 +734,7 @@ void MediaFileInfo::applyChanges(Diagnostics &diag, AbortableProgressFeedback &p
* \sa containerFormatName() * \sa containerFormatName()
* \sa parseContainerFormat() * \sa parseContainerFormat()
*/ */
const char *MediaFileInfo::containerFormatAbbreviation() const string_view MediaFileInfo::containerFormatAbbreviation() const
{ {
MediaType mediaType = MediaType::Unknown; MediaType mediaType = MediaType::Unknown;
unsigned int version = 0; unsigned int version = 0;
@ -788,7 +788,7 @@ const char *MediaFileInfo::containerFormatAbbreviation() const
* \sa containerFormatName() * \sa containerFormatName()
* \sa parseContainerFormat() * \sa parseContainerFormat()
*/ */
const char *MediaFileInfo::mimeType() const string_view MediaFileInfo::mimeType() const
{ {
MediaType mediaType; MediaType mediaType;
switch (m_containerFormat) { switch (m_containerFormat) {
@ -1531,7 +1531,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
} }
progress.updateStep("Removing ID3v1 tag ..."); progress.updateStep("Removing ID3v1 tag ...");
stream().close(); stream().close();
if (truncate(BasicFileInfo::pathForOpen(path()), static_cast<std::streamoff>(size() - 128)) == 0) { if (truncate(BasicFileInfo::pathForOpen(path()).data(), static_cast<std::streamoff>(size() - 128)) == 0) {
reportSizeChanged(size() - 128); reportSizeChanged(size() - 128);
} else { } else {
diag.emplace_back(DiagLevel::Critical, "Unable to truncate file to remove ID3v1 tag.", context); diag.emplace_back(DiagLevel::Critical, "Unable to truncate file to remove ID3v1 tag.", context);
@ -1647,7 +1647,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
try { try {
BackupHelper::createBackupFile(backupDirectory(), path(), backupPath, outputStream, backupStream); BackupHelper::createBackupFile(backupDirectory(), path(), backupPath, outputStream, backupStream);
// recreate original file, define buffer variables // recreate original file, define buffer variables
outputStream.open(BasicFileInfo::pathForOpen(path()), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(path()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back( diag.emplace_back(
DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context); DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context);
@ -1658,8 +1658,8 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
try { try {
close(); close();
backupStream.exceptions(ios_base::badbit | ios_base::failbit); backupStream.exceptions(ios_base::badbit | ios_base::failbit);
backupStream.open(BasicFileInfo::pathForOpen(path()), ios_base::in | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(path()).data(), ios_base::in | ios_base::binary);
outputStream.open(BasicFileInfo::pathForOpen(m_saveFilePath), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(m_saveFilePath).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context); diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context);
throw; throw;
@ -1670,7 +1670,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
// reopen original file to ensure it is opened for writing // reopen original file to ensure it is opened for writing
try { try {
close(); close();
outputStream.open(BasicFileInfo::pathForOpen(path()), ios_base::in | ios_base::out | ios_base::binary); outputStream.open(BasicFileInfo::pathForOpen(path()).data(), ios_base::in | ios_base::out | ios_base::binary);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back(DiagLevel::Critical, argsToString("Opening the file with write permissions failed: ", failure.what()), context); diag.emplace_back(DiagLevel::Critical, argsToString("Opening the file with write permissions failed: ", failure.what()), context);
throw; throw;
@ -1776,7 +1776,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
// -> prevent deferring final write operations // -> prevent deferring final write operations
outputStream.close(); outputStream.close();
// -> truncate file // -> truncate file
if (truncate(BasicFileInfo::pathForOpen(path()), static_cast<streamoff>(newSize)) == 0) { if (truncate(BasicFileInfo::pathForOpen(path()).data(), static_cast<streamoff>(newSize)) == 0) {
reportSizeChanged(newSize); reportSizeChanged(newSize);
} else { } else {
diag.emplace_back(DiagLevel::Critical, "Unable to truncate the file.", context); diag.emplace_back(DiagLevel::Critical, "Unable to truncate the file.", context);

View File

@ -65,10 +65,10 @@ public:
// methods to get parsed information regarding ... // methods to get parsed information regarding ...
// ... the container // ... the container
ContainerFormat containerFormat() const; ContainerFormat containerFormat() const;
const char *containerFormatName() const; std::string_view containerFormatName() const;
const char *containerFormatAbbreviation() const; std::string_view containerFormatAbbreviation() const;
const char *containerFormatSubversion() const; std::string_view containerFormatSubversion() const;
const char *mimeType() const; std::string_view mimeType() const;
std::uint64_t containerOffset() const; std::uint64_t containerOffset() const;
std::uint64_t paddingSize() const; std::uint64_t paddingSize() const;
AbstractContainer *container() const; AbstractContainer *container() const;
@ -126,9 +126,8 @@ public:
void setBackupDirectory(const std::string &backupDirectory); void setBackupDirectory(const std::string &backupDirectory);
const std::string &saveFilePath() const; const std::string &saveFilePath() const;
void setSaveFilePath(const std::string &saveFilePath); void setSaveFilePath(const std::string &saveFilePath);
const std::string writingApplication() const; const std::string &writingApplication() const;
void setWritingApplication(const std::string &writingApplication); void setWritingApplication(std::string_view writingApplication);
void setWritingApplication(const char *writingApplication);
bool isForcingFullParse() const; bool isForcingFullParse() const;
void setForceFullParse(bool forceFullParse); void setForceFullParse(bool forceFullParse);
bool isForcingRewrite() const; bool isForcingRewrite() const;
@ -223,7 +222,7 @@ inline ContainerFormat MediaFileInfo::containerFormat() const
* \sa containerFormatAbbreviation() * \sa containerFormatAbbreviation()
* \sa parseContainerFormat() * \sa parseContainerFormat()
*/ */
inline const char *MediaFileInfo::containerFormatName() const inline std::string_view MediaFileInfo::containerFormatName() const
{ {
return TagParser::containerFormatName(m_containerFormat); return TagParser::containerFormatName(m_containerFormat);
} }
@ -238,7 +237,7 @@ inline const char *MediaFileInfo::containerFormatName() const
* \sa containerFormatName() * \sa containerFormatName()
* \sa parseContainerFormat() * \sa parseContainerFormat()
*/ */
inline const char *MediaFileInfo::containerFormatSubversion() const inline std::string_view MediaFileInfo::containerFormatSubversion() const
{ {
return TagParser::containerFormatSubversion(m_containerFormat); return TagParser::containerFormatSubversion(m_containerFormat);
} }
@ -396,7 +395,7 @@ inline void MediaFileInfo::setSaveFilePath(const std::string &saveFilePath)
* \remarks This is not read from the file when parsing and only used when saving changes. * \remarks This is not read from the file when parsing and only used when saving changes.
* \sa setWritingApplication() for more details * \sa setWritingApplication() for more details
*/ */
inline const std::string MediaFileInfo::writingApplication() const inline const std::string &MediaFileInfo::writingApplication() const
{ {
return m_writingApplication; return m_writingApplication;
} }
@ -405,16 +404,7 @@ inline const std::string MediaFileInfo::writingApplication() const
* \brief Sets the writing application as container-level meta-data. Put the name of your application here. * \brief Sets the writing application as container-level meta-data. Put the name of your application here.
* \remarks Might not be used (depends on the format). * \remarks Might not be used (depends on the format).
*/ */
inline void MediaFileInfo::setWritingApplication(const std::string &writingApplication) inline void MediaFileInfo::setWritingApplication(std::string_view writingApplication)
{
m_writingApplication = writingApplication;
}
/*!
* \brief Sets the writing application as container-level meta-data. Put the name of your application here.
* \remarks Might not be used (depends on the format).
*/
inline void MediaFileInfo::setWritingApplication(const char *writingApplication)
{ {
m_writingApplication = writingApplication; m_writingApplication = writingApplication;
} }

View File

@ -14,7 +14,7 @@ using namespace SubFormats;
* *
* Returns an empty string if no name is available. * Returns an empty string if no name is available.
*/ */
const char *MediaFormat::name() const std::string_view MediaFormat::name() const
{ {
switch (general) { switch (general) {
case GeneralMediaFormat::Aac: case GeneralMediaFormat::Aac:
@ -443,7 +443,7 @@ const char *MediaFormat::name() const
* *
* Returns an empty string if no abbreviation is available. * Returns an empty string if no abbreviation is available.
*/ */
const char *MediaFormat::abbreviation() const std::string_view MediaFormat::abbreviation() const
{ {
switch (general) { switch (general) {
case GeneralMediaFormat::Aac: case GeneralMediaFormat::Aac:
@ -758,7 +758,7 @@ const char *MediaFormat::abbreviation() const
* *
* Returns an empty string if no abbreviation is available. * Returns an empty string if no abbreviation is available.
*/ */
const char *MediaFormat::shortAbbreviation() const std::string_view MediaFormat::shortAbbreviation() const
{ {
switch (general) { switch (general) {
case GeneralMediaFormat::Aac: case GeneralMediaFormat::Aac:
@ -1033,7 +1033,7 @@ const char *MediaFormat::shortAbbreviation() const
* *
* Returns an empty string if no abbreviation is available. * Returns an empty string if no abbreviation is available.
*/ */
const char *MediaFormat::extensionName() const std::string_view MediaFormat::extensionName() const
{ {
switch (general) { switch (general) {
using namespace ExtensionFormats; using namespace ExtensionFormats;
@ -1056,7 +1056,7 @@ const char *MediaFormat::extensionName() const
/*! /*!
* \brief Returns the string representation for the specified \a mediaType. * \brief Returns the string representation for the specified \a mediaType.
*/ */
const char *mediaTypeName(MediaType mediaType) std::string_view mediaTypeName(MediaType mediaType)
{ {
switch (mediaType) { switch (mediaType) {
case MediaType::Unknown: case MediaType::Unknown:

View File

@ -3,6 +3,7 @@
#include "./global.h" #include "./global.h"
#include <string_view>
#include <utility> #include <utility>
namespace TagParser { namespace TagParser {
@ -21,7 +22,7 @@ enum class MediaType : unsigned int {
Meta, /**< (timed) metadata */ Meta, /**< (timed) metadata */
}; };
TAG_PARSER_EXPORT const char *mediaTypeName(MediaType mediaType); TAG_PARSER_EXPORT std::string_view mediaTypeName(MediaType mediaType);
/*! /*!
* \brief The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...). * \brief The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...).
@ -246,10 +247,10 @@ class TAG_PARSER_EXPORT MediaFormat {
public: public:
constexpr MediaFormat(GeneralMediaFormat general = GeneralMediaFormat::Unknown, unsigned char sub = 0, unsigned char extension = 0); constexpr MediaFormat(GeneralMediaFormat general = GeneralMediaFormat::Unknown, unsigned char sub = 0, unsigned char extension = 0);
const char *name() const; std::string_view name() const;
const char *abbreviation() const; std::string_view abbreviation() const;
const char *shortAbbreviation() const; std::string_view shortAbbreviation() const;
const char *extensionName() const; std::string_view extensionName() const;
constexpr operator bool() const; constexpr operator bool() const;
constexpr MediaFormat &operator+=(const MediaFormat &other); constexpr MediaFormat &operator+=(const MediaFormat &other);
constexpr bool operator==(GeneralMediaFormat general) const; constexpr bool operator==(GeneralMediaFormat general) const;

View File

@ -516,7 +516,7 @@ calculatePadding:
try { try {
BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, outputStream, backupStream); BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, outputStream, backupStream);
// recreate original file, define buffer variables // recreate original file, define buffer variables
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back( diag.emplace_back(
DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context); DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context);
@ -526,9 +526,9 @@ calculatePadding:
// open the current file as backupStream and create a new outputStream at the specified "save file path" // open the current file as backupStream and create a new outputStream at the specified "save file path"
try { try {
backupStream.exceptions(ios_base::badbit | ios_base::failbit); backupStream.exceptions(ios_base::badbit | ios_base::failbit);
backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::in | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::binary);
fileInfo().close(); fileInfo().close();
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().saveFilePath()), ios_base::out | ios_base::binary | ios_base::trunc); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().saveFilePath()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context); diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context);
throw; throw;
@ -819,7 +819,7 @@ calculatePadding:
} }
// the outputStream needs to be reopened to be able to read again // the outputStream needs to be reopened to be able to read again
outputStream.close(); outputStream.close();
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::in | ios_base::out | ios_base::binary); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::out | ios_base::binary);
setStream(outputStream); setStream(outputStream);
} else { } else {
const auto newSize = static_cast<std::uint64_t>(outputStream.tellp()); const auto newSize = static_cast<std::uint64_t>(outputStream.tellp());
@ -828,13 +828,13 @@ calculatePadding:
// -> close stream before truncating // -> close stream before truncating
outputStream.close(); outputStream.close();
// -> truncate file // -> truncate file
if (truncate(BasicFileInfo::pathForOpen(fileInfo().path()), static_cast<iostream::off_type>(newSize)) == 0) { if (truncate(BasicFileInfo::pathForOpen(fileInfo().path()).data(), static_cast<iostream::off_type>(newSize)) == 0) {
fileInfo().reportSizeChanged(newSize); fileInfo().reportSizeChanged(newSize);
} else { } else {
diag.emplace_back(DiagLevel::Critical, "Unable to truncate the file.", context); diag.emplace_back(DiagLevel::Critical, "Unable to truncate the file.", context);
} }
// -> reopen the stream again // -> reopen the stream again
outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::in | ios_base::out | ios_base::binary); outputStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::out | ios_base::binary);
} else { } else {
// file is longer after the modification -> just report new size // file is longer after the modification -> just report new size
fileInfo().reportSizeChanged(newSize); fileInfo().reportSizeChanged(newSize);

View File

@ -21,15 +21,15 @@ namespace Mp4TagAtomIds {
* \brief Encapsulates "mean values" used in iTunes style MP4 tags. * \brief Encapsulates "mean values" used in iTunes style MP4 tags.
*/ */
namespace Mp4TagExtendedMeanIds { namespace Mp4TagExtendedMeanIds {
const char *iTunes = "com.apple.iTunes"; std::string_view iTunes = "com.apple.iTunes";
} }
/*! /*!
* \brief Encapsulates "name values" used in iTunes style MP4 tags. * \brief Encapsulates "name values" used in iTunes style MP4 tags.
*/ */
namespace Mp4TagExtendedNameIds { namespace Mp4TagExtendedNameIds {
const char *cdec = "cdec"; std::string_view cdec = "cdec";
const char *label = "LABEL"; std::string_view label = "LABEL";
} // namespace Mp4TagExtendedNameIds } // namespace Mp4TagExtendedNameIds
/*! /*!
@ -322,7 +322,7 @@ namespace Mpeg4ElementaryStreamTypeIds {
/*! /*!
* \brief Returns the name of the stream type denoted by the specified MPEG-4 stream type ID. * \brief Returns the name of the stream type denoted by the specified MPEG-4 stream type ID.
*/ */
const char *streamTypeName(std::uint8_t streamTypeId) std::string_view streamTypeName(std::uint8_t streamTypeId)
{ {
switch (streamTypeId) { switch (streamTypeId) {
case ObjectDescriptor: case ObjectDescriptor:
@ -430,7 +430,7 @@ namespace Mpeg4ChannelConfigs {
/*! /*!
* \brief Returns the string representation for the specified MPEG-4 channel config. * \brief Returns the string representation for the specified MPEG-4 channel config.
*/ */
const char *channelConfigString(std::uint8_t config) std::string_view channelConfigString(std::uint8_t config)
{ {
switch (config) { switch (config) {
case AotSpecificConfig: case AotSpecificConfig:

View File

@ -4,6 +4,7 @@
#include "../global.h" #include "../global.h"
#include <cstdint> #include <cstdint>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -124,12 +125,12 @@ enum KnownValue : std::uint32_t {
} }
namespace Mp4TagExtendedMeanIds { namespace Mp4TagExtendedMeanIds {
extern const char *iTunes; extern std::string_view iTunes;
} }
namespace Mp4TagExtendedNameIds { namespace Mp4TagExtendedNameIds {
extern const char *cdec; extern std::string_view cdec;
extern const char *label; extern std::string_view label;
} // namespace Mp4TagExtendedNameIds } // namespace Mp4TagExtendedNameIds
namespace Mp4MediaTypeIds { namespace Mp4MediaTypeIds {
@ -508,7 +509,7 @@ enum KnownValue : std::uint8_t {
StreamingText StreamingText
}; };
TAG_PARSER_EXPORT const char *streamTypeName(std::uint8_t streamTypeId); TAG_PARSER_EXPORT std::string_view streamTypeName(std::uint8_t streamTypeId);
} // namespace Mpeg4ElementaryStreamTypeIds } // namespace Mpeg4ElementaryStreamTypeIds
@ -623,7 +624,7 @@ enum Mpeg4ChannelConfig : std::uint8_t {
FrontCenterFrontLeftFrontRightSideLeftSideRightBackLeftBackRightLFEChannel FrontCenterFrontLeftFrontRightSideLeftSideRightBackLeftBackRightLFEChannel
}; };
TAG_PARSER_EXPORT const char *channelConfigString(std::uint8_t config); TAG_PARSER_EXPORT std::string_view channelConfigString(std::uint8_t config);
TAG_PARSER_EXPORT std::uint8_t channelCount(std::uint8_t config); TAG_PARSER_EXPORT std::uint8_t channelCount(std::uint8_t config);
} // namespace Mpeg4ChannelConfigs } // namespace Mpeg4ChannelConfigs

View File

@ -35,10 +35,7 @@ Mp4ExtendedFieldId::Mp4ExtendedFieldId(KnownField field)
name = Mp4TagExtendedNameIds::label; name = Mp4TagExtendedNameIds::label;
updateOnly = true; // set record label via extended field only if extended field is already present updateOnly = true; // set record label via extended field only if extended field is already present
break; break;
default: default:;
mean = nullptr;
name = nullptr;
updateOnly = false;
} }
} }
@ -109,7 +106,7 @@ std::vector<const TagValue *> Mp4Tag::values(KnownField field) const
* \remarks * \remarks
* - If there are multiple fields with specified \a mean and \a name only the first value will be returned. * - If there are multiple fields with specified \a mean and \a name only the first value will be returned.
*/ */
const TagValue &Mp4Tag::value(const char *mean, const char *name) const const TagValue &Mp4Tag::value(std::string_view mean, std::string_view name) const
{ {
auto range = fields().equal_range(Mp4TagAtomIds::Extended); auto range = fields().equal_range(Mp4TagAtomIds::Extended);
for (auto i = range.first; i != range.second; ++i) { for (auto i = range.first; i != range.second; ++i) {
@ -301,7 +298,7 @@ bool Mp4Tag::setValues(KnownField field, const std::vector<TagValue> &values)
* - If no field is present, a new one will be created. * - If no field is present, a new one will be created.
* - If \a value is empty, the field will be removed. * - If \a value is empty, the field will be removed.
*/ */
bool Mp4Tag::setValue(const char *mean, const char *name, const TagValue &value) bool Mp4Tag::setValue(std::string_view mean, std::string_view name, const TagValue &value)
{ {
auto range = fields().equal_range(Mp4TagAtomIds::Extended); auto range = fields().equal_range(Mp4TagAtomIds::Extended);
for (auto i = range.first; i != range.second; ++i) { for (auto i = range.first; i != range.second; ++i) {

View File

@ -11,24 +11,24 @@ class Mp4Atom;
class Mp4Tag; class Mp4Tag;
struct TAG_PARSER_EXPORT Mp4ExtendedFieldId { struct TAG_PARSER_EXPORT Mp4ExtendedFieldId {
Mp4ExtendedFieldId(const char *mean = nullptr, const char *name = nullptr, bool updateOnly = false); Mp4ExtendedFieldId(std::string_view mean, std::string_view name, bool updateOnly = false);
Mp4ExtendedFieldId(KnownField field); Mp4ExtendedFieldId(KnownField field);
operator bool() const; operator bool() const;
bool matches(const Mp4TagField &field) const; bool matches(const Mp4TagField &field) const;
/// \brief mean parameter, usually Mp4TagExtendedMeanIds::iTunes /// \brief mean parameter, usually Mp4TagExtendedMeanIds::iTunes
const char *mean; std::string_view mean;
/// \brief name parameter /// \brief name parameter
const char *name; std::string_view name;
/// \brief Whether only existing fields should be updated but *no* new extended field should be created /// \brief Whether only existing fields should be updated but *no* new extended field should be created
bool updateOnly; bool updateOnly = false;
}; };
/*! /*!
* \brief Constructs a new instance with the specified parameter. * \brief Constructs a new instance with the specified parameter.
*/ */
inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(const char *mean, const char *name, bool updateOnly) inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(std::string_view mean, std::string_view name, bool updateOnly)
: mean(mean) : mean(mean)
, name(name) , name(name)
, updateOnly(updateOnly) , updateOnly(updateOnly)
@ -40,7 +40,7 @@ inline Mp4ExtendedFieldId::Mp4ExtendedFieldId(const char *mean, const char *name
*/ */
inline Mp4ExtendedFieldId::operator bool() const inline Mp4ExtendedFieldId::operator bool() const
{ {
return mean && name; return !mean.empty() && !name.empty();
} }
/*! /*!
@ -101,7 +101,7 @@ public:
Mp4Tag(); Mp4Tag();
static constexpr TagType tagType = TagType::Mp4Tag; static constexpr TagType tagType = TagType::Mp4Tag;
static constexpr const char *tagName = "MP4/iTunes tag"; static constexpr std::string_view tagName = "MP4/iTunes tag";
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8; static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
bool canEncodingBeUsed(TagTextEncoding encoding) const override; bool canEncodingBeUsed(TagTextEncoding encoding) const override;
@ -110,14 +110,12 @@ public:
const TagValue &value(KnownField value) const override; const TagValue &value(KnownField value) const override;
using FieldMapBasedTag<Mp4Tag>::values; using FieldMapBasedTag<Mp4Tag>::values;
std::vector<const TagValue *> values(KnownField field) const override; std::vector<const TagValue *> values(KnownField field) const override;
const TagValue &value(const std::string &mean, const std::string &name) const; const TagValue &value(std::string_view mean, std::string_view name) const;
const TagValue &value(const char *mean, const char *name) const;
using FieldMapBasedTag<Mp4Tag>::setValue; using FieldMapBasedTag<Mp4Tag>::setValue;
bool setValue(KnownField field, const TagValue &value) override; bool setValue(KnownField field, const TagValue &value) override;
using FieldMapBasedTag<Mp4Tag>::setValues; using FieldMapBasedTag<Mp4Tag>::setValues;
bool setValues(KnownField field, const std::vector<TagValue> &values) override; bool setValues(KnownField field, const std::vector<TagValue> &values) override;
bool setValue(const std::string &mean, const std::string &name, const TagValue &value); bool setValue(std::string_view mean, std::string_view name, const TagValue &value);
bool setValue(const char *mean, const char *name, const TagValue &value);
using FieldMapBasedTag<Mp4Tag>::hasField; using FieldMapBasedTag<Mp4Tag>::hasField;
bool hasField(KnownField value) const override; bool hasField(KnownField value) const override;
bool supportsMultipleValues(KnownField) const override; bool supportsMultipleValues(KnownField) const override;
@ -149,22 +147,6 @@ inline bool Mp4Tag::supportsField(KnownField field) const
} }
} }
/*!
* \brief Returns the value of the field with the specified \a mean and \a name attributes.
*/
inline const TagValue &Mp4Tag::value(const std::string &mean, const std::string &name) const
{
return value(mean.data(), name.data());
}
/*!
* \brief Assigns the given \a value to the field with the specified \a mean and \a name attributes.
*/
inline bool Mp4Tag::setValue(const std::string &mean, const std::string &name, const TagValue &value)
{
return setValue(mean.data(), name.data(), value);
}
/*! /*!
* \brief Returns false for all fields (for now). * \brief Returns false for all fields (for now).
* \remarks Not sure whether iTunes-style MP4 tags allow this. Let's return false for now. * \remarks Not sure whether iTunes-style MP4 tags allow this. Let's return false for now.

View File

@ -53,7 +53,7 @@ Mp4TagField::Mp4TagField(IdentifierType id, const TagValue &value)
* \sa The last paragraph of <a href="http://atomicparsley.sourceforge.net/mpeg-4files.html">Known iTunes Metadata Atoms</a> * \sa The last paragraph of <a href="http://atomicparsley.sourceforge.net/mpeg-4files.html">Known iTunes Metadata Atoms</a>
* gives additional information about this form of MP4 tag fields. * gives additional information about this form of MP4 tag fields.
*/ */
Mp4TagField::Mp4TagField(const string &mean, const string &name, const TagValue &value) Mp4TagField::Mp4TagField(std::string_view mean, std::string_view name, const TagValue &value)
: Mp4TagField(Mp4TagAtomIds::Extended, value) : Mp4TagField(Mp4TagAtomIds::Extended, value)
{ {
m_name = name; m_name = name;

View File

@ -122,7 +122,7 @@ public:
Mp4TagField(); Mp4TagField();
Mp4TagField(IdentifierType id, const TagValue &value); Mp4TagField(IdentifierType id, const TagValue &value);
Mp4TagField(const std::string &mean, const std::string &name, const TagValue &value); Mp4TagField(std::string_view mean, std::string_view name, const TagValue &value);
void reparse(Mp4Atom &ilstChild, Diagnostics &diag); void reparse(Mp4Atom &ilstChild, Diagnostics &diag);
Mp4TagFieldMaker prepareMaking(Diagnostics &diag); Mp4TagFieldMaker prepareMaking(Diagnostics &diag);
@ -143,7 +143,7 @@ public:
std::uint32_t appropriateRawDataType() const; std::uint32_t appropriateRawDataType() const;
std::uint32_t appropriateRawDataTypeForValue(const TagValue &value) const; std::uint32_t appropriateRawDataTypeForValue(const TagValue &value) const;
static IdentifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static IdentifierType fieldIdFromString(std::string_view idString);
static std::string fieldIdToString(IdentifierType id); static std::string fieldIdToString(IdentifierType id);
private: private:
@ -252,9 +252,9 @@ inline bool Mp4TagField::supportsNestedFields() const
* \remarks The specified \a idString is assumed to be UTF-8 encoded. In order to get the ©-sign * \remarks The specified \a idString is assumed to be UTF-8 encoded. In order to get the ©-sign
* correctly, it is converted to Latin-1. * correctly, it is converted to Latin-1.
*/ */
inline Mp4TagField::IdentifierType Mp4TagField::fieldIdFromString(const char *idString, std::size_t idStringSize) inline Mp4TagField::IdentifierType Mp4TagField::fieldIdFromString(std::string_view idString)
{ {
const auto latin1 = CppUtilities::convertUtf8ToLatin1(idString, idStringSize != std::string::npos ? idStringSize : std::strlen(idString)); const auto latin1 = CppUtilities::convertUtf8ToLatin1(idString.data(), idString.size());
switch (latin1.second) { switch (latin1.second) {
case 4: case 4:
return CppUtilities::BE::toUInt32(latin1.first.get()); return CppUtilities::BE::toUInt32(latin1.first.get());

View File

@ -14,7 +14,7 @@ namespace TagParser {
/*! /*!
* \brief Returns the string representation for the specified \a channelMode. * \brief Returns the string representation for the specified \a channelMode.
*/ */
const char *mpegChannelModeString(MpegChannelMode channelMode) std::string_view mpegChannelModeString(MpegChannelMode channelMode)
{ {
switch (channelMode) { switch (channelMode) {
case MpegChannelMode::Stereo: case MpegChannelMode::Stereo:

View File

@ -5,6 +5,7 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <string_view>
namespace CppUtilities { namespace CppUtilities {
class BinaryReader; class BinaryReader;
@ -23,7 +24,7 @@ enum class MpegChannelMode {
Unspecifed /**< used to indicate that the channel mode is unknown */ Unspecifed /**< used to indicate that the channel mode is unknown */
}; };
TAG_PARSER_EXPORT const char *mpegChannelModeString(MpegChannelMode channelMode); TAG_PARSER_EXPORT std::string_view mpegChannelModeString(MpegChannelMode channelMode);
enum class XingHeaderFlags { enum class XingHeaderFlags {
None = 0x0u, /**< No Xing frames are present */ None = 0x0u, /**< No Xing frames are present */

View File

@ -21,7 +21,7 @@ namespace TagParser {
* \brief Specialization of TagParser::VorbisComment for Vorbis comments inside an OGG stream. * \brief Specialization of TagParser::VorbisComment for Vorbis comments inside an OGG stream.
*/ */
const char *OggVorbisComment::typeName() const std::string_view OggVorbisComment::typeName() const
{ {
switch (m_oggParams.streamFormat) { switch (m_oggParams.streamFormat) {
case GeneralMediaFormat::Flac: case GeneralMediaFormat::Flac:
@ -376,7 +376,7 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback
try { try {
BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, fileInfo().stream(), backupStream); BackupHelper::createBackupFile(fileInfo().backupDirectory(), fileInfo().path(), backupPath, fileInfo().stream(), backupStream);
// recreate original file, define buffer variables // recreate original file, define buffer variables
fileInfo().stream().open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::out | ios_base::binary | ios_base::trunc); fileInfo().stream().open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back( diag.emplace_back(
DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context); DiagLevel::Critical, argsToString("Creation of temporary file (to rewrite the original file) failed: ", failure.what()), context);
@ -386,9 +386,10 @@ void OggContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFeedback
// open the current file as backupStream and create a new outputStream at the specified "save file path" // open the current file as backupStream and create a new outputStream at the specified "save file path"
try { try {
backupStream.exceptions(ios_base::badbit | ios_base::failbit); backupStream.exceptions(ios_base::badbit | ios_base::failbit);
backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()), ios_base::in | ios_base::binary); backupStream.open(BasicFileInfo::pathForOpen(fileInfo().path()).data(), ios_base::in | ios_base::binary);
fileInfo().close(); fileInfo().close();
fileInfo().stream().open(BasicFileInfo::pathForOpen(fileInfo().saveFilePath()), ios_base::out | ios_base::binary | ios_base::trunc); fileInfo().stream().open(
BasicFileInfo::pathForOpen(fileInfo().saveFilePath()).data(), ios_base::out | ios_base::binary | ios_base::trunc);
} catch (const std::ios_base::failure &failure) { } catch (const std::ios_base::failure &failure) {
diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context); diag.emplace_back(DiagLevel::Critical, argsToString("Opening streams to write output file failed: ", failure.what()), context);
throw; throw;

View File

@ -71,9 +71,9 @@ public:
OggVorbisComment(); OggVorbisComment();
static constexpr TagType tagType = TagType::OggVorbisComment; static constexpr TagType tagType = TagType::OggVorbisComment;
static constexpr const char *tagName = "OGG Vorbis comment"; static constexpr std::string_view tagName = "OGG Vorbis comment";
TagType type() const override; TagType type() const override;
const char *typeName() const override; std::string_view typeName() const override;
bool supportsTarget() const override; bool supportsTarget() const override;
OggParameter &oggParams(); OggParameter &oggParams();

View File

@ -101,17 +101,17 @@ enum Sig16 : std::uint16_t {
* \return Returns the container format denoted by the signature. If the * \return Returns the container format denoted by the signature. If the
* signature is unknown ContainerFormat::Unknown is returned. * signature is unknown ContainerFormat::Unknown is returned.
*/ */
ContainerFormat parseSignature(const char *buffer, int bufferSize) ContainerFormat parseSignature(std::string_view buffer)
{ {
// read signature // read signature
std::uint64_t sig = 0; std::uint64_t sig = 0;
if (bufferSize >= 8) { if (buffer.size() >= 8) {
sig = BE::toUInt64(buffer); sig = BE::toUInt64(buffer.data());
} else if (bufferSize >= 4) { } else if (buffer.size() >= 4) {
sig = BE::toUInt32(buffer); sig = BE::toUInt32(buffer.data());
sig <<= 4; sig <<= 4;
} else if (bufferSize >= 2) { } else if (buffer.size() >= 2) {
sig = BE::toUInt16(buffer); sig = BE::toUInt16(buffer.data());
sig <<= 6; sig <<= 6;
} else { } else {
return ContainerFormat::Unknown; return ContainerFormat::Unknown;
@ -127,7 +127,7 @@ ContainerFormat parseSignature(const char *buffer, int bufferSize)
case Png: case Png:
return ContainerFormat::Png; return ContainerFormat::Png;
case YUV4Mpeg2: case YUV4Mpeg2:
if (bufferSize >= 10 && buffer[8] == 0x32 && buffer[9] == 0x20) { if (buffer.size() >= 10 && buffer[8] == 0x32 && buffer[9] == 0x20) {
return ContainerFormat::YUV4Mpeg2; return ContainerFormat::YUV4Mpeg2;
} }
break; break;
@ -178,9 +178,9 @@ ContainerFormat parseSignature(const char *buffer, int bufferSize)
case PhotoshopDocument: case PhotoshopDocument:
return ContainerFormat::PhotoshopDocument; return ContainerFormat::PhotoshopDocument;
case Riff: case Riff:
if (bufferSize >= 16 && BE::toUInt64(buffer + 8) == Sig64::RiffAvi) { if (buffer.size() >= 16 && BE::toUInt64(buffer.data() + 8) == Sig64::RiffAvi) {
return ContainerFormat::RiffAvi; return ContainerFormat::RiffAvi;
} else if (bufferSize >= 12 && BE::toUInt32(buffer + 8) == RiffWave) { } else if (buffer.size() >= 12 && BE::toUInt32(buffer.data() + 8) == RiffWave) {
return ContainerFormat::RiffWave; return ContainerFormat::RiffWave;
} else { } else {
return ContainerFormat::Riff; return ContainerFormat::Riff;
@ -248,7 +248,7 @@ ContainerFormat parseSignature(const char *buffer, int bufferSize)
* \remarks The abbreviation might be used as file extension. * \remarks The abbreviation might be used as file extension.
* \returns Returns an empty string if no abbreviation is available. * \returns Returns an empty string if no abbreviation is available.
*/ */
const char *containerFormatAbbreviation(ContainerFormat containerFormat, MediaType mediaType, unsigned int version) std::string_view containerFormatAbbreviation(ContainerFormat containerFormat, MediaType mediaType, unsigned int version)
{ {
switch (containerFormat) { switch (containerFormat) {
case ContainerFormat::Ac3Frames: case ContainerFormat::Ac3Frames:
@ -370,7 +370,7 @@ const char *containerFormatAbbreviation(ContainerFormat containerFormat, MediaTy
* *
* Returns "unknown" if no name is available. * Returns "unknown" if no name is available.
*/ */
const char *containerFormatName(ContainerFormat containerFormat) std::string_view containerFormatName(ContainerFormat containerFormat)
{ {
switch (containerFormat) { switch (containerFormat) {
case ContainerFormat::Ac3Frames: case ContainerFormat::Ac3Frames:
@ -475,7 +475,7 @@ const char *containerFormatName(ContainerFormat containerFormat)
* *
* Returns an empty string if there is no subversion available. * Returns an empty string if there is no subversion available.
*/ */
const char *containerFormatSubversion(ContainerFormat containerFormat) std::string_view containerFormatSubversion(ContainerFormat containerFormat)
{ {
switch (containerFormat) { switch (containerFormat) {
case ContainerFormat::Gif87a: case ContainerFormat::Gif87a:
@ -496,7 +496,7 @@ const char *containerFormatSubversion(ContainerFormat containerFormat)
* *
* Returns an empty string if there is no MIME-type available. * Returns an empty string if there is no MIME-type available.
*/ */
const char *containerMimeType(ContainerFormat containerFormat, MediaType mediaType) std::string_view containerMimeType(ContainerFormat containerFormat, MediaType mediaType)
{ {
switch (containerFormat) { switch (containerFormat) {
case ContainerFormat::Ac3Frames: case ContainerFormat::Ac3Frames:

View File

@ -4,6 +4,7 @@
#include "./mediaformat.h" #include "./mediaformat.h"
#include <cstdint> #include <cstdint>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -66,15 +67,21 @@ enum class ContainerFormat : unsigned int {
Zip, /**< ZIP archive */ Zip, /**< ZIP archive */
}; };
TAG_PARSER_EXPORT ContainerFormat parseSignature(const char *buffer, int bufferSize); TAG_PARSER_EXPORT ContainerFormat parseSignature(const char *buffer, std::size_t bufferSize);
TAG_PARSER_EXPORT const char *containerFormatName(ContainerFormat containerFormat); TAG_PARSER_EXPORT ContainerFormat parseSignature(std::string_view buffer);
TAG_PARSER_EXPORT const char *containerFormatAbbreviation( TAG_PARSER_EXPORT std::string_view containerFormatName(ContainerFormat containerFormat);
TAG_PARSER_EXPORT std::string_view containerFormatAbbreviation(
ContainerFormat containerFormat, MediaType mediaType = MediaType::Unknown, unsigned int version = 0); ContainerFormat containerFormat, MediaType mediaType = MediaType::Unknown, unsigned int version = 0);
TAG_PARSER_EXPORT const char *containerFormatSubversion(ContainerFormat containerFormat); TAG_PARSER_EXPORT std::string_view containerFormatSubversion(ContainerFormat containerFormat);
TAG_PARSER_EXPORT const char *containerMimeType(ContainerFormat containerFormat, MediaType mediaType = MediaType::Unknown); TAG_PARSER_EXPORT std::string_view containerMimeType(ContainerFormat containerFormat, MediaType mediaType = MediaType::Unknown);
TAG_PARSER_EXPORT TagTargetLevel containerTargetLevel(ContainerFormat containerFormat, std::uint64_t targetLevelValue); TAG_PARSER_EXPORT TagTargetLevel containerTargetLevel(ContainerFormat containerFormat, std::uint64_t targetLevelValue);
TAG_PARSER_EXPORT std::uint64_t containerTargetLevelValue(ContainerFormat containerFormat, TagTargetLevel targetLevel); TAG_PARSER_EXPORT std::uint64_t containerTargetLevelValue(ContainerFormat containerFormat, TagTargetLevel targetLevel);
inline ContainerFormat parseSignature(const char *buffer, std::size_t bufferSize)
{
return parseSignature(std::string_view(buffer, bufferSize));
}
} // namespace TagParser } // namespace TagParser
#endif // TAG_PARSER_SIGNATURE_H #endif // TAG_PARSER_SIGNATURE_H

View File

@ -6,7 +6,7 @@ namespace TagParser {
* \brief Returns an abbreviation for the current instance, eg. 720p for sizes greather than 1280×720 * \brief Returns an abbreviation for the current instance, eg. 720p for sizes greather than 1280×720
* and 1080p for sizes greather than 1920×1080. * and 1080p for sizes greather than 1920×1080.
*/ */
const char *Size::abbreviation() const std::string_view Size::abbreviation() const
{ {
if (*this >= Size(7680, 4320)) { if (*this >= Size(7680, 4320)) {
return "8k"; return "8k";

3
size.h
View File

@ -7,6 +7,7 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <string_view>
namespace TagParser { namespace TagParser {
@ -23,7 +24,7 @@ public:
void setWidth(std::uint32_t value); void setWidth(std::uint32_t value);
void setHeight(std::uint32_t value); void setHeight(std::uint32_t value);
constexpr std::uint32_t resolution() const; constexpr std::uint32_t resolution() const;
const char *abbreviation() const; std::string_view abbreviation() const;
bool constexpr isNull() const; bool constexpr isNull() const;
bool constexpr operator==(const Size &other) const; bool constexpr operator==(const Size &other) const;

10
tag.h
View File

@ -110,7 +110,7 @@ public:
virtual ~Tag(); virtual ~Tag();
virtual TagType type() const; virtual TagType type() const;
virtual const char *typeName() const; virtual std::string_view typeName() const;
std::string toString() const; std::string toString() const;
virtual TagTextEncoding proposedTextEncoding() const; virtual TagTextEncoding proposedTextEncoding() const;
virtual bool canEncodingBeUsed(TagTextEncoding encoding) const; virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
@ -126,7 +126,7 @@ public:
const TagTarget &target() const; const TagTarget &target() const;
void setTarget(const TagTarget &target); void setTarget(const TagTarget &target);
virtual TagTargetLevel targetLevel() const; virtual TagTargetLevel targetLevel() const;
const char *targetLevelName() const; std::string_view targetLevelName() const;
bool isTargetingLevel(TagTargetLevel tagTargetLevel) const; bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
std::string targetString() const; std::string targetString() const;
virtual unsigned int fieldCount() const = 0; virtual unsigned int fieldCount() const = 0;
@ -151,7 +151,7 @@ inline TagType Tag::type() const
return TagType::Unspecified; return TagType::Unspecified;
} }
inline const char *Tag::typeName() const inline std::string_view Tag::typeName() const
{ {
return "unspecified"; return "unspecified";
} }
@ -196,9 +196,9 @@ inline TagTargetLevel Tag::targetLevel() const
return TagTargetLevel::Unspecified; return TagTargetLevel::Unspecified;
} }
inline const char *Tag::targetLevelName() const inline std::string_view Tag::targetLevelName() const
{ {
return supportsTarget() ? tagTargetLevelName(targetLevel()) : nullptr; return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
} }
inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const

View File

@ -14,7 +14,7 @@ namespace TagParser {
/*! /*!
* \brief Returns a string representation for the specified \a tagTargetLevel. * \brief Returns a string representation for the specified \a tagTargetLevel.
*/ */
const char *tagTargetLevelName(TagTargetLevel tagTargetLevel) std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
{ {
switch (tagTargetLevel) { switch (tagTargetLevel) {
case TagTargetLevel::Shot: case TagTargetLevel::Shot:
@ -32,7 +32,7 @@ const char *tagTargetLevelName(TagTargetLevel tagTargetLevel)
case TagTargetLevel::Collection: case TagTargetLevel::Collection:
return "collection"; return "collection";
default: default:
return ""; return std::string_view();
} }
} }
@ -57,15 +57,15 @@ const char *tagTargetLevelName(TagTargetLevel tagTargetLevel)
* \brief Returns the string representation of the current instance. * \brief Returns the string representation of the current instance.
* \remarks Uses the specified \a tagTargetLevel if no levelName() is assigned. * \remarks Uses the specified \a tagTargetLevel if no levelName() is assigned.
*/ */
string TagTarget::toString(TagTargetLevel tagTargetLevel) const std::string TagTarget::toString(TagTargetLevel tagTargetLevel) const
{ {
string levelString; auto levelString = std::string();
if (level()) { if (level()) {
levelString += "level "; levelString += "level ";
levelString += numberToString(level()); levelString += numberToString(level());
} }
const char *defaultLevelName; auto defaultLevelName = std::string_view();
if (!levelName().empty() || *(defaultLevelName = tagTargetLevelName(tagTargetLevel))) { if (!levelName().empty() || !(defaultLevelName = tagTargetLevelName(tagTargetLevel)).empty()) {
if (!levelString.empty()) { if (!levelString.empty()) {
levelString += ' '; levelString += ' ';
} }

View File

@ -15,7 +15,7 @@ namespace TagParser {
*/ */
enum class TagTargetLevel : unsigned char { Unspecified, Shot, Subtrack, Track, Part, Album, Edition, Collection }; enum class TagTargetLevel : unsigned char { Unspecified, Shot, Subtrack, Track, Part, Album, Edition, Collection };
TAG_PARSER_EXPORT const char *tagTargetLevelName(TagTargetLevel tagTargetLevel); TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel);
class TAG_PARSER_EXPORT TagTarget { class TAG_PARSER_EXPORT TagTarget {
public: public:

View File

@ -22,7 +22,7 @@ namespace TagParser {
/*! /*!
* \brief Returns the string representation of the specified \a dataType. * \brief Returns the string representation of the specified \a dataType.
*/ */
const char *tagDataTypeString(TagDataType dataType) std::string_view tagDataTypeString(TagDataType dataType)
{ {
switch (dataType) { switch (dataType) {
case TagDataType::Text: case TagDataType::Text:
@ -655,7 +655,7 @@ void TagValue::toString(string &result, TagTextEncoding encoding) const
const auto genreIndex = toInteger(); const auto genreIndex = toInteger();
if (Id3Genres::isEmptyGenre(genreIndex)) { if (Id3Genres::isEmptyGenre(genreIndex)) {
result.clear(); result.clear();
} else if (const char *genreName = Id3Genres::stringFromIndex(genreIndex)) { } else if (const auto genreName = Id3Genres::stringFromIndex(genreIndex); !genreName.empty()) {
result.assign(genreName); result.assign(genreName);
} else { } else {
throw ConversionException("No string representation for the assigned standard genre index available."); throw ConversionException("No string representation for the assigned standard genre index available.");
@ -739,7 +739,7 @@ void TagValue::toWString(std::u16string &result, TagTextEncoding encoding) const
const auto genreIndex = toInteger(); const auto genreIndex = toInteger();
if (Id3Genres::isEmptyGenre(genreIndex)) { if (Id3Genres::isEmptyGenre(genreIndex)) {
regularStrRes.clear(); regularStrRes.clear();
} else if (const char *genreName = Id3Genres::stringFromIndex(genreIndex)) { } else if (const auto genreName = Id3Genres::stringFromIndex(genreIndex); !genreName.empty()) {
regularStrRes.assign(genreName); regularStrRes.assign(genreName);
} else { } else {
throw ConversionException("No string representation for the assigned standard genre index available."); throw ConversionException("No string representation for the assigned standard genre index available.");

View File

@ -102,6 +102,8 @@ public:
const char *text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified); const char *text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
explicit TagValue( explicit TagValue(
const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified); const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
explicit TagValue(
std::string_view text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
explicit TagValue(int value); explicit TagValue(int value);
explicit TagValue( explicit TagValue(
const char *data, std::size_t length, TagDataType type = TagDataType::Undefined, TagTextEncoding encoding = TagTextEncoding::Latin1); const char *data, std::size_t length, TagDataType type = TagDataType::Undefined, TagTextEncoding encoding = TagTextEncoding::Latin1);
@ -140,10 +142,11 @@ public:
std::size_t dataSize() const; std::size_t dataSize() const;
char *dataPointer(); char *dataPointer();
const char *dataPointer() const; const char *dataPointer() const;
std::string_view data() const;
const std::string &description() const; const std::string &description() const;
void setDescription(const std::string &value, TagTextEncoding encoding = TagTextEncoding::Latin1); void setDescription(std::string_view value, TagTextEncoding encoding = TagTextEncoding::Latin1);
const std::string &mimeType() const; const std::string &mimeType() const;
void setMimeType(const std::string &mimeType); void setMimeType(std::string_view mimeType);
const Locale &locale() const; const Locale &locale() const;
Locale &locale(); Locale &locale();
void setLocale(const Locale &locale); void setLocale(const Locale &locale);
@ -164,6 +167,8 @@ public:
TagTextEncoding convertTo = TagTextEncoding::Unspecified); TagTextEncoding convertTo = TagTextEncoding::Unspecified);
void assignText( void assignText(
const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified); const std::string &text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
void assignText(
std::string_view text, TagTextEncoding textEncoding = TagTextEncoding::Latin1, TagTextEncoding convertTo = TagTextEncoding::Unspecified);
void assignInteger(int value); void assignInteger(int value);
void assignStandardGenreIndex(int index); void assignStandardGenreIndex(int index);
void assignData(const char *data, std::size_t length, TagDataType type = TagDataType::Binary, TagTextEncoding encoding = TagTextEncoding::Latin1); void assignData(const char *data, std::size_t length, TagDataType type = TagDataType::Binary, TagTextEncoding encoding = TagTextEncoding::Latin1);
@ -264,6 +269,22 @@ inline TagValue::TagValue(const std::string &text, TagTextEncoding textEncoding,
assignText(text, textEncoding, convertTo); assignText(text, textEncoding, convertTo);
} }
/*!
* \brief Constructs a new TagValue holding a copy of the given \a text.
* \param text Specifies the text to be assigned.
* \param textEncoding Specifies the encoding of the given \a text.
* \param convertTo Specifies the encoding to convert \a text to; set to TagTextEncoding::Unspecified to
* use \a textEncoding without any character set conversions.
* \throws Throws a ConversionException if the conversion the specified character set fails.
* \remarks Strips the BOM of the specified \a text.
*/
inline TagValue::TagValue(std::string_view text, TagTextEncoding textEncoding, TagTextEncoding convertTo)
: m_descEncoding(TagTextEncoding::Latin1)
, m_flags(TagValueFlags::None)
{
assignText(text, textEncoding, convertTo);
}
/*! /*!
* \brief Constructs a new TagValue holding the given integer \a value. * \brief Constructs a new TagValue holding the given integer \a value.
*/ */
@ -387,6 +408,20 @@ inline void TagValue::assignText(const std::string &text, TagTextEncoding textEn
assignText(text.data(), text.size(), textEncoding, convertTo); assignText(text.data(), text.size(), textEncoding, convertTo);
} }
/*!
* \brief Assigns a copy of the given \a text.
* \param text Specifies the text to be assigned.
* \param textEncoding Specifies the encoding of the given \a text.
* \param convertTo Specifies the encoding to convert \a text to; set to TagTextEncoding::Unspecified to
* use \a textEncoding without any character set conversions.
* \throws Throws a ConversionException if the conversion the specified character set fails.
* \remarks Strips the BOM of the specified \a text.
*/
inline void TagValue::assignText(std::string_view text, TagTextEncoding textEncoding, TagTextEncoding convertTo)
{
assignText(text.data(), text.size(), textEncoding, convertTo);
}
/*! /*!
* \brief Assigns the given PositionInSet \a value. * \brief Assigns the given PositionInSet \a value.
*/ */
@ -542,6 +577,14 @@ inline const char *TagValue::dataPointer() const
return m_ptr.get(); return m_ptr.get();
} }
/*!
* \brief Returns the currently assigned raw data.
*/
inline std::string_view TagValue::data() const
{
return std::string_view(m_ptr.get(), m_size);
}
/*! /*!
* \brief Returns the description. * \brief Returns the description.
* \remarks * \remarks
@ -568,7 +611,7 @@ inline const std::string &TagValue::description() const
* - description() and descriptionEncoding() * - description() and descriptionEncoding()
* - convertDescriptionEncoding() to change the description encoding after assignment * - convertDescriptionEncoding() to change the description encoding after assignment
*/ */
inline void TagValue::setDescription(const std::string &value, TagTextEncoding encoding) inline void TagValue::setDescription(std::string_view value, TagTextEncoding encoding)
{ {
m_desc = value; m_desc = value;
m_descEncoding = encoding; m_descEncoding = encoding;
@ -593,7 +636,7 @@ inline const std::string &TagValue::mimeType() const
* be ignored by the implementation of the tag format if not supported. * be ignored by the implementation of the tag format if not supported.
* \sa mimeType() * \sa mimeType()
*/ */
inline void TagValue::setMimeType(const std::string &mimeType) inline void TagValue::setMimeType(std::string_view mimeType)
{ {
m_mimeType = mimeType; m_mimeType = mimeType;
} }

View File

@ -12,11 +12,11 @@ OverallTests::OverallTests()
*/ */
void OverallTests::setUp() void OverallTests::setUp()
{ {
m_testTitle.assignText("some title", TagTextEncoding::Utf8); m_testTitle.assignText("some title"sv, TagTextEncoding::Utf8);
m_testComment.assignText("some cómment", TagTextEncoding::Utf8); m_testComment.assignText("some cómment"sv, TagTextEncoding::Utf8);
m_testComment.setDescription("some descriptión", TagTextEncoding::Utf8); m_testComment.setDescription("some descriptión"sv, TagTextEncoding::Utf8);
m_testCommentWithoutDescription.assignText("some cómment", TagTextEncoding::Utf8); m_testCommentWithoutDescription.assignText("some cómment"sv, TagTextEncoding::Utf8);
m_testAlbum.assignText("some album", TagTextEncoding::Utf8); m_testAlbum.assignText("some album"sv, TagTextEncoding::Utf8);
m_testPartNumber.assignInteger(41); m_testPartNumber.assignInteger(41);
m_testTotalParts.assignInteger(61); m_testTotalParts.assignInteger(61);
m_testPosition.assignPosition(PositionInSet(41, 61)); m_testPosition.assignPosition(PositionInSet(41, 61));

View File

@ -49,50 +49,50 @@ VorbisComment::IdentifierType VorbisComment::internallyGetFieldId(KnownField fie
using namespace VorbisCommentIds; using namespace VorbisCommentIds;
switch (field) { switch (field) {
case KnownField::Album: case KnownField::Album:
return album(); return std::string(album());
case KnownField::Artist: case KnownField::Artist:
return artist(); return std::string(artist());
case KnownField::Comment: case KnownField::Comment:
return comment(); return std::string(comment());
case KnownField::Cover: case KnownField::Cover:
return cover(); return std::string(cover());
case KnownField::RecordDate: case KnownField::RecordDate:
case KnownField::Year: case KnownField::Year:
return date(); return std::string(date());
case KnownField::Title: case KnownField::Title:
return title(); return std::string(title());
case KnownField::Genre: case KnownField::Genre:
return genre(); return std::string(genre());
case KnownField::TrackPosition: case KnownField::TrackPosition:
return trackNumber(); return std::string(trackNumber());
case KnownField::DiskPosition: case KnownField::DiskPosition:
return diskNumber(); return std::string(diskNumber());
case KnownField::PartNumber: case KnownField::PartNumber:
return partNumber(); return std::string(partNumber());
case KnownField::Composer: case KnownField::Composer:
return composer(); return std::string(composer());
case KnownField::Encoder: case KnownField::Encoder:
return encoder(); return std::string(encoder());
case KnownField::EncoderSettings: case KnownField::EncoderSettings:
return encoderSettings(); return std::string(encoderSettings());
case KnownField::Description: case KnownField::Description:
return description(); return std::string(description());
case KnownField::Grouping: case KnownField::Grouping:
return grouping(); return std::string(grouping());
case KnownField::RecordLabel: case KnownField::RecordLabel:
return label(); return std::string(label());
case KnownField::Performers: case KnownField::Performers:
return performer(); return std::string(performer());
case KnownField::Language: case KnownField::Language:
return language(); return std::string(language());
case KnownField::Lyricist: case KnownField::Lyricist:
return lyricist(); return std::string(lyricist());
case KnownField::Lyrics: case KnownField::Lyrics:
return lyrics(); return std::string(lyrics());
case KnownField::AlbumArtist: case KnownField::AlbumArtist:
return albumArtist(); return std::string(albumArtist());
default: default:
return string(); return std::string();
} }
} }
@ -100,7 +100,7 @@ KnownField VorbisComment::internallyGetKnownField(const IdentifierType &id) cons
{ {
using namespace VorbisCommentIds; using namespace VorbisCommentIds;
// clang-format off // clang-format off
static const map<string, KnownField, CaseInsensitiveStringComparer> fieldMap({ static const std::map<std::string_view, KnownField, CaseInsensitiveStringComparer> fieldMap({
{ album(), KnownField::Album }, { album(), KnownField::Album },
{ artist(), KnownField::Artist }, { artist(), KnownField::Artist },
{ comment(), KnownField::Comment }, { comment(), KnownField::Comment },
@ -185,8 +185,8 @@ template <class StreamType> void VorbisComment::internalParse(StreamType &stream
// turn "YEAR" into "DATE" (unless "DATE" exists) // turn "YEAR" into "DATE" (unless "DATE" exists)
// note: "DATE" is an official field and "YEAR" only an inofficial one but present in some files. In consistency with // note: "DATE" is an official field and "YEAR" only an inofficial one but present in some files. In consistency with
// MediaInfo and VLC player it is treated like "DATE" here. // MediaInfo and VLC player it is treated like "DATE" here.
if (fields().find(VorbisCommentIds::date()) == fields().end()) { if (fields().find(std::string(VorbisCommentIds::date())) == fields().end()) {
const auto [first, end] = fields().equal_range(VorbisCommentIds::year()); const auto [first, end] = fields().equal_range(std::string(VorbisCommentIds::year()));
for (auto i = first; i != end; ++i) { for (auto i = first; i != end; ++i) {
fields().insert(std::pair(VorbisCommentIds::date(), std::move(i->second))); fields().insert(std::pair(VorbisCommentIds::date(), std::move(i->second)));
} }

View File

@ -29,7 +29,7 @@ public:
VorbisComment(); VorbisComment();
static constexpr TagType tagType = TagType::VorbisComment; static constexpr TagType tagType = TagType::VorbisComment;
static constexpr const char *tagName = "Vorbis comment"; static constexpr std::string_view tagName = "Vorbis comment";
static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8; static constexpr TagTextEncoding defaultTextEncoding = TagTextEncoding::Utf8;
bool canEncodingBeUsed(TagTextEncoding encoding) const override; bool canEncodingBeUsed(TagTextEncoding encoding) const override;

View File

@ -58,7 +58,7 @@ public:
bool isAdditionalTypeInfoUsed() const; bool isAdditionalTypeInfoUsed() const;
bool supportsNestedFields() const; bool supportsNestedFields() const;
static typename std::string fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static typename std::string fieldIdFromString(std::string_view idString);
static std::string fieldIdToString(const std::string &id); static std::string fieldIdToString(const std::string &id);
private: private:
@ -85,9 +85,9 @@ inline bool VorbisCommentField::supportsNestedFields() const
* \brief Converts the specified ID string representation to an actual ID. * \brief Converts the specified ID string representation to an actual ID.
* \remarks As Vorbis field IDs are plain text the string is just passed. * \remarks As Vorbis field IDs are plain text the string is just passed.
*/ */
inline std::string VorbisCommentField::fieldIdFromString(const char *idString, std::size_t idStringSize) inline std::string VorbisCommentField::fieldIdFromString(std::string_view idString)
{ {
return idStringSize != std::string::npos ? std::string(idString, idStringSize) : std::string(idString); return std::string(idString);
} }
/*! /*!

View File

@ -3,6 +3,8 @@
#include "../global.h" #include "../global.h"
#include <string_view>
namespace TagParser { namespace TagParser {
/*! /*!
@ -11,163 +13,163 @@ namespace TagParser {
*/ */
namespace VorbisCommentIds { namespace VorbisCommentIds {
constexpr TAG_PARSER_EXPORT const char *trackNumber() constexpr TAG_PARSER_EXPORT std::string_view trackNumber()
{ {
return "TRACKNUMBER"; return "TRACKNUMBER";
} }
constexpr TAG_PARSER_EXPORT const char *diskNumber() constexpr TAG_PARSER_EXPORT std::string_view diskNumber()
{ {
return "DISCNUMBER"; return "DISCNUMBER";
} }
constexpr TAG_PARSER_EXPORT const char *part() constexpr TAG_PARSER_EXPORT std::string_view part()
{ {
return "PART"; return "PART";
} }
constexpr TAG_PARSER_EXPORT const char *partNumber() constexpr TAG_PARSER_EXPORT std::string_view partNumber()
{ {
return "PARTNUMBER"; return "PARTNUMBER";
} }
constexpr TAG_PARSER_EXPORT const char *title() constexpr TAG_PARSER_EXPORT std::string_view title()
{ {
return "TITLE"; return "TITLE";
} }
constexpr TAG_PARSER_EXPORT const char *version() constexpr TAG_PARSER_EXPORT std::string_view version()
{ {
return "VERSION"; return "VERSION";
} }
constexpr TAG_PARSER_EXPORT const char *artist() constexpr TAG_PARSER_EXPORT std::string_view artist()
{ {
return "ARTIST"; return "ARTIST";
} }
constexpr TAG_PARSER_EXPORT const char *albumArtist() constexpr TAG_PARSER_EXPORT std::string_view albumArtist()
{ {
return "ALBUMARTIST"; return "ALBUMARTIST";
} }
constexpr TAG_PARSER_EXPORT const char *grouping() constexpr TAG_PARSER_EXPORT std::string_view grouping()
{ {
return "GROUPING"; return "GROUPING";
} }
constexpr TAG_PARSER_EXPORT const char *album() constexpr TAG_PARSER_EXPORT std::string_view album()
{ {
return "ALBUM"; return "ALBUM";
} }
constexpr TAG_PARSER_EXPORT const char *label() constexpr TAG_PARSER_EXPORT std::string_view label()
{ {
return "LABEL"; return "LABEL";
} }
constexpr TAG_PARSER_EXPORT const char *labelNo() constexpr TAG_PARSER_EXPORT std::string_view labelNo()
{ {
return "LABELNO"; return "LABELNO";
} }
constexpr TAG_PARSER_EXPORT const char *language() constexpr TAG_PARSER_EXPORT std::string_view language()
{ {
return "LANGUAGE"; return "LANGUAGE";
} }
constexpr TAG_PARSER_EXPORT const char *performer() constexpr TAG_PARSER_EXPORT std::string_view performer()
{ {
return "PERFORMER"; return "PERFORMER";
} }
constexpr TAG_PARSER_EXPORT const char *composer() constexpr TAG_PARSER_EXPORT std::string_view composer()
{ {
return "COMPOSER"; return "COMPOSER";
} }
constexpr TAG_PARSER_EXPORT const char *ensemble() constexpr TAG_PARSER_EXPORT std::string_view ensemble()
{ {
return "ENSEMBLE"; return "ENSEMBLE";
} }
constexpr TAG_PARSER_EXPORT const char *arranger() constexpr TAG_PARSER_EXPORT std::string_view arranger()
{ {
return "ARRANGER"; return "ARRANGER";
} }
constexpr TAG_PARSER_EXPORT const char *lyricist() constexpr TAG_PARSER_EXPORT std::string_view lyricist()
{ {
return "LYRICIST"; return "LYRICIST";
} }
constexpr TAG_PARSER_EXPORT const char *lyrics() constexpr TAG_PARSER_EXPORT std::string_view lyrics()
{ {
return "LYRICS"; return "LYRICS";
} }
constexpr TAG_PARSER_EXPORT const char *author() constexpr TAG_PARSER_EXPORT std::string_view author()
{ {
return "AUTHOR"; return "AUTHOR";
} }
constexpr TAG_PARSER_EXPORT const char *conductor() constexpr TAG_PARSER_EXPORT std::string_view conductor()
{ {
return "CONDUCTOR"; return "CONDUCTOR";
} }
constexpr TAG_PARSER_EXPORT const char *encoder() constexpr TAG_PARSER_EXPORT std::string_view encoder()
{ {
return "ENCODER"; return "ENCODER";
} }
constexpr TAG_PARSER_EXPORT const char *encoderSettings() constexpr TAG_PARSER_EXPORT std::string_view encoderSettings()
{ {
return "ENCODER_OPTIONS"; return "ENCODER_OPTIONS";
} }
constexpr TAG_PARSER_EXPORT const char *publisher() constexpr TAG_PARSER_EXPORT std::string_view publisher()
{ {
return "PUBLISHER"; return "PUBLISHER";
} }
constexpr TAG_PARSER_EXPORT const char *genre() constexpr TAG_PARSER_EXPORT std::string_view genre()
{ {
return "GENRE"; return "GENRE";
} }
constexpr TAG_PARSER_EXPORT const char *originalMediaType() constexpr TAG_PARSER_EXPORT std::string_view originalMediaType()
{ {
return "ORIGINAL_TAG_PARSER_TYPE"; return "ORIGINAL_TAG_PARSER_TYPE";
} }
constexpr TAG_PARSER_EXPORT const char *contentType() constexpr TAG_PARSER_EXPORT std::string_view contentType()
{ {
return "CONTENT_TYPE"; return "CONTENT_TYPE";
} }
constexpr TAG_PARSER_EXPORT const char *subject() constexpr TAG_PARSER_EXPORT std::string_view subject()
{ {
return "SUBJECT"; return "SUBJECT";
} }
constexpr TAG_PARSER_EXPORT const char *description() constexpr TAG_PARSER_EXPORT std::string_view description()
{ {
return "DESCRIPTION"; return "DESCRIPTION";
} }
constexpr TAG_PARSER_EXPORT const char *isrc() constexpr TAG_PARSER_EXPORT std::string_view isrc()
{ {
return "ISRC"; return "ISRC";
} }
constexpr TAG_PARSER_EXPORT const char *eanupn() constexpr TAG_PARSER_EXPORT std::string_view eanupn()
{ {
return "EAN/UPN"; return "EAN/UPN";
} }
constexpr TAG_PARSER_EXPORT const char *comment() constexpr TAG_PARSER_EXPORT std::string_view comment()
{ {
return "COMMENT"; return "COMMENT";
} }
constexpr TAG_PARSER_EXPORT const char *date() constexpr TAG_PARSER_EXPORT std::string_view date()
{ {
return "DATE"; return "DATE";
} }
constexpr TAG_PARSER_EXPORT const char *year() constexpr TAG_PARSER_EXPORT std::string_view year()
{ {
return "YEAR"; // not mentioned in https://xiph.org/vorbis/doc/v-comment.html but seen in the wild return "YEAR"; // not mentioned in https://xiph.org/vorbis/doc/v-comment.html but seen in the wild
} }
constexpr TAG_PARSER_EXPORT const char *location() constexpr TAG_PARSER_EXPORT std::string_view location()
{ {
return "LOCATION"; return "LOCATION";
} }
constexpr TAG_PARSER_EXPORT const char *license() constexpr TAG_PARSER_EXPORT std::string_view license()
{ {
return "LICENSE"; return "LICENSE";
} }
constexpr TAG_PARSER_EXPORT const char *copyright() constexpr TAG_PARSER_EXPORT std::string_view copyright()
{ {
return "COPYRIGHT"; return "COPYRIGHT";
} }
constexpr TAG_PARSER_EXPORT const char *opus() constexpr TAG_PARSER_EXPORT std::string_view opus()
{ {
return "OPUS"; return "OPUS";
} }
constexpr TAG_PARSER_EXPORT const char *sourceMedia() constexpr TAG_PARSER_EXPORT std::string_view sourceMedia()
{ {
return "SOURCEMEDIA"; return "SOURCEMEDIA";
} }
constexpr TAG_PARSER_EXPORT const char *cover() constexpr TAG_PARSER_EXPORT std::string_view cover()
{ {
return "METADATA_BLOCK_PICTURE"; return "METADATA_BLOCK_PICTURE";
} }