mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 20:53:16 +01:00
convert command-line arguments to UTF-8 too
This commit is contained in:
parent
cc3bb6397d
commit
e471c82605
19
src/cli.cc
19
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;
|
||||
|
@ -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<std::string> to_add;
|
||||
|
Loading…
x
Reference in New Issue
Block a user