diff --git a/src/cli.cc b/src/cli.cc index cf0f45f..54cea4a 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -56,6 +56,9 @@ static struct option getopt_options[] = { ot::status ot::parse_options(int argc, char** argv, ot::options& opt) { + static ot::encoding_converter to_utf8("", "UTF-8"); + std::string utf8; + ot::status rc; opt = {}; if (argc == 1) return {st::bad_arguments, "No arguments specified. Use -h for help."}; @@ -81,17 +84,23 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt) opt.overwrite = true; break; case 'd': - if (strchr(optarg, '=') != nullptr) + rc = to_utf8(optarg, strlen(optarg), utf8); + if (rc != ot::st::ok) + return {st::bad_arguments, "Could not encode argument into UTF-8: " + rc.message}; + if (strchr(utf8.c_str(), '=') != nullptr) return {st::bad_arguments, "Invalid field name '"s + optarg + "'."}; - opt.to_delete.emplace_back(optarg); + opt.to_delete.emplace_back(std::move(utf8)); break; case 'a': case 's': - if (strchr(optarg, '=') == NULL) + rc = to_utf8(optarg, strlen(optarg), utf8); + if (rc != ot::st::ok) + return {st::bad_arguments, "Could not encode argument into UTF-8: " + rc.message}; + if (strchr(utf8.c_str(), '=') == NULL) return {st::bad_arguments, "Invalid comment '"s + optarg + "'."}; - opt.to_add.emplace_back(optarg); if (c == 's') - opt.to_delete.emplace_back(optarg); + opt.to_delete.emplace_back(utf8); + opt.to_add.emplace_back(std::move(utf8)); break; case 'S': opt.set_all = true; diff --git a/src/opustags.h b/src/opustags.h index d9db029..94772f7 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -400,6 +400,8 @@ struct options { * #to_add takes precedence over #to_delete, so if the same comment appears in both lists, * the one in #to_delete applies only to the previously existing tags. * + * The strings are stored in UTF-8. + * * \todo Consider making it case-insensitive. * \todo Allow values like `ARTIST=x` to delete only the ARTIST comment whose value is x. * @@ -416,6 +418,8 @@ struct options { * List of comments to add, in the current system encoding. For exemple `TITLE=a b c`. They * must be valid. * + * The strings are stored in UTF-8. + * * Options: --add, --set, --set-all */ std::vector to_add;