[cstdstring] removal of Trim/TrimLeft/TrimRight
authorJonathan Marshall <jmarshall@xbmc.org>
Sun, 27 Oct 2013 07:36:49 +0000 (20:36 +1300)
committerJonathan Marshall <jmarshall@xbmc.org>
Wed, 13 Nov 2013 21:52:50 +0000 (10:52 +1300)
61 files changed:
xbmc/CueDocument.cpp
xbmc/FileItem.cpp
xbmc/GUIInfoManager.cpp
xbmc/TextureCacheJob.cpp
xbmc/URL.cpp
xbmc/Util.cpp
xbmc/XBDateTime.cpp
xbmc/addons/GUIDialogAddonSettings.cpp
xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecSSA.cpp
xbmc/cores/dvdplayer/DVDPlayerSubtitle.cpp
xbmc/cores/dvdplayer/DVDSubtitles/DVDSubtitleParserSubrip.cpp
xbmc/cores/dvdplayer/DVDSubtitles/DVDSubtitleTagSami.cpp
xbmc/cores/dvdplayer/DVDTSCorrection.cpp
xbmc/cores/paplayer/PCMCodec.cpp
xbmc/dbwrappers/DatabaseQuery.cpp
xbmc/filesystem/HTTPDirectory.cpp
xbmc/filesystem/MythSession.cpp
xbmc/filesystem/RTVDirectory.cpp
xbmc/filesystem/SMBDirectory.cpp
xbmc/filesystem/UPnPDirectory.cpp
xbmc/filesystem/VirtualDirectory.cpp
xbmc/guilib/GUIColorManager.cpp
xbmc/guilib/GUIMultiSelectText.cpp
xbmc/guilib/TextureBundleXBT.cpp
xbmc/guilib/TextureBundleXPR.cpp
xbmc/input/ButtonTranslator.cpp
xbmc/interfaces/Builtins.cpp
xbmc/linux/LinuxTimezone.cpp
xbmc/music/MusicDatabase.cpp
xbmc/music/tags/MusicInfoTag.cpp
xbmc/music/tags/MusicInfoTagLoaderFactory.cpp
xbmc/music/tags/TagLoaderTagLib.cpp
xbmc/network/cddb.cpp
xbmc/network/linux/NetworkLinux.cpp
xbmc/network/websocket/WebSocketV13.cpp
xbmc/network/websocket/WebSocketV8.cpp
xbmc/peripherals/devices/PeripheralCecAdapter.cpp
xbmc/playlists/PlayListM3U.cpp
xbmc/playlists/PlayListPLS.cpp
xbmc/storage/DetectDVDType.cpp
xbmc/storage/MediaManager.cpp
xbmc/utils/CPUInfo.cpp
xbmc/utils/LangCodeExpander.cpp
xbmc/utils/ScraperParser.cpp
xbmc/utils/ScraperParser.h
xbmc/utils/StdString.h
xbmc/utils/StringUtils.cpp
xbmc/utils/StringUtils.h
xbmc/utils/SystemInfo.cpp
xbmc/utils/TextSearch.cpp
xbmc/utils/URIUtils.cpp
xbmc/utils/Weather.cpp
xbmc/utils/log.cpp
xbmc/utils/test/TestXBMCTinyXML.cpp
xbmc/video/VideoDatabase.cpp
xbmc/video/VideoInfoTag.cpp
xbmc/video/dialogs/GUIDialogVideoInfo.cpp
xbmc/win32/WIN32Util.cpp
xbmc/windowing/X11/XRandR.cpp
xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
xbmc/windows/GUIMediaWindow.cpp

index 80e0511..1137970 100644 (file)
@@ -132,7 +132,7 @@ bool CCueDocument::Parse(const CStdString &strFile)
       {
         // lets manage tracks titles without quotes
         CStdString titleNoQuote = strLine.Mid(5);
-        titleNoQuote.TrimLeft();
+        StringUtils::TrimLeft(titleNoQuote);
         if (!titleNoQuote.empty())
         {
           g_charsetConverter.unknownToUTF8(titleNoQuote);
@@ -193,7 +193,7 @@ bool CCueDocument::Parse(const CStdString &strFile)
       if (!ExtractQuoteInfo(strLine, m_strGenre))
       {
         CStdString genreNoQuote = strLine.Mid(9);
-        genreNoQuote.TrimLeft();
+        StringUtils::TrimLeft(genreNoQuote);
         if (!genreNoQuote.empty())
         {
           g_charsetConverter.unknownToUTF8(genreNoQuote);
@@ -290,7 +290,7 @@ bool CCueDocument::ReadNextLine(CStdString &szLine)
   {
     // Remove the white space at the beginning and end of the line.
     szLine = m_szBuffer;
-    szLine.Trim();
+    StringUtils::Trim(szLine);
     if (!szLine.empty())
       return true;
     // If we are here, we have an empty line so try the next line
@@ -325,14 +325,14 @@ int CCueDocument::ExtractTimeFromIndex(const CStdString &index)
 {
   // Get rid of the index number and any whitespace
   CStdString numberTime = index.Mid(5);
-  numberTime.TrimLeft();
+  StringUtils::TrimLeft(numberTime);
   while (!numberTime.empty())
   {
     if (!isdigit(numberTime[0]))
       break;
     numberTime.erase(0, 1);
   }
-  numberTime.TrimLeft();
+  StringUtils::TrimLeft(numberTime);
   // split the resulting string
   CStdStringArray time;
   StringUtils::SplitString(numberTime, ":", time);
@@ -353,7 +353,7 @@ int CCueDocument::ExtractTimeFromIndex(const CStdString &index)
 int CCueDocument::ExtractNumericInfo(const CStdString &info)
 {
   CStdString number(info);
-  number.TrimLeft();
+  StringUtils::TrimLeft(number);
   if (number.empty() || !isdigit(number[0]))
     return -1;
   return atoi(number.c_str());
index 85d43e7..1805d1b 100644 (file)
@@ -1402,7 +1402,7 @@ void CFileItem::FillInMimeType(bool lookup /*= true*/)
       int i = m_mimetype.Find(';');
       if(i>=0)
         m_mimetype.Delete(i, m_mimetype.length() - i);
-      m_mimetype.Trim();
+      StringUtils::Trim(m_mimetype);
     }
     else
       m_mimetype = CMime::GetMimeType(*this);
index 627bf6e..8c1d9ea 100644 (file)
@@ -794,8 +794,7 @@ int CGUIInfoManager::TranslateSingleString(const CStdString &strCondition)
 {
   // trim whitespaces
   CStdString strTest = strCondition;
-  strTest.TrimLeft(" \t\r\n");
-  strTest.TrimRight(" \t\r\n");
+  StringUtils::Trim(strTest);
 
   vector< Property> info;
   SplitInfoString(strTest, info);
@@ -1385,7 +1384,7 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fa
     break;
   case WEATHER_CONDITIONS:
     strLabel = g_weatherManager.GetInfo(WEATHER_LABEL_CURRENT_COND);
-    strLabel = strLabel.Trim();
+    StringUtils::Trim(strLabel);
     break;
   case WEATHER_TEMPERATURE:
     strLabel = StringUtils::Format("%s%s",
@@ -2111,8 +2110,7 @@ bool CGUIInfoManager::GetInt(int &value, int info, int contextWindow, const CGUI
 unsigned int CGUIInfoManager::Register(const CStdString &expression, int context)
 {
   CStdString condition(CGUIInfoLabel::ReplaceLocalize(expression));
-  condition.TrimLeft(" \t\r\n");
-  condition.TrimRight(" \t\r\n");
+  StringUtils::Trim(condition);
 
   if (condition.empty())
     return 0;
@@ -4516,7 +4514,7 @@ CStdString CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, CStdSt
       if (info==LISTITEM_FILE_EXTENSION)
       {
         CStdString strExtension = URIUtils::GetExtension(strFile);
-        return strExtension.TrimLeft(".");
+        return StringUtils::TrimLeft(strExtension, ".");
       }
       return strFile;
     }
index d58b1f4..0922382 100644 (file)
@@ -146,7 +146,7 @@ CStdString CTextureCacheJob::DecodeImageURL(const CStdString &url, unsigned int
     image = thumbURL.GetHostName();
 
     CStdString optionString = thumbURL.GetOptions().Mid(1);
-    optionString.TrimRight('/'); // in case XBMC adds a slash
+    StringUtils::TrimRight(optionString, "/"); // In case XBMC adds a slash.
 
     std::vector<CStdString> options;
     StringUtils::SplitString(optionString, "&", options);
index 96960ac..c9f0722 100644 (file)
@@ -360,7 +360,8 @@ void CURL::SetFileName(const CStdString& strFileName)
   else
     m_strFileType = "";
 
-  m_strFileType.Normalize();
+  StringUtils::Trim(m_strFileType);
+  StringUtils::ToLower(m_strFileType);
 }
 
 void CURL::SetHostName(const CStdString& strHostName)
index 4b31976..48cdae3 100644 (file)
@@ -297,7 +297,8 @@ void CUtil::CleanString(const CStdString& strFileName, CStdString& strTitle, CSt
     }
   }
 
-  strTitle = strTitleAndYear.Trim();
+  StringUtils::Trim(strTitleAndYear);
+  strTitle = strTitleAndYear;
 
   // append year
   if (!strYear.empty())
@@ -911,8 +912,7 @@ CStdString CUtil::MakeLegalFileName(const CStdString &strFile, int LegalType)
     result.Replace('<', '_');
     result.Replace('>', '_');
     result.Replace('|', '_');
-    result.TrimRight(".");
-    result.TrimRight(" ");
+    StringUtils::TrimRight(result, ". ");
   }
   return result;
 }
@@ -1045,7 +1045,7 @@ void CUtil::SplitExecFunction(const CStdString &execString, CStdString &function
     function = execString;
 
   // remove any whitespace, and the standard prefix (if it exists)
-  function.Trim();
+  StringUtils::Trim(function);
   if( StringUtils::StartsWithNoCase(function, "xbmc.") )
     function.Delete(0, 5);
 
index a1de91a..0fdf9d1 100644 (file)
@@ -1004,7 +1004,7 @@ void CDateTime::SetFromDBTime(const CStdString &time)
 void CDateTime::SetFromRFC1123DateTime(const CStdString &dateTime)
 {
   CStdString date = dateTime;
-  date.Trim();
+  StringUtils::Trim(date);
 
   if (date.size() != 29)
     return;
index e60bc8a..06a0292 100644 (file)
@@ -460,7 +460,8 @@ bool CGUIDialogAddonSettings::ShowVirtualKeyboard(int iControl)
             vector<ADDON::TYPE> types;
             for (unsigned int i = 0 ; i < addonTypes.size() ; i++)
             {
-              ADDON::TYPE type = TranslateType(addonTypes[i].Trim());
+              StringUtils::Trim(addonTypes[i]);
+              ADDON::TYPE type = TranslateType(addonTypes[i]);
               if (type != ADDON_UNKNOWN)
                 types.push_back(type);
             }
@@ -1079,9 +1080,8 @@ bool CGUIDialogAddonSettings::GetCondition(const CStdString &condition, const in
 bool CGUIDialogAddonSettings::TranslateSingleString(const CStdString &strCondition, vector<CStdString> &condVec)
 {
   CStdString strTest = strCondition;
-  strTest.ToLower();
-  strTest.TrimLeft(" ");
-  strTest.TrimRight(" ");
+  StringUtils::ToLower(strTest);
+  StringUtils::Trim(strTest);
 
   int pos1 = strTest.Find("(");
   int pos2 = strTest.Find(",");
index 2fadb4d..7ac67fe 100644 (file)
@@ -87,7 +87,7 @@ int CDVDOverlayCodecSSA::Decode(DemuxPacket *pPacket)
     for(size_t i=0; i<lines.size(); i++)
     {
       line = lines[i];
-      line.Trim();
+      StringUtils::Trim(line);
       auto_aptr<char> layer(new char[line.length()+1]);
 
       if(sscanf(line.c_str(), "%*[^:]:%[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d"
index 18625a0..bd04114 100644 (file)
@@ -33,6 +33,7 @@
 #include "DVDCodecs/DVDFactoryCodec.h"
 #include "DVDDemuxers/DVDDemuxUtils.h"
 #include "utils/log.h"
+#include "utils/StringUtils.h"
 #include "threads/SingleLock.h"
 #ifdef TARGET_POSIX
 #include "config.h"
index 1f28fa4..eb6283a 100644 (file)
@@ -22,6 +22,7 @@
 #include "DVDCodecs/Overlay/DVDOverlayText.h"
 #include "DVDClock.h"
 #include "utils/StdString.h"
+#include "utils/StringUtils.h"
 #include "DVDSubtitleTagSami.h"
 
 using namespace std;
@@ -51,7 +52,7 @@ bool CDVDSubtitleParserSubrip::Open(CDVDStreamInfo &hints)
   while (m_pStream->ReadLine(line, sizeof(line)))
   {
     strLine = line;
-    strLine.Trim();
+    StringUtils::Trim(strLine);
 
     if (strLine.length() > 0)
     {
@@ -76,7 +77,7 @@ bool CDVDSubtitleParserSubrip::Open(CDVDStreamInfo &hints)
         while (m_pStream->ReadLine(line, sizeof(line)))
         {
           strLine = line;
-          strLine.Trim();
+          StringUtils::Trim(strLine);
 
           // empty line, next subtitle is about to start
           if (strLine.length() <= 0) break;
index 264a60a..7307787 100644 (file)
@@ -22,6 +22,7 @@
 #include "DVDSubtitleStream.h"
 #include "DVDCodecs/Overlay/DVDOverlayText.h"
 #include "utils/RegExp.h"
+#include "utils/StringUtils.h"
 
 CDVDSubtitleTagSami::~CDVDSubtitleTagSami()
 {
@@ -48,7 +49,7 @@ void CDVDSubtitleTagSami::ConvertLine(CDVDOverlayText* pOverlay, const char* lin
 {
   CStdStringA strUTF8;
   strUTF8.assign(line, len);
-  strUTF8.Trim();
+  StringUtils::Trim(strUTF8);
 
   int pos = 0;
   int del_start = 0;
@@ -243,9 +244,9 @@ void CDVDSubtitleTagSami::LoadHead(CDVDSubtitleStream* samiStream)
           lc.Name = reg.GetMatch(2);
           lc.Lang = reg.GetMatch(3);
           lc.SAMIType = reg.GetMatch(4);
-          lc.Name.Trim();
-          lc.Lang.Trim();
-          lc.SAMIType.Trim();
+          StringUtils::Trim(lc.Name);
+          StringUtils::Trim(lc.Lang);
+          StringUtils::Trim(lc.SAMIType);
           m_Langclass.push_back(lc);
         }
       }
index 38a9fac..f5afa7b 100644 (file)
@@ -22,7 +22,7 @@
 #include "DVDClock.h"
 #include "DVDCodecs/DVDCodecUtils.h"
 #include "utils/log.h"
-
+#include "utils/StringUtils.h"
 #include <cmath>
 
 #define MAXERR DVD_MSEC_TO_TIME(2.5)
@@ -323,7 +323,7 @@ CStdString CPullupCorrection::GetPatternStr()
   for (unsigned int i = 0; i < m_pattern.size(); i++)
     patternstr.AppendFormat("%.2f ", m_pattern[i]);
 
-  patternstr.Trim();
+  StringUtils::Trim(patternstr);
 
   return patternstr;
 }
index 145f5cd..1c4e89d 100644 (file)
@@ -112,11 +112,13 @@ void PCMCodec::SetMimeParams(const CStdString& strMimeParams)
     {
       if (thisParam[0] == "rate")
       {
-        m_SampleRate = atoi(thisParam[1].Trim());
+        StringUtils::Trim(thisParam[1]);
+        m_SampleRate = atoi(thisParam[1]);
       }
       else if (thisParam[0] == "channels")
       {
-        m_Channels = atoi(thisParam[1].Trim());
+        StringUtils::Trim(thisParam[1]);
+        m_Channels = atoi(thisParam[1]);
       }
     }
   }
index 4a21e4a..9db5970 100644 (file)
@@ -254,7 +254,7 @@ CStdString CDatabaseQueryRule::FormatParameter(const CStdString &operatorString,
     {
       if (!parameter.empty())
         parameter += ",";
-      parameter += db.PrepareSQL("'%s'", (*itIn).Trim().c_str());
+      parameter += db.PrepareSQL("'%s'", StringUtils::Trim(*itIn).c_str());
     }
     parameter = " IN (" + parameter + ")";
   }
index 8e075dd..bbb75e8 100644 (file)
@@ -91,7 +91,7 @@ bool CHTTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &item
       if(strLink[0] == '/')
         strLink = strLink.Mid(1);
 
-      CStdString strNameTemp = strName.Trim();
+      CStdString strNameTemp = StringUtils::Trim(strName);
 
       CStdStringW wName, wLink, wConverted;
       if (fileCharset.empty())
index 594fc1e..aed3ebb 100644 (file)
@@ -127,7 +127,7 @@ CStdString CMythSession::GetValue(char *str)
   {
     result = str;
     m_dll->ref_release(str);
-    result.Trim();
+    StringUtils::Trim(result);
   }
   return result;
 }
index 338c15d..3d0bc7d 100644 (file)
@@ -26,6 +26,7 @@
 #include "utils/URIUtils.h"
 #include "URL.h"
 #include "utils/XBMCTinyXML.h"
+#include "utils/StringUtils.h"
 #include "FileItem.h"
 
 using namespace XFILE;
@@ -99,7 +100,7 @@ bool CRTVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items
       // Isolate the IP from the URL and replace the "*" with the real IP
       // of the ReplayTV.  E.g., rtv://*/Video/192.168.1.100/ becomes
       // rtv://192.168.1.100/Video/ .  This trickery makes things work.
-      strURL = strRoot.TrimRight('/');
+      strURL = StringUtils::TrimRight(strRoot, "/");
       pos = strURL.ReverseFind('/');
       strRTV = strURL.Left(pos + 1);
       strRTV.Replace("*", strURL.Mid(pos + 1));
index 9461673..9f1b6b6 100644 (file)
@@ -422,7 +422,7 @@ CStdString CSMBDirectory::MountShare(const CStdString &smbPath, const CStdString
   }
 
   CStdString newPath = smbPath;
-  newPath.TrimLeft("/");
+  StringUtils::TrimLeft(newPath, "/");
   smbFullPath += newPath;
 
   // Make the mount command.
index f00c982..a066fde 100644 (file)
@@ -32,6 +32,7 @@
 #include "FileItem.h"
 #include "utils/log.h"
 #include "utils/URIUtils.h"
+#include "utils/StringUtils.h"
 
 using namespace MUSIC_INFO;
 using namespace XFILE;
@@ -150,7 +151,7 @@ bool CUPnPDirectory::GetResource(const CURL& path, CFileItem &item)
 
     CStdString uuid   = path.GetHostName();
     CStdString object = path.GetFileName();
-    object.TrimRight("/");
+    StringUtils::TrimRight(object, "/");
     CURL::Decode(object);
 
     PLT_DeviceDataReference device;
@@ -245,7 +246,7 @@ CUPnPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
         bool video = true;
         bool audio = true;
         bool image = true;
-        m_strFileMask.TrimLeft("/");
+        StringUtils::TrimLeft(m_strFileMask, "/");
         if (!m_strFileMask.empty()) {
             video = m_strFileMask.Find(".wmv") >= 0;
             audio = m_strFileMask.Find(".wma") >= 0;
index eca46e5..482cda2 100644 (file)
@@ -23,6 +23,7 @@
 #include "DirectoryFactory.h"
 #include "Util.h"
 #include "utils/URIUtils.h"
+#include "utils/StringUtils.h"
 #include "Directory.h"
 #include "DirectoryCache.h"
 #include "SourcesDirectory.h"
@@ -103,8 +104,7 @@ bool CVirtualDirectory::GetDirectory(const CStdString& strPath, CFileItemList &i
 bool CVirtualDirectory::IsSource(const CStdString& strPath, VECSOURCES *sources, CStdString *name) const
 {
   CStdString strPathCpy = strPath;
-  strPathCpy.TrimRight("/");
-  strPathCpy.TrimRight("\\");
+  StringUtils::TrimRight(strPathCpy, "/\\");
 
   // just to make sure there's no mixed slashing in share/default defines
   // ie. f:/video and f:\video was not be recognised as the same directory,
@@ -121,8 +121,7 @@ bool CVirtualDirectory::IsSource(const CStdString& strPath, VECSOURCES *sources,
   {
     const CMediaSource& share = shares.at(i);
     CStdString strShare = share.strPath;
-    strShare.TrimRight("/");
-    strShare.TrimRight("\\");
+    StringUtils::TrimRight(strShare, "/\\");
     if(URIUtils::IsDOSPath(strShare))
       strShare.Replace("/", "\\");
     if (strShare == strPathCpy)
index 49e4cc2..0275cdf 100644 (file)
@@ -24,6 +24,7 @@
 #include "utils/log.h"
 #include "utils/URIUtils.h"
 #include "utils/XBMCTinyXML.h"
+#include "utils/StringUtils.h"
 
 CGUIColorManager g_colorManager;
 
@@ -107,7 +108,7 @@ color_t CGUIColorManager::GetColor(const CStdString &color) const
 {
   // look in our color map
   CStdString trimmed(color);
-  trimmed.TrimLeft("= ");
+  StringUtils::TrimLeft(trimmed, "= ");
   icColor it = m_colors.find(trimmed);
   if (it != m_colors.end())
     return (*it).second;
index 5a1025f..6e93348 100644 (file)
@@ -22,6 +22,7 @@
 #include "GUIWindowManager.h"
 #include "Key.h"
 #include "utils/log.h"
+#include "utils/StringUtils.h"
 
 using namespace std;
 
@@ -30,8 +31,8 @@ CGUIMultiSelectTextControl::CSelectableString::CSelectableString(CGUIFont *font,
 {
   m_selectable = selectable;
   m_clickAction = clickAction;
-  m_clickAction.TrimLeft(" =");
-  m_clickAction.TrimRight(" ");
+  StringUtils::TrimLeft(m_clickAction, " =");
+  StringUtils::TrimRight(m_clickAction);
   m_text.Update(text);
   float height;
   m_text.GetTextExtent(m_length, height);
index 2a3d60d..edd4f8e 100644 (file)
@@ -29,6 +29,7 @@
 #include "filesystem/SpecialProtocol.h"
 #include "utils/EndianSwap.h"
 #include "utils/URIUtils.h"
+#include "utils/StringUtils.h"
 #include "XBTF.h"
 #include <lzo/lzo1x.h>
 #include "utils/StringUtils.h"
@@ -260,7 +261,9 @@ void CTextureBundleXBT::SetThemeBundle(bool themeBundle)
 CStdString CTextureBundleXBT::Normalize(const CStdString &name)
 {
   CStdString newName(name);
-  newName.Normalize();
+  
+  StringUtils::Trim(newName);
+  StringUtils::ToLower(newName);
   newName.Replace('\\','/');
 
   return newName;
index 30e41e7..61055ef 100644 (file)
@@ -509,7 +509,8 @@ void CTextureBundleXPR::SetThemeBundle(bool themeBundle)
 CStdString CTextureBundleXPR::Normalize(const CStdString &name)
 {
   CStdString newName(name);
-  newName.Normalize();
+  StringUtils::Trim(newName);
+  StringUtils::ToLower(newName);
   newName.Replace('/','\\');
   return newName;
 }
index 8a4c86c..a0e77f9 100644 (file)
@@ -1405,7 +1405,7 @@ uint32_t CButtonTranslator::TranslateKeyboardButton(TiXmlElement *pButton)
     for (unsigned int i = 0; i < modArray.size(); i++)
     {
       CStdString& substr = modArray[i];
-      substr.Trim();
+      StringUtils::Trim(substr);
 
       if (substr == "ctrl" || substr == "control")
         button_id |= CKey::MODIFIER_CTRL;
index 5c17169..4b9b9f0 100644 (file)
@@ -870,7 +870,8 @@ int CBuiltins::Execute(const CStdString& execString)
       else
       {
         // Don't bother checking the argument: an invalid arg will do seek(0)
-        offset = parameter.Mid(15).TrimRight(")");
+        offset = parameter.Mid(15);
+        StringUtils::TrimRight(offset, ")");
         float offsetpercent = (float) atof(offset.c_str());
         if (offsetpercent < 0 || offsetpercent > 100)
           CLog::Log(LOGERROR,"PlayerControl(seekpercentage(n)) argument, %f, must be 0-100", offsetpercent);
@@ -899,7 +900,8 @@ int CBuiltins::Execute(const CStdString& execString)
           context = PARTYMODECONTEXT_VIDEO;
         else if (parameter.size() != 16 || !StringUtils::EndsWithNoCase(parameter, "music)"))
         {
-          strXspPath = parameter.Mid(10).TrimRight(")");
+          strXspPath = parameter.Mid(10);
+          StringUtils::TrimRight(strXspPath, ")");
           context = PARTYMODECONTEXT_UNKNOWN;
         }
       }
index 1fe69cf..515c2bc 100644 (file)
@@ -60,7 +60,7 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
       {
          tokens.clear();
          s = line;
-         s.TrimLeft(" \t").TrimRight(" \n");
+         StringUtils::Trim(s);
 
          if (s.length() == 0)
             continue;
@@ -114,7 +114,7 @@ CLinuxTimezone::CLinuxTimezone() : m_IsDST(0)
       while (getdelim(&line, &linelen, '\n', fp) > 0)
       {
          s = line;
-         s.TrimLeft(" \t").TrimRight(" \n");
+         StringUtils::Trim(s);
 
          if (s.length() == 0)
             continue;
index 623d7cd..47c02e7 100644 (file)
@@ -562,7 +562,7 @@ int CMusicDatabase::AddGenre(const CStdString& strGenre1)
   try
   {
     CStdString strGenre = strGenre1;
-    strGenre.Trim();
+    StringUtils::Trim(strGenre);
 
     if (strGenre.empty())
       strGenre=g_localizeStrings.Get(13205); // Unknown
index 122b68f..3778241 100644 (file)
@@ -739,7 +739,7 @@ void CMusicInfoTag::AppendGenre(const CStdString &genre)
 CStdString CMusicInfoTag::Trim(const CStdString &value) const
 {
   CStdString trimmedValue(value);
-  trimmedValue.TrimLeft(' ');
-  trimmedValue.TrimRight(" \n\r");
+  StringUtils::TrimLeft(trimmedValue, " ");
+  StringUtils::TrimRight(trimmedValue, " \n\r");
   return trimmedValue;
 }
index ad53464..efac945 100644 (file)
@@ -33,7 +33,7 @@
 #include "MusicInfoTagLoaderDatabase.h"
 #include "MusicInfoTagLoaderASAP.h"
 #include "MusicInfoTagLoaderMidi.h"
-
+#include "utils/StringUtils.h"
 #include "utils/URIUtils.h"
 #include "FileItem.h"
 
@@ -60,8 +60,8 @@ IMusicInfoTagLoader* CMusicInfoTagLoaderFactory::CreateLoader(const CStdString&
     return new CMusicInfoTagLoaderDatabase();
 
   CStdString strExtension = URIUtils::GetExtension(strFileName);
-  strExtension.ToLower();
-  strExtension.TrimLeft('.');
+  StringUtils::ToLower(strExtension);
+  StringUtils::TrimLeft(strExtension, ".");
 
   if (strExtension.empty())
     return NULL;
index e641368..fdb3f0e 100644 (file)
@@ -94,8 +94,8 @@ bool CTagLoaderTagLib::Load(const CStdString& strFileName, MUSIC_INFO::CMusicInf
 bool CTagLoaderTagLib::Load(const CStdString& strFileName, CMusicInfoTag& tag, const CStdString& fallbackFileExtension, MUSIC_INFO::EmbeddedArt *art /* = NULL */)
 {  
   CStdString strExtension = URIUtils::GetExtension(strFileName);
-  strExtension.ToLower();
-  strExtension.TrimLeft('.');
+  StringUtils::ToLower(strExtension);
+  StringUtils::TrimLeft(strExtension, ".");
 
   if (strExtension.empty())
   {
index 8bdc760..34bae4a 100644 (file)
@@ -499,7 +499,7 @@ void Xcddb::parseData(const char *buffer)
       if (s != NULL)
       {
         CStdString strKeyword(line, s - line);
-        strKeyword.TrimRight(" ");
+        StringUtils::TrimRight(strKeyword);
 
         CStdString strValue(s+1);
         strValue.Replace("\\n", "\n"); 
@@ -569,7 +569,7 @@ void Xcddb::parseData(const char *buffer)
         if (iPos > -1)
         {
           CStdString strGenre = strExtd.Mid(iPos + 5, 4);
-          strGenre.TrimLeft(' ');
+          StringUtils::TrimLeft(strGenre);
           if (StringUtils::IsNaturalNumber(strGenre))
           {
             int iGenre = strtol(strGenre, NULL, 10);
@@ -1078,7 +1078,7 @@ CStdString Xcddb::GetCacheFile(uint32_t disc_id) const
 CStdString Xcddb::TrimToUTF8(const CStdString &untrimmedText)
 {
   CStdString text(untrimmedText);
-  text.Trim();
+  StringUtils::Trim(text);
   // You never know if you really get UTF-8 strings from cddb
   g_charsetConverter.unknownToUTF8(text);
   return text;
index 9da86e6..c58c9e5 100644 (file)
@@ -916,7 +916,8 @@ void CNetworkInterfaceLinux::GetSettings(NetworkAssignment& assignment, CStdStri
       std::vector<std::string> tokens;
 
       s = line;
-      s.TrimLeft(" \t").TrimRight(" \n");
+      StringUtils::TrimLeft(s, " \t");
+      StringUtils::TrimRight(s," \n");
 
       // skip comments
       if (s.length() == 0 || s.GetAt(0) == '#')
@@ -1001,7 +1002,8 @@ void CNetworkInterfaceLinux::SetSettings(NetworkAssignment& assignment, CStdStri
       std::vector<std::string> tokens;
 
       s = line;
-      s.TrimLeft(" \t").TrimRight(" \n");
+      StringUtils::TrimLeft(s, " \t");
+      StringUtils::TrimRight(s," \n");
 
       // skip comments
       if (!foundInterface && (s.length() == 0 || s.GetAt(0) == '#'))
index 1304d44..3ec35b0 100644 (file)
@@ -124,9 +124,10 @@ bool CWebSocketV13::Handshake(const char* data, size_t length, std::string &resp
   {
     CStdStringArray protocols;
     StringUtils::SplitString(value, ",", protocols);
-    for (unsigned int index = 0; index < protocols.size(); index++)
+    for (CStdStringArray::iterator protocol = protocols.begin(); protocol != protocols.end(); ++protocol)
     {
-      if (protocols.at(index).Trim().Equals(WS_PROTOCOL_JSONRPC))
+      StringUtils::Trim(*protocol);
+      if (*protocol == WS_PROTOCOL_JSONRPC)
       {
         websocketProtocol = WS_PROTOCOL_JSONRPC;
         break;
index c1fe890..c148e1e 100644 (file)
@@ -109,9 +109,10 @@ bool CWebSocketV8::Handshake(const char* data, size_t length, std::string &respo
   {
     CStdStringArray protocols;
     StringUtils::SplitString(value, ",", protocols);
-    for (unsigned int index = 0; index < protocols.size(); index++)
+    for (CStdStringArray::iterator protocol = protocols.begin(); protocol != protocols.end(); ++protocol)
     {
-      if (protocols.at(index).Trim().Equals(WS_PROTOCOL_JSONRPC))
+      StringUtils::Trim(*protocol);
+      if (*protocol == WS_PROTOCOL_JSONRPC)
       {
         websocketProtocol = WS_PROTOCOL_JSONRPC;
         break;
index 0245fcf..9b08ee9 100644 (file)
@@ -1313,7 +1313,8 @@ void CPeripheralCecAdapter::SetConfigurationFromSettings(void)
     m_configuration.tvVendor = iVendor;
 
   // read the devices to wake when starting
-  CStdString strWakeDevices = CStdString(GetSettingString("wake_devices_advanced")).Trim();
+  CStdString strWakeDevices = GetSettingString("wake_devices_advanced");
+  StringUtils::Trim(strWakeDevices);
   m_configuration.wakeDevices.Clear();
   if (!strWakeDevices.empty())
     ReadLogicalAddresses(strWakeDevices, m_configuration.wakeDevices);
@@ -1321,7 +1322,8 @@ void CPeripheralCecAdapter::SetConfigurationFromSettings(void)
     ReadLogicalAddresses(GetSettingInt("wake_devices"), m_configuration.wakeDevices);
 
   // read the devices to power off when stopping
-  CStdString strStandbyDevices = CStdString(GetSettingString("standby_devices_advanced")).Trim();
+  CStdString strStandbyDevices = GetSettingString("standby_devices_advanced");
+  StringUtils::Trim(strStandbyDevices);
   m_configuration.powerOffDevices.Clear();
   if (!strStandbyDevices.empty())
     ReadLogicalAddresses(strStandbyDevices, m_configuration.powerOffDevices);
@@ -1348,7 +1350,8 @@ void CPeripheralCecAdapter::ReadLogicalAddresses(const CStdString &strString, ce
 {
   for (size_t iPtr = 0; iPtr < strString.size(); iPtr++)
   {
-    CStdString strDevice = CStdString(strString.substr(iPtr, 1)).Trim();
+    CStdString strDevice = strString.substr(iPtr, 1);
+    StringUtils::Trim(strDevice);
     if (!strDevice.empty())
     {
       int iDevice(0);
@@ -1390,7 +1393,8 @@ bool CPeripheralCecAdapter::WriteLogicalAddresses(const cec_logical_addresses& a
     for (unsigned int iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
       if (addresses[iPtr])
         strPowerOffDevices.AppendFormat(" %X", iPtr);
-    bChanged = SetSetting(strAdvancedSettingName, strPowerOffDevices.Trim());
+    StringUtils::Trim(strPowerOffDevices);
+    bChanged = SetSetting(strAdvancedSettingName, strPowerOffDevices);
   }
 
   int iSettingPowerOffDevices = LOCALISED_ID_NONE;
index 341a456..043c439 100644 (file)
@@ -89,8 +89,7 @@ bool CPlayListM3U::Load(const CStdString& strFileName)
   while (file.ReadString(szLine, 1024))
   {
     strLine = szLine;
-    strLine.TrimRight(" \t\r\n");
-    strLine.TrimLeft(" \t");
+    StringUtils::Trim(strLine);
 
     if (strLine.Left( (int)strlen(M3U_INFO_MARKER) ) == M3U_INFO_MARKER)
     {
@@ -218,8 +217,7 @@ CStdString CPlayListM3U::GetBestBandwidthStream(const CStdString &strFileName, s
   {
     // read and trim a line
     strLine = szLine;
-    strLine.TrimRight(" \t\r\n");
-    strLine.TrimLeft(" \t");
+    StringUtils::Trim(strLine);
 
     // skip the first line
     if (strLine == M3U_START_MARKER)
@@ -240,8 +238,7 @@ CStdString CPlayListM3U::GetBestBandwidthStream(const CStdString &strFileName, s
             continue;
 
           strLine = szLine;
-          strLine.TrimRight(" \t\r\n");
-          strLine.TrimLeft(" \t");
+          StringUtils::Trim(strLine);
 
           // this line was empty
           if (strLine.empty())
@@ -281,12 +278,15 @@ std::map< CStdString, CStdString > CPlayListM3U::ParseStreamLine(const CStdStrin
   for (size_t i = 0; i < vecParams.size(); i++)
   {
     // split the param, ensure there was an =
-    CStdStringArray vecTuple = StringUtils::SplitString(vecParams[i].Trim(), "=");
+    StringUtils::Trim(vecParams[i]);
+    CStdStringArray vecTuple = StringUtils::SplitString(vecParams[i], "=");
     if (vecTuple.size() < 2)
       continue;
 
     // remove white space from name and value and store it in the dictionary
-    params[vecTuple[0].Trim()] = vecTuple[1].Trim();
+    StringUtils::Trim(vecTuple[0]);
+    StringUtils::Trim(vecTuple[1]);
+    params[vecTuple[0]] = vecTuple[1];
   }
 
   return params;
index 1d67d48..5a7a737 100644 (file)
@@ -100,8 +100,7 @@ bool CPlayListPLS::Load(const CStdString &strFile)
       return size() > 0;
     }
     strLine = szLine;
-    strLine.TrimLeft(" \t");
-    strLine.TrimRight(" \n\r");
+    StringUtils::Trim(strLine);
     if(strLine.Equals(START_PLAYLIST_MARKER))
       break;
 
index 754071e..79f7928 100644 (file)
@@ -294,7 +294,7 @@ void CDetectDVDMedia::DetectMediaType()
   else
   {
     strLabel = m_pCdInfo->GetDiscLabel();
-    strLabel.TrimRight(" ");
+    StringUtils::TrimRight(strLabel);
   }
 
   SetNewDVDShareUrl( strNewUrl , bCDDA, strLabel);
index 0e613b0..8f3415f 100644 (file)
@@ -490,7 +490,7 @@ CStdString CMediaManager::GetDiskLabel(const CStdString& devicePath)
   if(GetVolumeInformationW(CStdStringW(strDevice).c_str(), cVolumenName, 127, NULL, NULL, NULL, cFSName, 127)==0)
     return "";
   g_charsetConverter.wToUTF8(cVolumenName, strDevice);
-  return strDevice.TrimRight(" ");
+  return StringUtils::TrimRight(strDevice, " ");
 #else
   return MEDIA_DETECT::CDetectDVDMedia::GetDVDLabel();
 #endif
index 9844987..7a0c523 100644 (file)
@@ -273,7 +273,7 @@ CCPUInfo::CCPUInfo(void)
         {
           needle+=2;
           m_cores[nCurrId].m_strVendor = needle;
-          m_cores[nCurrId].m_strVendor.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strVendor);
         }
       }
       else if (strncmp(buffer, "Processor", strlen("Processor"))==0)
@@ -284,7 +284,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuModel = needle;
           m_cores[nCurrId].m_strModel = m_cpuModel;
-          m_cores[nCurrId].m_strModel.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strModel);
         }
       }
       else if (strncmp(buffer, "BogoMIPS", strlen("BogoMIPS"))==0)
@@ -295,7 +295,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuBogoMips = needle;
           m_cores[nCurrId].m_strBogoMips = m_cpuBogoMips;
-          m_cores[nCurrId].m_strBogoMips.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strBogoMips);
         }
       }
       else if (strncmp(buffer, "Hardware", strlen("Hardware"))==0)
@@ -306,7 +306,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuHardware = needle;
           m_cores[nCurrId].m_strHardware = m_cpuHardware;
-          m_cores[nCurrId].m_strHardware.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strHardware);
         }
       }
       else if (strncmp(buffer, "Revision", strlen("Revision"))==0)
@@ -317,7 +317,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuRevision = needle;
           m_cores[nCurrId].m_strRevision = m_cpuRevision;
-          m_cores[nCurrId].m_strRevision.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strRevision);
         }
       }
       else if (strncmp(buffer, "Serial", strlen("Serial"))==0)
@@ -328,7 +328,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuSerial = needle;
           m_cores[nCurrId].m_strSerial = m_cpuSerial;
-          m_cores[nCurrId].m_strSerial.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strSerial);
         }
       }
       else if (strncmp(buffer, "model name", strlen("model name"))==0)
@@ -339,7 +339,7 @@ CCPUInfo::CCPUInfo(void)
           needle+=2;
           m_cpuModel = needle;
           m_cores[nCurrId].m_strModel = m_cpuModel;
-          m_cores[nCurrId].m_strModel.Trim();
+          StringUtils::Trim(m_cores[nCurrId].m_strModel);
         }
       }
       else if (strncmp(buffer, "flags", 5) == 0)
index 3d99afd..a550e91 100644 (file)
@@ -147,9 +147,8 @@ bool CLangCodeExpander::ConvertTwoToThreeCharCode(CStdString& strThreeCharCode,
   if ( strTwoCharCode.length() == 2 )
   {
     CStdString strTwoCharCodeLower( strTwoCharCode );
-    strTwoCharCodeLower.MakeLower();
-    strTwoCharCodeLower.TrimLeft();
-    strTwoCharCodeLower.TrimRight();
+    StringUtils::ToLower(strTwoCharCodeLower);
+    StringUtils::Trim(strTwoCharCodeLower);
 
     for (unsigned int index = 0; index < sizeof(CharCode2To3) / sizeof(CharCode2To3[0]); ++index)
     {
@@ -226,9 +225,8 @@ bool CLangCodeExpander::ConvertLinuxToWindowsRegionCodes(const CStdString& strTw
     return false;
 
   CStdString strLower( strTwoCharCode );
-  strLower.MakeLower();
-  strLower.TrimLeft();
-  strLower.TrimRight();
+  StringUtils::ToLower(strLower);
+  StringUtils::Trim(strLower);
   for (unsigned int index = 0; index < sizeof(RegionCode2To3) / sizeof(RegionCode2To3[0]); ++index)
   {
     if (strLower.Equals(RegionCode2To3[index].old))
@@ -327,7 +325,7 @@ bool CLangCodeExpander::ReverseLookup(const CStdString& desc, CStdString& code)
     return false;
 
   CStdString descTmp(desc);
-  descTmp.Trim();
+  StringUtils::Trim(descTmp);
   STRINGLOOKUPTABLE::iterator it;
   for (it = m_mapUser.begin(); it != m_mapUser.end() ; it++)
   {
@@ -364,9 +362,9 @@ bool CLangCodeExpander::LookupInMap(CStdString& desc, const CStdString& code)
   STRINGLOOKUPTABLE::iterator it;
   //Make sure we convert to lowercase before trying to find it
   CStdString sCode(code);
-  sCode.MakeLower();
-  sCode.TrimLeft();
-  sCode.TrimRight();
+  StringUtils::ToLower(sCode);
+  StringUtils::Trim(sCode);
+
   it = m_mapUser.find(sCode);
   if (it != m_mapUser.end())
   {
@@ -383,9 +381,9 @@ bool CLangCodeExpander::LookupInDb(CStdString& desc, const CStdString& code)
 
   long longcode;
   CStdString sCode(code);
-  sCode.MakeLower();
-  sCode.TrimLeft();
-  sCode.TrimRight();
+  StringUtils::ToLower(sCode);
+  StringUtils::Trim(sCode);
+
   if(sCode.length() == 2)
   {
     longcode = MAKECODE('\0', '\0', sCode[0], sCode[1]);
index e6728c9..84a81dd 100644 (file)
@@ -427,7 +427,7 @@ void CScraperParser::Clean(CStdString& strDirty)
       strBuffer = strDirty.substr(i+11,i2-i-11);
       CStdString strConverted(strBuffer);
       HTML::CHTMLUtil::RemoveTags(strConverted);
-      RemoveWhiteSpace(strConverted);
+      StringUtils::Trim(strConverted);
       strDirty.erase(i,i2-i+11);
       strDirty.Insert(i,strConverted);
       i += strConverted.size();
@@ -442,7 +442,7 @@ void CScraperParser::Clean(CStdString& strDirty)
     if ((i2=strDirty.Find("!!!TRIM!!!",i+10)) != -1)
     {
       strBuffer = strDirty.substr(i+10,i2-i-10);
-      RemoveWhiteSpace(strBuffer);
+      StringUtils::Trim(strBuffer);
       strDirty.erase(i,i2-i+10);
       strDirty.Insert(i,strBuffer);
       i += strBuffer.size();
@@ -462,7 +462,7 @@ void CScraperParser::Clean(CStdString& strDirty)
       CStdStringW wConverted;
       HTML::CHTMLUtil::ConvertHTMLToW(wbuffer,wConverted);
       g_charsetConverter.fromW(wConverted,strBuffer,GetSearchStringEncoding());
-      RemoveWhiteSpace(strBuffer);
+      StringUtils::Trim(strBuffer);
       ConvertJSON(strBuffer);
       strDirty.erase(i,i2-i+14);
       strDirty.Insert(i,strBuffer);
@@ -488,12 +488,6 @@ void CScraperParser::Clean(CStdString& strDirty)
   }
 }
 
-void CScraperParser::RemoveWhiteSpace(CStdString &string)
-{
-  string.TrimLeft(" \t\r\n");
-  string.TrimRight(" \t\r\n");
-}
-
 void CScraperParser::ConvertJSON(CStdString &string)
 {
   CRegExp reg;
index 4069201..9e224e1 100644 (file)
@@ -64,10 +64,6 @@ private:
   void ParseExpression(const CStdString& input, CStdString& dest, TiXmlElement* element, bool bAppend);
   void ParseNext(TiXmlElement* element);
   void Clean(CStdString& strDirty);
-  /*! \brief Remove spaces, tabs, and newlines from a string
-   \param string the string in question, which will be modified.
-   */
-  void RemoveWhiteSpace(CStdString &string);
   void ConvertJSON(CStdString &string);
   void ClearBuffers();
   void GetBufferParams(bool* result, const char* attribute, bool defvalue);
index 9392416..15d2810 100644 (file)
@@ -2458,13 +2458,6 @@ public:
     return *this;
   }
 
-
-  MYTYPE& Normalize()
-  {
-    return Trim().ToLower();
-  }
-
-
   // -------------------------------------------------------------------------
   // CStdStr -- Direct access to character buffer.  In the MS' implementation,
   // the at() function that we use here also calls _Freeze() providing us some
@@ -3013,65 +3006,6 @@ public:
 
 #endif
 
-
-  // -------------------------------------------------------------------------
-  // Trim and its variants
-  // -------------------------------------------------------------------------
-  MYTYPE& Trim()
-  {
-    return TrimLeft().TrimRight();
-  }
-
-  MYTYPE& TrimLeft()
-  {
-    this->erase(this->begin(),
-      std::find_if(this->begin(), this->end(), NotSpace<CT>()));
-
-    return *this;
-  }
-
-  MYTYPE&  TrimLeft(CT tTrim)
-  {
-    this->erase(0, this->find_first_not_of(tTrim));
-    return *this;
-  }
-
-  MYTYPE&  TrimLeft(PCMYSTR szTrimChars)
-  {
-    this->erase(0, this->find_first_not_of(szTrimChars));
-    return *this;
-  }
-
-  MYTYPE& TrimRight()
-  {
-    // NOTE:  When comparing reverse_iterators here (MYRITER), I avoid using
-    // operator!=.  This is because namespace rel_ops also has a template
-    // operator!= which conflicts with the global operator!= already defined
-    // for reverse_iterator in the header <utility>.
-    // Thanks to John James for alerting me to this.
-
-    MYRITER it = std::find_if(this->rbegin(), this->rend(), NotSpace<CT>());
-    if ( !(this->rend() == it) )
-      this->erase(this->rend() - it);
-
-    this->erase(!(it == this->rend()) ? this->find_last_of(*it) + 1 : 0);
-    return *this;
-  }
-
-  MYTYPE&  TrimRight(CT tTrim)
-  {
-    MYSIZE nIdx  = this->find_last_not_of(tTrim);
-    this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);
-    return *this;
-  }
-
-  MYTYPE&  TrimRight(PCMYSTR szTrimChars)
-  {
-    MYSIZE nIdx  = this->find_last_not_of(szTrimChars);
-    this->erase(MYBASE::npos == nIdx ? 0 : ++nIdx);
-    return *this;
-  }
-
   void      FreeExtra()
   {
     MYTYPE mt;
index 2d15f3a..29fae76 100644 (file)
@@ -233,12 +233,26 @@ std::string& StringUtils::TrimLeft(std::string &str)
   return str;
 }
 
+std::string& StringUtils::TrimLeft(std::string &str, const std::string& chars)
+{
+  size_t nidx = str.find_first_not_of(chars);
+  str.substr(nidx == str.npos ? 0 : nidx).swap(str);
+  return str;
+}
+
 std::string& StringUtils::TrimRight(std::string &str)
 {
   str.erase(::find_if(str.rbegin(), str.rend(), ::not1(::ptr_fun(isspace_c))).base(), str.end());
   return str;
 }
 
+std::string& StringUtils::TrimRight(std::string &str, const std::string& chars)
+{
+  size_t nidx = str.find_last_not_of(chars);
+  str.erase(str.npos == nidx ? 0 : ++nidx);
+  return str;
+}
+
 std::string& StringUtils::RemoveDuplicatedSpacesAndTabs(std::string& str)
 {
   std::string::iterator it = str.begin();
@@ -594,8 +608,7 @@ int StringUtils::DateStringToYYYYMMDD(const CStdString &dateString)
 long StringUtils::TimeStringToSeconds(const CStdString &timeString)
 {
   CStdString strCopy(timeString);
-  strCopy.TrimLeft(" \n\r\t");
-  strCopy.TrimRight(" \n\r\t");
+  StringUtils::Trim(strCopy);
   if(StringUtils::EndsWithNoCase(strCopy, " min"))
   {
     // this is imdb format of "XXX min"
index 36c887f..7799859 100644 (file)
@@ -64,7 +64,9 @@ public:
   static std::string Right(const std::string &str, size_t count);
   static std::string& Trim(std::string &str);
   static std::string& TrimLeft(std::string &str);
+  static std::string& TrimLeft(std::string &str, const std::string &chars);
   static std::string& TrimRight(std::string &str);
+  static std::string& TrimRight(std::string &str, const std::string &chars);
   static std::string& RemoveDuplicatedSpacesAndTabs(std::string& str);
   static int Replace(std::string &str, char oldChar, char newChar);
   static int Replace(std::string &str, const std::string &oldStr, const std::string &newStr);
index 5c522bc..5eab2da 100644 (file)
@@ -718,7 +718,7 @@ CStdString CSysInfo::GetLinuxDistro()
       result = buffer;
     pclose(pipe);
     if (!result.empty())
-      return result.Trim();
+      return StringUtils::Trim(result);
   }
 
   FILE* file = NULL;
@@ -731,7 +731,7 @@ CStdString CSysInfo::GetLinuxDistro()
       {
         result = buffer;
         if (!result.empty())
-          return result.Trim();
+          return StringUtils::Trim(result);
       }
       fclose(file);
     }
@@ -767,7 +767,7 @@ CStdString CSysInfo::GetUnameVersion()
     {
       result = buffer;
 #if defined(TARGET_DARWIN)
-      result.Trim();
+      StringUtils::Trim(result);
       result += ", "; 
       result += GetDarwinVersionString();
 #endif
@@ -778,7 +778,7 @@ CStdString CSysInfo::GetUnameVersion()
   }
 #endif//else !TARGET_ANDROID
 
-  return result.Trim();
+  return StringUtils::Trim(result);
 }
 #endif
 
index 5f625c1..fa589c0 100644 (file)
@@ -106,7 +106,7 @@ void CTextSearch::GetAndCutNextTerm(CStdString &strSearchTerm, CStdString &strNe
 void CTextSearch::ExtractSearchTerms(const CStdString &strSearchTerm, TextSearchDefault defaultSearchMode)
 {
   CStdString strParsedSearchTerm(strSearchTerm);
-  strParsedSearchTerm = strParsedSearchTerm.Trim();
+  StringUtils::Trim(strParsedSearchTerm);
 
   if (!m_bCaseSensitive)
     strParsedSearchTerm = strParsedSearchTerm.ToLower();
@@ -117,7 +117,7 @@ void CTextSearch::ExtractSearchTerms(const CStdString &strSearchTerm, TextSearch
 
   while (strParsedSearchTerm.length() > 0)
   {
-    strParsedSearchTerm = strParsedSearchTerm.TrimLeft();
+    StringUtils::TrimLeft(strParsedSearchTerm);
 
     if (StringUtils::StartsWith(strParsedSearchTerm, "!") || StringUtils::StartsWithNoCase(strParsedSearchTerm, "not"))
     {
@@ -160,6 +160,6 @@ void CTextSearch::ExtractSearchTerms(const CStdString &strSearchTerm, TextSearch
       bNextNOT = (defaultSearchMode == SEARCH_DEFAULT_NOT);
     }
 
-    strParsedSearchTerm = strParsedSearchTerm.TrimLeft();
+    StringUtils::TrimLeft(strParsedSearchTerm);
   }
 }
index 63d53ed..e0a694a 100644 (file)
@@ -1091,8 +1091,8 @@ void URIUtils::CreateArchivePath(CStdString& strUrlPath,
   strUrlPath += strBuffer;
 
   strBuffer = strFilePathInArchive;
-  strBuffer.Replace('\\', '/');
-  strBuffer.TrimLeft('/');
+  StringUtils::Replace(strBuffer, '\\', '/');
+  StringUtils::TrimLeft(strBuffer, "/");
 
   strUrlPath += "/";
   strUrlPath += strBuffer;
index 4094150..12fd114 100644 (file)
@@ -155,7 +155,7 @@ void CWeatherJob::LocalizeOverview(CStdString &str)
     LocalizeOverviewToken(words[i]);
     str += words[i] + " ";
   }
-  str.TrimRight(" ");
+  StringUtils::TrimRight(str);
 }
 
 // input param must be kmh
index 1be94b1..ec02264 100644 (file)
@@ -116,16 +116,8 @@ void CLog::Log(int loglevel, const char *format, ... )
     m_repeatLine      = strData;
     m_repeatLogLevel  = loglevel;
 
-    unsigned int length = 0;
-    while ( length != strData.length() )
-    {
-      length = strData.length();
-      strData.TrimRight(" ");
-      strData.TrimRight('\n');
-      strData.TrimRight("\r");
-    }
-
-    if (!length)
+    StringUtils::TrimRight(strData);
+    if (strData.empty())
       return;
     
     OutputDebugString(strData);
index 073a114..2df445b 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include "utils/XBMCTinyXML.h"
+#include "utils/StringUtils.h"
 #include "test/TestUtils.h"
 
 #include "gtest/gtest.h"
@@ -62,7 +63,7 @@ TEST(TestXBMCTinyXML, ParseFromFileHandle)
     if (url && url->FirstChild())
     {
       CStdString str = url->FirstChild()->ValueStr();
-      retval = (str.Trim() == "http://api.themoviedb.org/3/movie/12244?api_key=57983e31fb435df4df77afb854740ea9&language=en???");
+      retval = (StringUtils::Trim(str) == "http://api.themoviedb.org/3/movie/12244?api_key=57983e31fb435df4df77afb854740ea9&language=en???");
     }
   }
   EXPECT_TRUE(retval);
index 88187b6..74eafb4 100644 (file)
@@ -2393,7 +2393,7 @@ int CVideoDatabase::SetDetailsForMusicVideo(const CStdString& strFilenameAndPath
       for (unsigned int i = 0; i < details.m_artist.size(); i++)
       {
         CStdString artist = details.m_artist[i];
-        artist.Trim();
+        StringUtils::Trim(artist);
         int idArtist = AddActor(artist,"");
         AddArtistToMusicVideo(idMVideo, idArtist);
       }
@@ -8097,7 +8097,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
 
     if ( ! filesToDelete.empty() )
     {
-      filesToDelete.TrimRight(",");
+      StringUtils::TrimRight(filesToDelete, ",");
       // now grab them movies
       sql = PrepareSQL("select idMovie from movie where idFile in (%s)",filesToDelete.c_str());
       m_pDS->query(sql.c_str());
@@ -8163,7 +8163,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
 
     if ( ! moviesToDelete.empty() )
     {
-      moviesToDelete = "(" + moviesToDelete.TrimRight(",") + ")";
+      moviesToDelete = "(" + StringUtils::TrimRight(moviesToDelete, ",") + ")";
 
       CLog::Log(LOGDEBUG, "%s: Cleaning movie table", __FUNCTION__);
       sql = "delete from movie where idMovie in " + moviesToDelete;
@@ -8196,7 +8196,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
 
     if ( ! episodesToDelete.empty() )
     {
-      episodesToDelete = "(" + episodesToDelete.TrimRight(",") + ")";
+      episodesToDelete = "(" + StringUtils::TrimRight(episodesToDelete, ",") + ")";
 
       CLog::Log(LOGDEBUG, "%s: Cleaning episode table", __FUNCTION__);
       sql = "delete from episode where idEpisode in " + episodesToDelete;
@@ -8228,7 +8228,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
     m_pDS->close();
     if (!strIds.empty())
     {
-      strIds.TrimRight(",");
+      StringUtils::TrimRight(strIds, ",");
       sql = PrepareSQL("delete from path where idPath in (%s)",strIds.c_str());
       m_pDS->exec(sql.c_str());
       sql = PrepareSQL("delete from tvshowlinkpath where idPath in (%s)",strIds.c_str());
@@ -8258,7 +8258,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
     m_pDS->close();
     if (!showsToDelete.empty())
     {
-      sql = "delete from tvshow where idShow in (" + showsToDelete.TrimRight(",") + ")";
+      sql = "delete from tvshow where idShow in (" + StringUtils::TrimRight(showsToDelete, ",") + ")";
       m_pDS->exec(sql.c_str());
     }
 
@@ -8290,7 +8290,7 @@ void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const se
 
     if ( ! musicVideosToDelete.empty() )
     {
-      musicVideosToDelete = "(" + musicVideosToDelete.TrimRight(",") + ")";
+      musicVideosToDelete = "(" + StringUtils::TrimRight(musicVideosToDelete, ",") + ")";
 
       CLog::Log(LOGDEBUG, "%s: Cleaning musicvideo table", __FUNCTION__);
       sql = "delete from musicvideo where idMVideo in " + musicVideosToDelete;
index 38ea5bc..bcb7d21 100644 (file)
@@ -549,7 +549,7 @@ const CStdString CVideoInfoTag::GetCast(bool bIncludeRole /*= false*/) const
       character = StringUtils::Format("%s %s %s\n", it->strName.c_str(), g_localizeStrings.Get(20347).c_str(), it->strRole.c_str());
     strLabel += character;
   }
-  return strLabel.TrimRight("\n");
+  return StringUtils::TrimRight(strLabel, "\n");
 }
 
 void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prioritise)
index 11c7978..b26f585 100644 (file)
@@ -368,7 +368,7 @@ void CGUIDialogVideoInfo::Update()
     if (m_movieItem->GetVideoInfoTag()->m_playCount == 0 && !CSettings::Get().GetBool("videolibrary.showunwatchedplots"))
       strTmp = g_localizeStrings.Get(20370);
 
-  strTmp.Trim();
+  StringUtils::Trim(strTmp);
   SetLabel(CONTROL_TEXTAREA, strTmp);
 
   CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_LIST, 0, 0, m_castList);
index 04ab450..ac1e6f8 100644 (file)
@@ -313,7 +313,7 @@ bool CWIN32Util::XBMCShellExecute(const CStdString &strPath, bool bWaitForScript
   CStdString strParams;
   CStdString strWorkingDir;
 
-  strCommand.Trim();
+  StringUtils::Trim(strCommand);
   if (strCommand.empty())
   {
     return false;
@@ -977,7 +977,8 @@ CStdString CWIN32Util::GetDiskLabel(const CStdString& strPath)
   URIUtils::AddSlashAtEnd(strDrive);
   if(GetVolumeInformation(strDrive.c_str(), cVolumenName, 127, NULL, NULL, NULL, cFSName, 127)==0)
     return "";
-  return CStdString(cVolumenName).TrimRight(" ");
+  CStdString volume = cVolumenName;
+  return StringUtils::TrimRight(volume, " ");
 }
 
 extern "C"
index bd22dbf..0ac17ab 100644 (file)
@@ -27,6 +27,7 @@
 #include "system.h"
 #include "PlatformInclude.h"
 #include "utils/XBMCTinyXML.h"
+#include "utils/StringUtils.h"
 #include "../xbmc/utils/log.h"
 
 #if defined(TARGET_FREEBSD)
@@ -89,8 +90,7 @@ bool CXRandR::Query(bool force)
   {
     XOutput xoutput;
     xoutput.name = output->Attribute("name");
-    xoutput.name.TrimLeft(" \n\r\t");
-    xoutput.name.TrimRight(" \n\r\t");
+    StringUtils::Trim(xoutput.name);
     xoutput.isConnected = (strcasecmp(output->Attribute("connected"), "true") == 0);
     xoutput.w = (output->Attribute("w") != NULL ? atoi(output->Attribute("w")) : 0);
     xoutput.h = (output->Attribute("h") != NULL ? atoi(output->Attribute("h")) : 0);
@@ -317,11 +317,9 @@ void CXRandR::LoadCustomModeLinesToAllOutputs(void)
   for (TiXmlElement* modeline = pRootElement->FirstChildElement("modeline"); modeline; modeline = modeline->NextSiblingElement("modeline"))
   {
     name = modeline->Attribute("label");
-    name.TrimLeft(" \n\t\r");
-    name.TrimRight(" \n\t\r");
+    StringUtils::Trim(name);
     strModeLine = modeline->FirstChild()->Value();
-    strModeLine.TrimLeft(" \n\t\r");
-    strModeLine.TrimRight(" \n\t\r");
+    StringUtils::Trim(strModeLine);
     if (getenv("XBMC_BIN_HOME"))
     {
       snprintf(cmd, sizeof(cmd), "%s/xbmc-xrandr --newmode \"%s\" %s > /dev/null 2>&1", getenv("XBMC_BIN_HOME"),
index f2289fb..7b20f7e 100644 (file)
@@ -54,7 +54,7 @@ bool CEGLNativeTypeAmlogic::CheckCompatibility()
 
   aml_get_sysfs_str(modalias.c_str(), name, 255);
   CStdString strName = name;
-  strName.Trim();
+  StringUtils::Trim(strName);
   if (strName == "platform:mesonfb")
     return true;
   return false;
@@ -243,7 +243,7 @@ bool CEGLNativeTypeAmlogic::ModeToResolution(const char *mode, RESOLUTION_INFO *
     return false;
 
   CStdString fromMode = mode;
-  fromMode.Trim();
+  StringUtils::Trim(fromMode);
   // strips, for example, 720p* to 720p
   // the * indicate the 'native' mode of the display
   if (fromMode.Right(1) == "*")
index b4b876c..de6c39b 100644 (file)
@@ -1793,7 +1793,8 @@ bool CGUIMediaWindow::GetFilteredItems(const CStdString &filter, CFileItemList &
     result = GetAdvanceFilteredItems(items);
 
   CStdString trimmedFilter(filter);
-  trimmedFilter.TrimLeft().ToLower();
+  StringUtils::TrimLeft(trimmedFilter);
+  StringUtils::ToLower(trimmedFilter);
   
   if (trimmedFilter.empty())
     return result;