From a4df286667e4e3369abc37942ee2e16bb32584b2 Mon Sep 17 00:00:00 2001 From: Zereges Date: Thu, 22 Aug 2024 15:31:02 +0200 Subject: [PATCH] Some random cleanup and targetting of new version of taglib --- README.md | 2 +- id3-tags-cli.sln | 4 ++-- id3-tags-cli.vcxproj | 6 +++--- src/arguments.hpp | 26 ++++++++++++++------------ src/help.hpp | 4 ++-- src/main.cpp | 12 +++++++----- src/platform.hpp | 4 +--- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c514a07..bd8a383 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Usage: id3-tags-cli [options] file [STR] - String type [INT] - Integer type - If no argument is specified, information of given file is retrieved. + If no arguments are specified, information of given file is retrieved. If the option is not specified, the value is unchanged. If the argument is empty string ("") (for [STR]) or 0 (for [INT]) the value is cleared. diff --git a/id3-tags-cli.sln b/id3-tags-cli.sln index 37487b3..5fb45e0 100644 --- a/id3-tags-cli.sln +++ b/id3-tags-cli.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.136 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "id3-tags-cli", "id3-tags-cli.vcxproj", "{2F93CC68-3189-4099-9E02-9CD5394305B5}" EndProject diff --git a/id3-tags-cli.vcxproj b/id3-tags-cli.vcxproj index 9a25da7..fa2641c 100644 --- a/id3-tags-cli.vcxproj +++ b/id3-tags-cli.vcxproj @@ -14,19 +14,19 @@ 15.0 {2f93cc68-3189-4099-9e02-9cd5394305b5} id3_tags_cli - 10.0.17763.0 + 10.0 Application true - v141 + v143 Unicode Application false - v141 + v143 true Unicode diff --git a/src/arguments.hpp b/src/arguments.hpp index d993f3b..0a5f9b0 100644 --- a/src/arguments.hpp +++ b/src/arguments.hpp @@ -1,7 +1,7 @@ -#pragma once +// ReSharper disable CppClangTidyConcurrencyMtUnsafe +#pragma once #include #include -#include #include @@ -48,9 +48,11 @@ class arguments static arguments parse_args(int argc, std::vector& arg_vector) { std::vector argv; + argv.reserve(argc); for (int i = 0; i < argc; ++i) argv.push_back(arg_vector[i].data()); - argv.push_back(nullptr); + + opterr = 0; // getopt segfaults while trying to print an error arguments args{false, false}; for (;;) @@ -119,47 +121,47 @@ class arguments return args; } - bool is_help() const + [[nodiscard]] bool is_help() const { return m_help; } - bool is_version() const + [[nodiscard]] bool is_version() const { return m_version; } - const std::string& file_name() const + [[nodiscard]] const std::string& file_name() const { return m_file_name; } - std::pair artist() const + [[nodiscard]] std::pair artist() const { return { m_artist.has_value(), m_artist.value_or("") }; } - std::pair title() const + [[nodiscard]] std::pair title() const { return { m_title.has_value(), m_title.value_or("") }; } - std::pair album() const + [[nodiscard]] std::pair album() const { return { m_album.has_value(), m_album.value_or("") }; } - std::pair year() const + [[nodiscard]] std::pair year() const { return { m_year.has_value(), m_year.value_or("") }; } - std::pair track() const + [[nodiscard]] std::pair track() const { return { m_track.has_value(), m_track.value_or("") }; } - std::pair genre() const + [[nodiscard]] std::pair genre() const { return { m_genre.has_value(), m_genre.value_or("") }; } diff --git a/src/help.hpp b/src/help.hpp index fe4ed40..3566532 100644 --- a/src/help.hpp +++ b/src/help.hpp @@ -3,7 +3,7 @@ #include #include -constexpr static const int VERSION = 100; +constexpr static int VERSION = 110; inline void print_usage(std::ostream& stream, const std::string& exe_name) { @@ -39,7 +39,7 @@ inline void print_help(const std::string& exe_name) << " " << "[STR] - String type" << "\n" << " " << "[INT] - Integer type" << "\n" << "\n" - << " " << "If no argument is specified, information of given file is retrieved." << "\n" + << " " << "If no arguments are specified, information of given file is retrieved." << "\n" << " " << "If the option is not specified, the value is unchanged." << "\n" << " " << "If the argument is empty string (\"\") (for [STR]) or 0 (for [INT]) the value is cleared." << "\n" << "\n" diff --git a/src/main.cpp b/src/main.cpp index f16728b..eaab46a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ void print_field(const std::string& field_name, const T& field_value) std::cout << field_name << ": " << field_value << std::endl; } -bool process_file(arguments&& args) +bool process_file(const arguments& args) { platform::string file_name = platform::convert::to_platform(args.file_name()); TagLib::FileRef file(file_name.c_str()); @@ -41,17 +41,19 @@ bool process_file(arguments&& args) TagLib::Tag& tag = *file.tag(); + /* auto [artist_valid, artist] = args.artist(); auto [title_valid, title] = args.title(); auto [album_valid, album] = args.album(); auto [year_valid, year] = args.year(); auto [track_valid, track] = args.track(); auto [genre_valid, genre] = args.genre(); + */ auto utf8string = [](const std::string& str) { if (str.empty()) - return TagLib::String::null; + return TagLib::String{}; return TagLib::String(str, TagLib::String::Type::UTF8); }; @@ -86,8 +88,8 @@ bool process_file(arguments&& args) return true; } -constexpr static const int RETURN_OK = 0; -constexpr static const int RETURN_ERROR = 1; +constexpr static int RETURN_OK = 0; +constexpr static int RETURN_ERROR = 1; int MAIN(int argc, platform::char_t* argv[]) { @@ -117,7 +119,7 @@ int MAIN(int argc, platform::char_t* argv[]) return RETURN_OK; } - if (!process_file(std::move(args.value()))) + if (!process_file(args.value())) { std::cerr << "Couldn't process given file" << std::endl; print_usage(std::cerr, exe_name); diff --git a/src/platform.hpp b/src/platform.hpp index 91de5c6..dc1d136 100644 --- a/src/platform.hpp +++ b/src/platform.hpp @@ -1,8 +1,6 @@ #pragma once #include #include -#include -#include #ifdef _MSC_VER #define TAGLIB_HEADERS_BEGIN __pragma(warning(disable: 4251)) @@ -18,7 +16,6 @@ #ifdef _MSC_VER #include - #include #include #define MAIN wmain #else @@ -54,6 +51,7 @@ namespace platform static std::vector convert_args(int argc, platform::char_t** argv) { std::vector args; + args.reserve(argc); for (int i = 0; i < argc; ++i) args.push_back(from_platform(argv[i])); return args;