mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Removed a utility function which is used only at one place.
This commit is contained in:
parent
56cd3695f7
commit
9d58e9f8e8
@ -47,23 +47,23 @@ using namespace APE;
|
||||
|
||||
namespace
|
||||
{
|
||||
bool isKeyValid(const char *key, size_t length)
|
||||
const unsigned int MinKeyLength = 2;
|
||||
const unsigned int MaxKeyLength = 255;
|
||||
|
||||
bool isKeyValid(const ByteVector &key)
|
||||
{
|
||||
const char *invalidKeys[] = { "ID3", "TAG", "OGGS", "MP+", 0 };
|
||||
|
||||
if(length < 2 || length > 255)
|
||||
return false;
|
||||
|
||||
// only allow printable ASCII including space (32..126)
|
||||
|
||||
for(const char *p = key; p < key + length; ++p) {
|
||||
const int c = static_cast<unsigned char>(*p);
|
||||
for(ByteVector::ConstIterator it = key.begin(); it != key.end(); ++it) {
|
||||
const int c = static_cast<unsigned char>(*it);
|
||||
if(c < 32 || c > 126)
|
||||
return false;
|
||||
}
|
||||
|
||||
for(size_t i = 0; invalidKeys[i] != 0; ++i) {
|
||||
if(Utils::equalsIgnoreCase(key, invalidKeys[i]))
|
||||
if(String(key).upper() == invalidKeys[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -296,11 +296,10 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps)
|
||||
|
||||
bool APE::Tag::checkKey(const String &key)
|
||||
{
|
||||
if(!key.isLatin1())
|
||||
if(key.size() < MinKeyLength || key.size() > MaxKeyLength)
|
||||
return false;
|
||||
|
||||
const std::string data = key.to8Bit(false);
|
||||
return isKeyValid(data.c_str(), data.size());
|
||||
return isKeyValid(key.data(String::Latin1));
|
||||
}
|
||||
|
||||
APE::Footer *APE::Tag::footer() const
|
||||
@ -419,7 +418,10 @@ void APE::Tag::parse(const ByteVector &data)
|
||||
const unsigned int keyLength = nullPos - pos - 8;
|
||||
const unsigned int valLegnth = data.toUInt(pos, false);
|
||||
|
||||
if(isKeyValid(&data[pos + 8], keyLength)){
|
||||
if(keyLength >= MinKeyLength
|
||||
&& keyLength <= MaxKeyLength
|
||||
&& isKeyValid(data.mid(pos + 8, keyLength)))
|
||||
{
|
||||
APE::Item item;
|
||||
item.parse(data.mid(pos));
|
||||
|
||||
|
@ -221,35 +221,6 @@ namespace TagLib
|
||||
return String();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Converts the letter c to lower case, not depending on the locale.
|
||||
*/
|
||||
inline int toLowerCase(char c)
|
||||
{
|
||||
if('A' <= c && c <= 'Z')
|
||||
return c + ('a' - 'A');
|
||||
else
|
||||
return c;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns whether the two strings s1 and s2 are equal, ignoring the case
|
||||
* of the characters. This only supports US-ASCII and does not depend on
|
||||
* the current locale.
|
||||
*
|
||||
* We took the trouble to define this one here, since there are some
|
||||
* incompatible variations of case insensitive strcmp().
|
||||
*/
|
||||
inline bool equalsIgnoreCase(const char *s1, const char *s2)
|
||||
{
|
||||
while(*s1 != '\0' && *s2 != '\0' && toLowerCase(*s1) == toLowerCase(*s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (*s1 == '\0' && *s2 == '\0');
|
||||
}
|
||||
|
||||
/*!
|
||||
* The types of byte order of the running system.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user