Navigation Menu

Skip to content

Commit

Permalink
Move Tokenize from Util to StringUtils and replace CStdString by std:…
Browse files Browse the repository at this point in the history
…:string.
  • Loading branch information
ace20022 committed Sep 24, 2013
1 parent 6d2989c commit ecf8892
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 120 deletions.
19 changes: 0 additions & 19 deletions xbmc/Util.cpp
Expand Up @@ -740,25 +740,6 @@ CStdString CUtil::GetNextPathname(const CStdString &path_template, int max)
return "";
}

void CUtil::Tokenize(const CStdString& path, vector<CStdString>& tokens, const string& delimiters)
{
// Tokenize ripped from http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-7.html
// Skip delimiters at beginning.
string::size_type lastPos = path.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = path.find_first_of(delimiters, lastPos);

while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(path.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = path.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = path.find_first_of(delimiters, lastPos);
}
}

void CUtil::StatToStatI64(struct _stati64 *result, struct stat *stat)
{
result->st_dev = stat->st_dev;
Expand Down
1 change: 0 additions & 1 deletion xbmc/Util.h
Expand Up @@ -91,7 +91,6 @@ class CUtil
static int64_t ToInt64(uint32_t high, uint32_t low);
static CStdString GetNextFilename(const CStdString &fn_template, int max);
static CStdString GetNextPathname(const CStdString &path_template, int max);
static void Tokenize(const CStdString& path, std::vector<CStdString>& tokens, const std::string& delimiters);
static void StatToStatI64(struct _stati64 *result, struct stat *stat);
static void Stat64ToStatI64(struct _stati64 *result, struct __stat64 *stat);
static void StatI64ToStat64(struct __stat64 *result, struct _stati64 *stat);
Expand Down
42 changes: 21 additions & 21 deletions xbmc/addons/GUIDialogAddonSettings.cpp
Expand Up @@ -286,19 +286,19 @@ bool CGUIDialogAddonSettings::ShowVirtualKeyboard(int iControl)
pDlg->Reset();

int selected = -1;
vector<CStdString> valuesVec;
vector<std::string> valuesVec;
if (setting->Attribute("values"))
CUtil::Tokenize(setting->Attribute("values"), valuesVec, "|");
StringUtils::Tokenize(setting->Attribute("values"), valuesVec, "|");
else if (setting->Attribute("lvalues"))
{ // localize
CUtil::Tokenize(setting->Attribute("lvalues"), valuesVec, "|");
StringUtils::Tokenize(setting->Attribute("lvalues"), valuesVec, "|");
for (unsigned int i = 0; i < valuesVec.size(); i++)
{
if (i == (unsigned int)atoi(value))
selected = i;
CStdString localized = m_addon->GetString(atoi(valuesVec[i]));
CStdString localized = m_addon->GetString(atoi(valuesVec[i].c_str()));
if (localized.IsEmpty())
localized = g_localizeStrings.Get(atoi(valuesVec[i]));
localized = g_localizeStrings.Get(atoi(valuesVec[i].c_str()));
valuesVec[i] = localized;
}
}
Expand All @@ -310,7 +310,7 @@ bool CGUIDialogAddonSettings::ShowVirtualKeyboard(int iControl)
for (unsigned int i = 0; i < valuesVec.size(); i++)
{
pDlg->Add(valuesVec[i]);
if (selected == (int)i || (selected < 0 && valuesVec[i].Equals(value)))
if (selected == (int)i || (selected < 0 && StringUtils::EqualsNoCase(valuesVec[i], value)))
pDlg->SetSelected(i); // FIXME: the SetSelected() does not select "i", it always defaults to the first position
}
pDlg->DoModal();
Expand Down Expand Up @@ -747,15 +747,15 @@ void CGUIDialogAddonSettings::CreateControls()
}
else if (strcmpi(type, "enum") == 0 || strcmpi(type, "labelenum") == 0)
{
vector<CStdString> valuesVec;
vector<CStdString> entryVec;
vector<std::string> valuesVec;
vector<std::string> entryVec;

pControl = new CGUISpinControlEx(*pOriginalSpin);
if (!pControl) return;
((CGUISpinControlEx *)pControl)->SetText(label);

if (!lvalues.IsEmpty())
CUtil::Tokenize(lvalues, valuesVec, "|");
StringUtils::Tokenize(lvalues, valuesVec, "|");
else if (values.Equals("$HOURS"))
{
for (unsigned int i = 0; i < 24; i++)
Expand All @@ -765,9 +765,9 @@ void CGUIDialogAddonSettings::CreateControls()
}
}
else
CUtil::Tokenize(values, valuesVec, "|");
StringUtils::Tokenize(values, valuesVec, "|");
if (!entries.IsEmpty())
CUtil::Tokenize(entries, entryVec, "|");
StringUtils::Tokenize(entries, entryVec, "|");

if(bSort && strcmpi(type, "labelenum") == 0)
std::sort(valuesVec.begin(), valuesVec.end(), sortstringbyname());
Expand All @@ -776,12 +776,12 @@ void CGUIDialogAddonSettings::CreateControls()
{
int iAdd = i;
if (entryVec.size() > i)
iAdd = atoi(entryVec[i]);
iAdd = atoi(entryVec[i].c_str());
if (!lvalues.IsEmpty())
{
CStdString replace = m_addon->GetString(atoi(valuesVec[i]));
CStdString replace = m_addon->GetString(atoi(valuesVec[i].c_str()));
if (replace.IsEmpty())
replace = g_localizeStrings.Get(atoi(valuesVec[i]));
replace = g_localizeStrings.Get(atoi(valuesVec[i].c_str()));
((CGUISpinControlEx *)pControl)->AddLabel(replace, iAdd);
}
else
Expand All @@ -802,11 +802,11 @@ void CGUIDialogAddonSettings::CreateControls()
((CGUISpinControlEx *)pControl)->SetText(label);
((CGUISpinControlEx *)pControl)->SetFloatValue(1.0f);

vector<CStdString> items = GetFileEnumValues(values, setting->Attribute("mask"), setting->Attribute("option"));
vector<std::string> items = GetFileEnumValues(values, setting->Attribute("mask"), setting->Attribute("option"));
for (unsigned int i = 0; i < items.size(); ++i)
{
((CGUISpinControlEx *)pControl)->AddLabel(items[i], i);
if (items[i].Equals(m_settings[id]))
if (StringUtils::EqualsNoCase(items[i], m_settings[id]))
((CGUISpinControlEx *)pControl)->SetValue(i);
}
}
Expand Down Expand Up @@ -933,7 +933,7 @@ CStdString CGUIDialogAddonSettings::GetAddonNames(const CStdString& addonIDslist
return retVal;
}

vector<CStdString> CGUIDialogAddonSettings::GetFileEnumValues(const CStdString &path, const CStdString &mask, const CStdString &options) const
vector<std::string> CGUIDialogAddonSettings::GetFileEnumValues(const CStdString &path, const CStdString &mask, const CStdString &options) const
{
// Create our base path, used for type "fileenum" settings
// replace $PROFILE with the profile path of the plugin/script
Expand All @@ -951,7 +951,7 @@ vector<CStdString> CGUIDialogAddonSettings::GetFileEnumValues(const CStdString &
else
CDirectory::GetDirectory(fullPath, items, "", XFILE::DIR_FLAG_NO_FILE_DIRS);

vector<CStdString> values;
vector<std::string> values;
for (int i = 0; i < items.Size(); ++i)
{
CFileItemPtr pItem = items[i];
Expand Down Expand Up @@ -998,15 +998,15 @@ bool CGUIDialogAddonSettings::GetCondition(const CStdString &condition, const in
bool bCondition = true;
bool bCompare = true;
bool bControlDependend = false;//flag if the condition depends on another control
vector<CStdString> conditionVec;
vector<std::string> conditionVec;

if (condition.Find("+") >= 0)
CUtil::Tokenize(condition, conditionVec, "+");
StringUtils::Tokenize(condition, conditionVec, "+");
else
{
bCondition = false;
bCompare = false;
CUtil::Tokenize(condition, conditionVec, "|");
StringUtils::Tokenize(condition, conditionVec, "|");
}

for (unsigned int i = 0; i < conditionVec.size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/addons/GUIDialogAddonSettings.h
Expand Up @@ -56,7 +56,7 @@ class CGUIDialogAddonSettings : public CGUIDialogBoxBase
\param options any options, such as "hideext" to hide extensions
\return the filenames in the path that match the mask
*/
std::vector<CStdString> GetFileEnumValues(const CStdString &path, const CStdString &mask, const CStdString &options) const;
std::vector<std::string> GetFileEnumValues(const CStdString &path, const CStdString &mask, const CStdString &options) const;

/*! \brief Translate list of addon IDs to list of addon names
\param addonIDslist comma seperated list of addon IDs
Expand Down
5 changes: 3 additions & 2 deletions xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecSSA.cpp
Expand Up @@ -25,6 +25,7 @@
#include "DVDClock.h"
#include "Util.h"
#include "utils/AutoPtrHandle.h"
#include "utils/StringUtils.h"

using namespace AUTOPTR;
using namespace std;
Expand Down Expand Up @@ -81,8 +82,8 @@ int CDVDOverlayCodecSSA::Decode(DemuxPacket *pPacket)
double beg, end;
size_t pos;
CStdString line, line2;
CStdStringArray lines;
CUtil::Tokenize((const char*)data, lines, "\r\n");
std::vector<std::string> lines;
StringUtils::Tokenize((const char*)data, lines, "\r\n");
for(size_t i=0; i<lines.size(); i++)
{
line = lines[i];
Expand Down
13 changes: 7 additions & 6 deletions xbmc/filesystem/CurlFile.cpp
Expand Up @@ -42,6 +42,7 @@
#include "SpecialProtocol.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
#include "utils/StringUtils.h"

using namespace XFILE;
using namespace XCURL;
Expand Down Expand Up @@ -71,9 +72,9 @@ extern "C" int debug_callback(CURL_HANDLE *handle, curl_infotype info, char *out

CStdString strLine;
strLine.append(output, size);
std::vector<CStdString> vecLines;
CUtil::Tokenize(strLine, vecLines, "\r\n");
std::vector<CStdString>::const_iterator it = vecLines.begin();
std::vector<std::string> vecLines;
StringUtils::Tokenize(strLine, vecLines, "\r\n");
std::vector<std::string>::const_iterator it = vecLines.begin();

char *infotype;
switch(info)
Expand Down Expand Up @@ -687,16 +688,16 @@ void CCurlFile::ParseAndCorrectUrl(CURL &url2)
/* it won't be so let's handle that case */

CStdString partial, filename(url2.GetFileName());
CStdStringArray array;
std::vector<std::string> array;

// if server sent us the filename in non-utf8, we need send back with same encoding.
if (url2.GetProtocolOption("utf8") == "0")
g_charsetConverter.utf8ToStringCharset(filename);

/* TODO: create a tokenizer that doesn't skip empty's */
CUtil::Tokenize(filename, array, "/");
StringUtils::Tokenize(filename, array, "/");
filename.Empty();
for(CStdStringArray::iterator it = array.begin(); it != array.end(); it++)
for(std::vector<std::string>::iterator it = array.begin(); it != array.end(); it++)
{
if(it != array.begin())
filename += "/";
Expand Down
9 changes: 5 additions & 4 deletions xbmc/filesystem/File.cpp
Expand Up @@ -32,6 +32,7 @@
#include "utils/BitstreamStats.h"
#include "Util.h"
#include "URL.h"
#include "utils/StringUtils.h"

#include "commons/Exception.h"

Expand Down Expand Up @@ -94,19 +95,19 @@ bool CFile::Cache(const CStdString& strFileName, const CStdString& strDest, XFIL
CFile newFile;
if (URIUtils::IsHD(strDest)) // create possible missing dirs
{
vector<CStdString> tokens;
vector<std::string> tokens;
CStdString strDirectory = URIUtils::GetDirectory(strDest);
URIUtils::RemoveSlashAtEnd(strDirectory); // for the test below
if (!(strDirectory.size() == 2 && strDirectory[1] == ':'))
{
CURL url(strDirectory);
CStdString pathsep;
std::string pathsep;
#ifndef TARGET_POSIX
pathsep = "\\";
#else
pathsep = "/";
#endif
CUtil::Tokenize(url.GetFileName(),tokens,pathsep.c_str());
StringUtils::Tokenize(url.GetFileName(),tokens,pathsep.c_str());
CStdString strCurrPath;
// Handle special
if (!url.GetProtocol().IsEmpty()) {
Expand All @@ -115,7 +116,7 @@ bool CFile::Cache(const CStdString& strFileName, const CStdString& strDest, XFIL
} // If the directory has a / at the beginning, don't forget it
else if (strDirectory[0] == pathsep[0])
strCurrPath += pathsep;
for (vector<CStdString>::iterator iter=tokens.begin();iter!=tokens.end();++iter)
for (vector<std::string>::iterator iter=tokens.begin();iter!=tokens.end();++iter)
{
strCurrPath += *iter+pathsep;
CDirectory::Create(strCurrPath);
Expand Down
7 changes: 4 additions & 3 deletions xbmc/filesystem/FileDirectoryFactory.cpp
Expand Up @@ -48,6 +48,7 @@
#include "ZipManager.h"
#include "settings/AdvancedSettings.h"
#include "FileItem.h"
#include "utils/StringUtils.h"

using namespace XFILE;
using namespace PLAYLIST;
Expand Down Expand Up @@ -170,13 +171,13 @@ IFileDirectory* CFileDirectoryFactory::Create(const CStdString& strPath, CFileIt
CStdString strUrl;
URIUtils::CreateArchivePath(strUrl, "rar", strPath, "");

vector<CStdString> tokens;
CUtil::Tokenize(strPath,tokens,".");
vector<std::string> tokens;
StringUtils::Tokenize(strPath,tokens,".");
if (tokens.size() > 2)
{
if (strExtension.Equals(".001"))
{
if (tokens[tokens.size()-2].Equals("ts")) // .ts.001 - treat as a movie file to scratch some users itch
if (StringUtils::EqualsNoCase(tokens[tokens.size()-2], "ts")) // .ts.001 - treat as a movie file to scratch some users itch
return NULL;
}
CStdString token = tokens[tokens.size()-2];
Expand Down
13 changes: 7 additions & 6 deletions xbmc/filesystem/RarFile.cpp
Expand Up @@ -31,6 +31,7 @@
#include "FileItem.h"
#include "utils/log.h"
#include "UnrarXLib/rar.hpp"
#include "utils/StringUtils.h"

#ifndef TARGET_POSIX
#include <process.h>
Expand Down Expand Up @@ -545,18 +546,18 @@ void CRarFile::InitFromUrl(const CURL& url)
m_strPassword = url.GetUserName();
m_strPathInRar = url.GetFileName();

vector<CStdString> options;
CUtil::Tokenize(url.GetOptions().Mid(1), options, "&");
vector<std::string> options;
StringUtils::Tokenize(url.GetOptions().Mid(1), options, "&");

m_bFileOptions = 0;

for( vector<CStdString>::iterator it = options.begin();it != options.end(); it++)
for( vector<std::string>::iterator it = options.begin();it != options.end(); it++)
{
int iEqual = (*it).Find('=');
int iEqual = (*it).find('=');
if( iEqual >= 0 )
{
CStdString strOption = (*it).Left(iEqual);
CStdString strValue = (*it).Mid(iEqual+1);
CStdString strOption = StringUtils::Left((*it), iEqual);
CStdString strValue = StringUtils::Mid((*it), iEqual+1);

if( strOption.Equals("flags") )
m_bFileOptions = atoi(strValue.c_str());
Expand Down
7 changes: 4 additions & 3 deletions xbmc/filesystem/RarManager.cpp
Expand Up @@ -33,6 +33,7 @@

#include "dialogs/GUIDialogYesNo.h"
#include "guilib/GUIWindowManager.h"
#include "utils/StringUtils.h"

#include <set>

Expand Down Expand Up @@ -247,9 +248,9 @@ bool CRarManager::GetFilesInRar(CFileItemList& vecpItems, const CStdString& strR
pFileList = it->second.first;

CFileItemPtr pFileItem;
vector<CStdString> vec;
vector<std::string> vec;
set<CStdString> dirSet;
CUtil::Tokenize(strPathInRar,vec,"/");
StringUtils::Tokenize(strPathInRar,vec,"/");
unsigned int iDepth = vec.size();

ArchiveList_struct* pIterator;
Expand Down Expand Up @@ -277,7 +278,7 @@ bool CRarManager::GetFilesInRar(CFileItemList& vecpItems, const CStdString& strR
continue;

vec.clear();
CUtil::Tokenize(strName,vec,"/");
StringUtils::Tokenize(strName,vec,"/");
if (vec.size() < iDepth)
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions xbmc/filesystem/SmbFile.cpp
Expand Up @@ -26,12 +26,12 @@
#include "SmbFile.h"
#include "PasswordManager.h"
#include "SMBDirectory.h"
#include "Util.h"
#include <libsmbclient.h>
#include "settings/AdvancedSettings.h"
#include "settings/Settings.h"
#include "threads/SingleLock.h"
#include "utils/log.h"
#include "Util.h"
#include "utils/StringUtils.h"
#include "utils/TimeUtils.h"
#include "commons/Exception.h"
Expand Down Expand Up @@ -264,9 +264,9 @@ CStdString CSMB::URLEncode(const CURL &url)
flat += URLEncode(url.GetHostName());

/* okey sadly since a slash is an invalid name we have to tokenize */
std::vector<CStdString> parts;
std::vector<CStdString>::iterator it;
CUtil::Tokenize(url.GetFileName(), parts, "/");
std::vector<std::string> parts;
std::vector<std::string>::iterator it;
StringUtils::Tokenize(url.GetFileName(), parts, "/");
for( it = parts.begin(); it != parts.end(); it++ )
{
flat += "/";
Expand Down

0 comments on commit ecf8892

Please sign in to comment.