mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 20:53:16 +01:00
reduce match_field into delete_comments
This commit is contained in:
parent
7df8c5c426
commit
6797e59417
23
src/opus.cc
23
src/opus.cc
@ -122,28 +122,15 @@ ot::dynamic_ogg_packet ot::render_tags(const opus_tags& tags)
|
||||
return op;
|
||||
}
|
||||
|
||||
/**
|
||||
* \todo Make the field name case-insensitive?
|
||||
*/
|
||||
static int match_field(const char *comment, uint32_t len, const char *field)
|
||||
{
|
||||
size_t field_len;
|
||||
for (field_len = 0; field[field_len] != '\0' && field[field_len] != '='; field_len++);
|
||||
if (len <= field_len)
|
||||
return 0;
|
||||
if (comment[field_len] != '=')
|
||||
return 0;
|
||||
if (strncmp(comment, field, field_len) != 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ot::delete_comments(opus_tags& tags, const char* field_name)
|
||||
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 (match_field(current->data(), current->size(), field_name))
|
||||
if (current->size() > field_len + 1 &&
|
||||
(*current)[field_len] == '=' &&
|
||||
strncmp(current->data(), field_name.data(), field_len) == 0)
|
||||
tags.comments.erase(current);
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ dynamic_ogg_packet render_tags(const opus_tags& tags);
|
||||
* \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 char* field_name);
|
||||
void delete_comments(opus_tags& tags, const std::string& field_name);
|
||||
|
||||
/** \} */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user