case-insensitive field name for comment deletion

This commit is contained in:
Frédéric Mangano-Tarumi 2018-12-16 18:56:18 -05:00
parent a9adc11cad
commit e2a1c06005
4 changed files with 4 additions and 5 deletions

View File

@ -68,8 +68,8 @@ Use \fB-y\fP to allow overwriting.
Note that this option is not needed when the output is a special file like \fI/dev/null\fP.
.TP
.B \-d, \-\-delete \fIFIELD\fP
Delete all the tags whose field name is \fIFIELD\fP. They may be several one of them, though usually
there is only one of each type.
Delete all the tags whose field name is \fIFIELD\fP. The field names are case-insensitive, and
expected to be ASCII.
.TP
.B \-a, \-\-add \fIFIELD=VALUE\fP
Add a tag. Note that multiple tags with the same field name are perfectly acceptable, so you can add

View File

@ -213,7 +213,7 @@ void ot::delete_comments(std::list<std::string>& comments, const std::string& fi
auto current = it++;
if (current->size() > field_len + 1 &&
(*current)[field_len] == '=' &&
strncmp(current->data(), field_name.data(), field_len) == 0)
strncasecmp(current->data(), field_name.data(), field_len) == 0)
comments.erase(current);
}
}

View File

@ -462,7 +462,6 @@ 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);

View File

@ -104,7 +104,7 @@ static void check_delete_comments()
throw failure("should not have deleted anything");
ot::delete_comments(edited, "Title");
C expected = {"TITLE=X", "ARTIST=A", "artIst=B"};
C expected = {"ARTIST=A", "artIst=B"};
if (!std::equal(edited.begin(), edited.end(), expected.begin(), expected.end()))
throw failure("did not delete Title correctly");
}