]> granicus.if.org Git - taglib/commitdiff
Removed a utility function which is used only at one place.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 8 Nov 2016 14:27:55 +0000 (23:27 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Tue, 8 Nov 2016 14:27:55 +0000 (23:27 +0900)
taglib/ape/apetag.cpp
taglib/toolkit/tutils.h

index 89ef8ff41a625460907daac124536fe7316471b0..359fc302ed5cdf0ffcf3f1c9078ee07891e340ee 100644 (file)
@@ -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));
 
index 365cfcab205308eface4fdf59f81acb6fd533c8b..d4051f642e2e0eb201541603304d6f38ec90b5d7 100644 (file)
@@ -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.
        */