From 9d58e9f8e8e8734a331b69d4038c981d7351c132 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 8 Nov 2016 23:27:55 +0900 Subject: [PATCH] Removed a utility function which is used only at one place. --- taglib/ape/apetag.cpp | 24 +++++++++++++----------- taglib/toolkit/tutils.h | 29 ----------------------------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 89ef8ff4..359fc302 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -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(*p); + for(ByteVector::ConstIterator it = key.begin(); it != key.end(); ++it) { + const int c = static_cast(*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)); diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index 365cfcab..d4051f64 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -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. */ -- 2.40.0