move delete_comments into cli

This commit is contained in:
Frédéric Mangano-Tarumi 2018-12-16 18:44:08 -05:00
parent 6797e59417
commit f872f71411
3 changed files with 22 additions and 23 deletions

View File

@ -205,6 +205,19 @@ ot::status ot::read_comments(FILE* input, std::list<std::string>& comments)
return ot::st::ok;
}
void ot::delete_comments(std::list<std::string>& comments, const std::string& field_name)
{
auto field_len = field_name.size();
auto it = comments.begin(), end = comments.end();
while (it != end) {
auto current = it++;
if (current->size() > field_len + 1 &&
(*current)[field_len] == '=' &&
strncmp(current->data(), field_name.data(), field_len) == 0)
comments.erase(current);
}
}
/** Apply the modifications requested by the user to the opustags packet. */
static ot::status edit_tags(ot::opus_tags& tags, const ot::options& opt)
{
@ -215,7 +228,7 @@ static ot::status edit_tags(ot::opus_tags& tags, const ot::options& opt)
} else if (opt.delete_all) {
tags.comments.clear();
} else for (const std::string& name : opt.to_delete) {
ot::delete_comments(tags, name.c_str());
ot::delete_comments(tags.comments, name.c_str());
}
for (const std::string& comment : opt.to_add)

View File

@ -121,16 +121,3 @@ ot::dynamic_ogg_packet ot::render_tags(const opus_tags& tags)
return op;
}
void ot::delete_comments(opus_tags& tags, const std::string& field_name)
{
auto field_len = field_name.size();
auto it = tags.comments.begin(), end = tags.comments.end();
while (it != end) {
auto current = it++;
if (current->size() > field_len + 1 &&
(*current)[field_len] == '=' &&
strncmp(current->data(), field_name.data(), field_len) == 0)
tags.comments.erase(current);
}
}

View File

@ -356,15 +356,6 @@ status parse_tags(const ogg_packet& packet, opus_tags& tags);
*/
dynamic_ogg_packet render_tags(const opus_tags& tags);
/**
* Remove all the comments whose field name is equal to the special one, case-sensitive.
*
* \todo Become case-insensitive.
* \todo Move to module cli.
* \todo Accept fields like X=Y to remove only comments X=Y, instead of all X.
*/
void delete_comments(opus_tags& tags, const std::string& field_name);
/** \} */
/***********************************************************************************************//**
@ -468,6 +459,14 @@ void print_comments(const std::list<std::string>& comments, FILE* output);
*/
status read_comments(FILE* input, std::list<std::string>& comments);
/**
* Remove all the comments whose field name is equal to the special one, case-sensitive.
*
* \todo Become case-insensitive.
* \todo Accept fields like X=Y to remove only comments X=Y, instead of all X.
*/
void delete_comments(std::list<std::string>& comments, const std::string& field_name);
/**
* Main entry point to the opustags program, and pretty much the same as calling opustags from the
* command-line.