[cstdstring] remove GetLength()
authorJonathan Marshall <jmarshall@xbmc.org>
Sun, 27 Oct 2013 01:35:32 +0000 (14:35 +1300)
committerJonathan Marshall <jmarshall@xbmc.org>
Wed, 13 Nov 2013 21:52:59 +0000 (10:52 +1300)
20 files changed:
xbmc/Util.cpp
xbmc/cores/DllLoader/Win32DllLoader.cpp
xbmc/dialogs/GUIDialogKeyboardGeneric.cpp
xbmc/filesystem/DirectoryCache.cpp
xbmc/filesystem/SlingboxFile.cpp
xbmc/filesystem/SpecialProtocolDirectory.cpp
xbmc/guilib/TextureBundleXBT.cpp
xbmc/guilib/TextureBundleXPR.cpp
xbmc/guilib/TextureManager.cpp
xbmc/music/MusicDatabase.cpp
xbmc/network/UdpClient.cpp
xbmc/network/cddb.cpp
xbmc/pictures/PictureInfoTag.cpp
xbmc/pvr/recordings/PVRRecordings.cpp
xbmc/utils/Archive.cpp
xbmc/utils/RssReader.cpp
xbmc/utils/ScraperParser.cpp
xbmc/utils/StdString.h
xbmc/utils/URIUtils.cpp
xbmc/video/VideoDatabase.cpp

index ee0d706..61b230a 100644 (file)
@@ -962,10 +962,10 @@ CStdString CUtil::ValidatePath(const CStdString &path, bool bFixDoubleSlashes /*
        necessary! This applies to certain DLLs or use from Python DLLs/scripts
        that incorrectly generate double (back) slashes.
     */
-    if (bFixDoubleSlashes)
+    if (bFixDoubleSlashes && !result.empty())
     {
       // Fixup for double back slashes (but ignore the \\ of unc-paths)
-      for (int x = 1; x < result.GetLength() - 1; x++)
+      for (size_t x = 1; x < result.size() - 1; x++)
       {
         if (result[x] == '\\' && result[x+1] == '\\')
           result.erase(x);
@@ -980,10 +980,10 @@ CStdString CUtil::ValidatePath(const CStdString &path, bool bFixDoubleSlashes /*
        necessary! This applies to certain DLLs or use from Python DLLs/scripts
        that incorrectly generate double (back) slashes.
     */
-    if (bFixDoubleSlashes)
+    if (bFixDoubleSlashes && !result.empty())
     {
       // Fixup for double forward slashes(/) but don't touch the :// of URLs
-      for (int x = 2; x < result.GetLength() - 1; x++)
+      for (size_t x = 2; x < result.size() - 1; x++)
       {
         if ( result[x] == '/' && result[x + 1] == '/' && !(result[x - 1] == ':' || (result[x - 1] == '/' && result[x - 2] == ':')) )
           result.erase(x);
@@ -1127,9 +1127,9 @@ void CUtil::SplitParams(const CStdString &paramString, std::vector<CStdString> &
   if (whiteSpacePos)
     parameter.erase(whiteSpacePos);
   // trim off start and end quotes
-  if (parameter.GetLength() > 1 && parameter[0] == '"' && parameter[parameter.GetLength() - 1] == '"')
-    parameter = parameter.substr(1,parameter.GetLength() - 2);
-  else if (parameter.GetLength() > 3 && parameter[parameter.GetLength() - 1] == '"')
+  if (parameter.size() > 1 && parameter[0] == '"' && parameter[parameter.size() - 1] == '"')
+    parameter = parameter.substr(1,parameter.size() - 2);
+  else if (parameter.size() > 3 && parameter[parameter.size() - 1] == '"')
   {
     // check name="value" style param.
     size_t quotaPos = parameter.find('"');
index 8c8e39a..42dfe6e 100644 (file)
@@ -342,9 +342,9 @@ bool Win32DllLoader::NeedsHooking(const char *dllName)
   CStdString xbmcPath = CSpecialProtocol::TranslatePath("special://xbmc");
   CStdString homePath = CSpecialProtocol::TranslatePath("special://home");
   CStdString tempPath = CSpecialProtocol::TranslatePath("special://temp");
-  return ((strncmp(xbmcPath.c_str(), dllPath.c_str(), xbmcPath.GetLength()) == 0) ||
-    (strncmp(homePath.c_str(), dllPath.c_str(), homePath.GetLength()) == 0) ||
-    (strncmp(tempPath.c_str(), dllPath.c_str(), tempPath.GetLength()) == 0));
+  return ((strncmp(xbmcPath.c_str(), dllPath.c_str(), xbmcPath.size()) == 0) ||
+    (strncmp(homePath.c_str(), dllPath.c_str(), homePath.size()) == 0) ||
+    (strncmp(tempPath.c_str(), dllPath.c_str(), tempPath.size()) == 0));
 }
 
 void Win32DllLoader::RestoreImports()
index 7bf51d5..3152e51 100644 (file)
@@ -163,7 +163,7 @@ bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
     }
     else if (b == XBMCVK_END)
     {
-      SetCursorPos(m_strEdit.GetLength());
+      SetCursorPos(m_strEdit.size());
     }
     else if (b == XBMCVK_LEFT)
     {
@@ -179,7 +179,7 @@ bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
     }
     else if (b == XBMCVK_DELETE)
     {
-      if (GetCursorPos() < m_strEdit.GetLength())
+      if (GetCursorPos() < (int)m_strEdit.size())
       {
         MoveCursor(1);
         Backspace();
@@ -213,7 +213,7 @@ bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
         Close();
         break;
       case 0x7F: // Delete
-        if (GetCursorPos() < m_strEdit.GetLength())
+        if (GetCursorPos() < (int)m_strEdit.size())
         {
           MoveCursor(1);
           Backspace();
index 29f55d7..2f0cafa 100644 (file)
@@ -23,6 +23,7 @@
 #include "threads/SingleLock.h"
 #include "utils/log.h"
 #include "utils/URIUtils.h"
+#include "utils/StringUtils.h"
 #include "climits"
 
 using namespace std;
@@ -142,8 +143,7 @@ void CDirectoryCache::ClearSubPaths(const CStdString& strPath)
   iCache i = m_cache.begin();
   while (i != m_cache.end())
   {
-    CStdString path = i->first;
-    if (strncmp(path.c_str(), storedPath.c_str(), storedPath.GetLength()) == 0)
+    if (StringUtils::StartsWith(i->first, storedPath))
       Delete(i++);
     else
       i++;
index 0332cec..d7e7194 100644 (file)
@@ -431,10 +431,10 @@ bool CSlingboxFile::SelectChannel(unsigned int uiChannel)
   {
     // Prepare variables
     CStdString strDigits = StringUtils::Format("%u", uiChannel);
-    unsigned int uiNumberOfDigits = strDigits.GetLength();
+    size_t uiNumberOfDigits = strDigits.size();
 
     // Change the channel using IR commands
-    for (unsigned int i = 0; i < uiNumberOfDigits; i++)
+    for (size_t i = 0; i < uiNumberOfDigits; i++)
     {
       if (m_pSlingbox->SendIRCommand(m_sSlingboxSettings.uiCodeNumber[strDigits[i] - '0']))
       {
index cb5378f..913997b 100644 (file)
@@ -21,6 +21,7 @@
 #include "SpecialProtocolDirectory.h"
 #include "SpecialProtocol.h"
 #include "Directory.h"
+#include "utils/StringUtils.h"
 #include "utils/URIUtils.h"
 #include "FileItem.h"
 
@@ -44,8 +45,8 @@ bool CSpecialProtocolDirectory::GetDirectory(const CStdString& strPath, CFileIte
     for (int i = 0; i < items.Size(); i++)
     {
       CFileItemPtr item = items[i];
-      if (strnicmp(item->GetPath().c_str(), translatedPath.c_str(), translatedPath.GetLength()) == 0)
-        item->SetPath(URIUtils::AddFileToFolder(untranslatedPath, item->GetPath().substr(translatedPath.GetLength())));
+      if (StringUtils::StartsWith(item->GetPath(), translatedPath))
+        item->SetPath(URIUtils::AddFileToFolder(untranslatedPath, item->GetPath().substr(translatedPath.size())));
     }
     return true;
   }
index edd4f8e..a0b82b2 100644 (file)
@@ -115,7 +115,7 @@ bool CTextureBundleXBT::HasFile(const CStdString& Filename)
 
 void CTextureBundleXBT::GetTexturesFromPath(const CStdString &path, std::vector<CStdString> &textures)
 {
-  if (path.GetLength() > 1 && path[1] == ':')
+  if (path.size() > 1 && path[1] == ':')
     return;
 
   if (!m_XBTFReader.IsOpen() && !OpenBundle())
index 61055ef..0a9f4cb 100644 (file)
@@ -251,7 +251,7 @@ bool CTextureBundleXPR::HasFile(const CStdString& Filename)
 
 void CTextureBundleXPR::GetTexturesFromPath(const CStdString &path, std::vector<CStdString> &textures)
 {
-  if (path.GetLength() > 1 && path[1] == ':')
+  if (path.size() > 1 && path[1] == ':')
     return;
 
   if (m_hFile == NULL && !OpenBundle())
index 9d94c92..ea272cd 100644 (file)
@@ -354,7 +354,7 @@ const CTextureArray& CGUITextureManager::Load(const CStdString& strTextureName,
       int iImages = AnimatedGifSet.LoadGIF(strPath.c_str());
       if (iImages == 0)
       {
-        CStdString rootPath = strPath.substr(0, g_SkinInfo->Path().GetLength());
+        CStdString rootPath = strPath.substr(0, g_SkinInfo->Path().size());
         if (0 == rootPath.CompareNoCase(g_SkinInfo->Path()))
           CLog::Log(LOGERROR, "Texture manager unable to load file: %s", strPath.c_str());
         return emptyTexture;
index ceee565..6eacb19 100644 (file)
@@ -1268,7 +1268,7 @@ bool CMusicDatabase::SearchArtists(const CStdString& search, CFileItemList &arti
 
     CStdString strVariousArtists = g_localizeStrings.Get(340).c_str();
     CStdString strSQL;
-    if (search.GetLength() >= MIN_FULL_SEARCH_LENGTH)
+    if (search.size() >= MIN_FULL_SEARCH_LENGTH)
       strSQL=PrepareSQL("select * from artist "
                                 "where (strArtist like '%s%%' or strArtist like '%% %s%%') and strArtist <> '%s' "
                                 , search.c_str(), search.c_str(), strVariousArtists.c_str() );
@@ -1854,7 +1854,7 @@ bool CMusicDatabase::SearchSongs(const CStdString& search, CFileItemList &items)
       return false;
 
     CStdString strSQL;
-    if (search.GetLength() >= MIN_FULL_SEARCH_LENGTH)
+    if (search.size() >= MIN_FULL_SEARCH_LENGTH)
       strSQL=PrepareSQL("select * from songview where strTitle like '%s%%' or strTitle like '%% %s%%' limit 1000", search.c_str(), search.c_str());
     else
       strSQL=PrepareSQL("select * from songview where strTitle like '%s%%' limit 1000", search.c_str());
@@ -1890,7 +1890,7 @@ bool CMusicDatabase::SearchAlbums(const CStdString& search, CFileItemList &album
     if (NULL == m_pDS.get()) return false;
 
     CStdString strSQL;
-    if (search.GetLength() >= MIN_FULL_SEARCH_LENGTH)
+    if (search.size() >= MIN_FULL_SEARCH_LENGTH)
       strSQL=PrepareSQL("select * from albumview where strAlbum like '%s%%' or strAlbum like '%% %s%%'", search.c_str(), search.c_str());
     else
       strSQL=PrepareSQL("select * from albumview where strAlbum like '%s%%'", search.c_str());
index 73ac2f6..76cce69 100644 (file)
@@ -260,7 +260,7 @@ bool CUdpClient::DispatchNextCommand()
 
     do
     {
-      ret = sendto(client_socket, command.message, command.message.GetLength(), 0, (struct sockaddr *) & command.address, sizeof(command.address));
+      ret = sendto(client_socket, command.message, command.message.size(), 0, (struct sockaddr *) & command.address, sizeof(command.address));
     }
     while (ret == -1 && !m_bStop);
   }
index c9b7aa5..8b8ddf2 100644 (file)
@@ -528,7 +528,7 @@ void Xcddb::parseData(const char *buffer)
       // DTITLE may contain artist and disc title, separated with " / ",
       // for example: DTITLE=Modern Talking / Album: Victory (The 11th Album)
       bool found = false;
-      for (int i = 0; i < strValue.GetLength() - 2; i++)
+      for (int i = 0; i < (int)strValue.size() - 2; i++)
       {
         if (strValue[i] == ' ' && strValue[i + 1] == '/' && strValue[i + 2] == ' ')
         {
index ef2dc25..35cb660 100644 (file)
@@ -280,7 +280,7 @@ void CPictureInfoTag::GetStringFromArchive(CArchive &ar, char *string, size_t le
 {
   CStdString temp;
   ar >> temp;
-  length = min((size_t)temp.GetLength(), length - 1);
+  length = min((size_t)temp.size(), length - 1);
   if (!temp.empty())
     memcpy(string, temp.c_str(), length);
   string[length] = 0;
index 36c70f1..68517bc 100644 (file)
@@ -72,9 +72,9 @@ const CStdString CPVRRecordings::GetDirectoryFromPath(const CStdString &strPath,
   if (!strUseBase.empty())
   {
     /* adding "/" to make sure that base matches the complete folder name and not only parts of it */
-    if (strUsePath.GetLength() <= strUseBase.GetLength() || !StringUtils::StartsWith(strUsePath, strUseBase + "/"))
+    if (strUsePath.size() <= strUseBase.size() || !StringUtils::StartsWith(strUsePath, strUseBase + "/"))
       return strReturn;
-    strUsePath.erase(0, strUseBase.GetLength());
+    strUsePath.erase(0, strUseBase.size());
   }
 
   /* check for more occurences */
@@ -229,10 +229,10 @@ bool CPVRRecordings::HasAllRecordingsPathExtension(const CStdString &strDirector
   CStdString strUseDir = TrimSlashes(strDirectory);
   CStdString strAllRecordingsPathExtension(PVR_ALL_RECORDINGS_PATH_EXTENSION);
 
-  if (strUseDir.GetLength() < strAllRecordingsPathExtension.GetLength())
+  if (strUseDir.size() < strAllRecordingsPathExtension.size())
     return false;
 
-  if (strUseDir.GetLength() == strAllRecordingsPathExtension.GetLength())
+  if (strUseDir.size() == strAllRecordingsPathExtension.size())
     return strUseDir.Equals(strAllRecordingsPathExtension);
 
   return StringUtils::EndsWith(strUseDir, "/" + strAllRecordingsPathExtension);
@@ -255,7 +255,7 @@ CStdString CPVRRecordings::RemoveAllRecordingsPathExtension(const CStdString &st
   if (!HasAllRecordingsPathExtension(strDirectory))
     return strDirectory;
 
-  return strDirectory.substr(0, strDirectory.GetLength() - strlen(PVR_ALL_RECORDINGS_PATH_EXTENSION) - 1);
+  return strDirectory.substr(0, strDirectory.size() - strlen(PVR_ALL_RECORDINGS_PATH_EXTENSION) - 1);
 }
 
 int CPVRRecordings::Load(void)
index 79cbf99..122c41b 100644 (file)
@@ -181,9 +181,9 @@ CArchive& CArchive::operator<<(const std::string& str)
 
 CArchive& CArchive::operator<<(const CStdString& str)
 {
-  *this << str.GetLength();
+  *this << (unsigned int)str.size();
 
-  int size = str.GetLength();
+  int size = str.size();
   if (m_BufferPos + size >= BUFFER_MAX)
     FlushBuffer();
 
@@ -205,9 +205,9 @@ CArchive& CArchive::operator<<(const CStdString& str)
 
 CArchive& CArchive::operator<<(const CStdStringW& str)
 {
-  *this << str.GetLength();
+  *this << (unsigned int)str.size();
 
-  int size = str.GetLength() * sizeof(wchar_t);
+  int size = str.size() * sizeof(wchar_t);
   if (m_BufferPos + size >= BUFFER_MAX)
     FlushBuffer();
 
@@ -377,7 +377,7 @@ CArchive& CArchive::operator>>(std::string& str)
 
 CArchive& CArchive::operator>>(CStdString& str)
 {
-  int iLength = 0;
+  unsigned int iLength = 0;
   *this >> iLength;
 
   m_pFile->Read((void*)str.GetBufferSetLength(iLength), iLength);
@@ -389,7 +389,7 @@ CArchive& CArchive::operator>>(CStdString& str)
 
 CArchive& CArchive::operator>>(CStdStringW& str)
 {
-  int iLength = 0;
+  unsigned int iLength = 0;
   *this >> iLength;
 
   m_pFile->Read((void*)str.GetBufferSetLength(iLength), iLength * sizeof(wchar_t));
index 62f9bb5..b1e53b7 100644 (file)
@@ -235,9 +235,9 @@ void CRssReader::AddString(CStdStringW aString, int aColour, int iFeed)
   else
     m_strFeed[iFeed] += aString;
 
-  int nStringLength = aString.GetLength();
+  size_t nStringLength = aString.size();
 
-  for (int i = 0;i < nStringLength;i++)
+  for (size_t i = 0;i < nStringLength;i++)
     aString[i] = (CHAR) (48 + aColour);
 
   if (m_rtlText)
index fdc0f95..54fa1ac 100644 (file)
@@ -158,7 +158,7 @@ void CScraperParser::ReplaceBuffers(CStdString& strDest)
     CStdString temp = StringUtils::Format("$$%i",i+1);
     while ((iIndex = strDest.find(temp,iIndex)) != CStdString::npos) // COPIED FROM CStdString WITH THE ADDITION OF $ ESCAPING
     {
-      strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+temp.GetLength(),m_param[i]);
+      strDest.replace(strDest.begin()+iIndex,strDest.begin()+iIndex+temp.size(),m_param[i]);
       iIndex += m_param[i].length();
     }
   }
index c83f5a2..5b5e18f 100644 (file)
@@ -2626,13 +2626,6 @@ public:
     return BufferSet(nLen);
   }
 
-  // GetLength() -- MFC docs say this is the # of BYTES but
-  // in truth it is the number of CHARACTERs (chars or wchar_ts)
-  int GetLength() const
-  {
-    return static_cast<int>(this->length());
-  }
-
 #ifndef SS_ANSI
   bool LoadString(UINT nId)
   {
index 43da816..85ae7cd 100644 (file)
@@ -42,7 +42,7 @@ bool URIUtils::IsInPath(const CStdString &uri, const CStdString &baseURI)
 {
   CStdString uriPath = CSpecialProtocol::TranslatePath(uri);
   CStdString basePath = CSpecialProtocol::TranslatePath(baseURI);
-  return (strncmp(uriPath.c_str(), basePath.c_str(), basePath.GetLength()) == 0);
+  return StringUtils::StartsWith(uriPath, basePath);
 }
 
 /* returns filename extension including period of filename */
index b714227..a159dab 100644 (file)
@@ -5756,7 +5756,7 @@ bool CVideoDatabase::GetStackedTvShowList(int idShow, CStdString& strIn) const
         strIn += PrepareSQL("%i,", m_pDS->fv(0).get_asInt());
         m_pDS->next();
       }
-      strIn[strIn.GetLength() - 1] = ')'; // replace last , with )
+      strIn[strIn.size() - 1] = ')'; // replace last , with )
     }
     m_pDS->close();
     return true;