From 7206604f858617962b793ca22ff3bc0bcba0c7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 11 Oct 2020 17:21:54 +0200 Subject: [PATCH] Make read_comments work on std::list For consistency with ot::opus_tags. --- src/cli.cc | 8 +++----- src/opustags.h | 4 ++-- t/cli.cc | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index be62846..27ead5d 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -138,13 +138,11 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt, FILE* comm if (set_all) { // Read comments from stdin and prepend them to opt.to_add. - std::vector comments; + std::list comments; auto rc = read_comments(comments_input, comments); if (rc != st::ok) return rc; - comments.reserve(comments.size() + opt.to_add.size()); - std::move(opt.to_add.begin(), opt.to_add.end(), std::back_inserter(comments)); - opt.to_add = std::move(comments); + opt.to_add.splice(opt.to_add.begin(), std::move(comments)); } return st::ok; } @@ -192,7 +190,7 @@ void ot::print_comments(const std::list& comments, FILE* output) fputs("warning: Some tags contain control characters.\n", stderr); } -ot::status ot::read_comments(FILE* input, std::vector& comments) +ot::status ot::read_comments(FILE* input, std::list& comments) { static ot::encoding_converter to_utf8("", "UTF-8"); comments.clear(); diff --git a/src/opustags.h b/src/opustags.h index f9d9240..14f280d 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -430,7 +430,7 @@ struct options { * * Options: --add, --set, --set-all */ - std::vector to_add; + std::list to_add; }; /** @@ -456,7 +456,7 @@ void print_comments(const std::list& comments, FILE* output); * * The comments are converted from the system encoding to UTF-8, and returned as UTF-8. */ -status read_comments(FILE* input, std::vector& comments); +status read_comments(FILE* input, std::list& comments); /** * Remove all comments matching the specified selector, which may either be a field name or a diff --git a/t/cli.cc b/t/cli.cc index 96231bf..cd78a66 100644 --- a/t/cli.cc +++ b/t/cli.cc @@ -7,7 +7,7 @@ using namespace std::literals::string_literals; void check_read_comments() { - std::vector comments; + std::list comments; ot::status rc; { std::string txt = "TITLE=a b c\n\nARTIST=X\nArtist=Y\n"s; @@ -72,13 +72,13 @@ void check_good_arguments() if (opt.paths_in.size() != 1 || opt.paths_in.front() != "x" || !opt.path_out || opt.path_out != "y" || !opt.delete_all || opt.overwrite || opt.to_delete.size() != 2 || opt.to_delete[0] != "X" || opt.to_delete[1] != "a=b" || - opt.to_add.size() != 1 || opt.to_add[0] != "X=Y Z") + opt.to_add != std::list{"X=Y Z"}) throw failure("unexpected option parsing result for case #1"); opt = parse({"opustags", "-S", "x", "-S", "-a", "x=y z", "-i"}); if (opt.paths_in.size() != 1 || opt.paths_in.front() != "x" || opt.path_out || !opt.overwrite || opt.to_delete.size() != 0 || - opt.to_add.size() != 2 || opt.to_add[0] != "N=1" || opt.to_add[1] != "x=y z") + opt.to_add != std::list{"N=1", "x=y z"}) throw failure("unexpected option parsing result for case #2"); opt = parse({"opustags", "-i", "x", "y", "z"});