aboutsummaryrefslogtreecommitdiff
path: root/xbmc/utils/StringUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/utils/StringUtils.cpp')
-rw-r--r--xbmc/utils/StringUtils.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/xbmc/utils/StringUtils.cpp b/xbmc/utils/StringUtils.cpp
index 56bb28ef99..508dde89e8 100644
--- a/xbmc/utils/StringUtils.cpp
+++ b/xbmc/utils/StringUtils.cpp
@@ -24,21 +24,26 @@
// Purpose: ATL split string utility
// Author: Paul J. Weiss
//
-// Modified to use J O'Leary's CStdString class by kraqh3d
+// Modified to use J O'Leary's std::string class by kraqh3d
//
//------------------------------------------------------------------------
#include "StringUtils.h"
-#include "utils/RegExp.h"
#include "utils/fstrcmp.h"
#include "Util.h"
#include <locale>
+#include <assert.h>
#include <math.h>
#include <sstream>
#include <time.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <memory.h>
+#include <algorithm>
+#include "utils/RegExp.h" // don't move or std functions end up in PCRE namespace
#define FORMAT_BLOCK_SIZE 512 // # of bytes for initial allocation for printf
@@ -47,9 +52,8 @@ using namespace std;
const char* ADDON_GUID_RE = "^(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}(\\}){0,1}$";
/* empty string for use in returns by ref */
-const CStdString StringUtils::EmptyString = "";
const std::string StringUtils::Empty = "";
-CStdString StringUtils::m_lastUUID = "";
+std::string StringUtils::m_lastUUID = "";
// Copyright (c) Leigh Brasington 2012. All rights reserved.
// This code may be used and reproduced without written permission.
@@ -350,7 +354,7 @@ wchar_t toupperUnicode(const wchar_t& c)
void StringUtils::ToUpper(string &str)
{
- transform(str.begin(), str.end(), str.begin(), ::toupper);
+ std::transform(str.begin(), str.end(), str.begin(), ::toupper);
}
void StringUtils::ToUpper(wstring &str)
@@ -423,7 +427,7 @@ string StringUtils::Mid(const string &str, size_t first, size_t count /* = strin
if (first > str.size())
return string();
- ASSERT(first + count <= str.size());
+ assert(first + count <= str.size());
return str.substr(first, count);
}
@@ -713,7 +717,7 @@ std::vector<std::string> StringUtils::Split(const std::string& input, const char
// returns the number of occurrences of strFind in strInput.
-int StringUtils::FindNumber(const CStdString& strInput, const CStdString &strFind)
+int StringUtils::FindNumber(const std::string& strInput, const std::string &strFind)
{
size_t pos = strInput.find(strFind, 0);
int numfound = 0;
@@ -791,7 +795,7 @@ int64_t StringUtils::AlphaNumericCompare(const wchar_t *left, const wchar_t *rig
return 0; // files are the same
}
-int StringUtils::DateStringToYYYYMMDD(const CStdString &dateString)
+int StringUtils::DateStringToYYYYMMDD(const std::string &dateString)
{
vector<string> days = StringUtils::Split(dateString, '-');
if (days.size() == 1)
@@ -804,9 +808,9 @@ int StringUtils::DateStringToYYYYMMDD(const CStdString &dateString)
return -1;
}
-long StringUtils::TimeStringToSeconds(const CStdString &timeString)
+long StringUtils::TimeStringToSeconds(const std::string &timeString)
{
- CStdString strCopy(timeString);
+ std::string strCopy(timeString);
StringUtils::Trim(strCopy);
if(StringUtils::EndsWithNoCase(strCopy, " min"))
{
@@ -826,7 +830,7 @@ long StringUtils::TimeStringToSeconds(const CStdString &timeString)
}
}
-CStdString StringUtils::SecondsToTimeString(long lSeconds, TIME_FORMAT format)
+std::string StringUtils::SecondsToTimeString(long lSeconds, TIME_FORMAT format)
{
int hh = lSeconds / 3600;
lSeconds = lSeconds % 3600;
@@ -835,7 +839,7 @@ CStdString StringUtils::SecondsToTimeString(long lSeconds, TIME_FORMAT format)
if (format == TIME_FORMAT_GUESS)
format = (hh >= 1) ? TIME_FORMAT_HH_MM_SS : TIME_FORMAT_MM_SS;
- CStdString strHMS;
+ std::string strHMS;
if (format & TIME_FORMAT_HH)
strHMS += StringUtils::Format("%02.2i", hh);
else if (format & TIME_FORMAT_H)
@@ -847,7 +851,7 @@ CStdString StringUtils::SecondsToTimeString(long lSeconds, TIME_FORMAT format)
return strHMS;
}
-bool StringUtils::IsNaturalNumber(const CStdString& str)
+bool StringUtils::IsNaturalNumber(const std::string& str)
{
size_t i = 0, n = 0;
// allow whitespace,digits,whitespace
@@ -862,7 +866,7 @@ bool StringUtils::IsNaturalNumber(const CStdString& str)
return i == str.size() && n > 0;
}
-bool StringUtils::IsInteger(const CStdString& str)
+bool StringUtils::IsInteger(const std::string& str)
{
size_t i = 0, n = 0;
// allow whitespace,-,digits,whitespace
@@ -906,9 +910,9 @@ void StringUtils::RemoveCRLF(std::string& strLine)
StringUtils::TrimRight(strLine, "\n\r");
}
-CStdString StringUtils::SizeToString(int64_t size)
+std::string StringUtils::SizeToString(int64_t size)
{
- CStdString strLabel;
+ std::string strLabel;
const char prefixes[] = {' ','k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
unsigned int i = 0;
double s = (double)size;
@@ -999,11 +1003,11 @@ size_t StringUtils::FindWords(const char *str, const char *wordLowerCase)
// and repeat until we're done
} while (*s);
- return CStdString::npos;
+ return std::string::npos;
}
// assumes it is called from after the first open bracket is found
-int StringUtils::FindEndBracket(const CStdString &str, char opener, char closer, int startPos)
+int StringUtils::FindEndBracket(const std::string &str, char opener, char closer, int startPos)
{
int blocks = 1;
for (unsigned int i = startPos; i < str.size(); i++)
@@ -1018,7 +1022,7 @@ int StringUtils::FindEndBracket(const CStdString &str, char opener, char closer,
}
}
- return (int)CStdString::npos;
+ return (int)std::string::npos;
}
void StringUtils::WordToDigits(std::string &word)
@@ -1039,7 +1043,7 @@ void StringUtils::WordToDigits(std::string &word)
}
}
-CStdString StringUtils::CreateUUID()
+std::string StringUtils::CreateUUID()
{
/* This function generate a DCE 1.1, ISO/IEC 11578:1996 and IETF RFC-4122
* Version 4 conform local unique UUID based upon random number generation.
@@ -1086,19 +1090,19 @@ CStdString StringUtils::CreateUUID()
return UuidStrTmp;
}
-bool StringUtils::ValidateUUID(const CStdString &uuid)
+bool StringUtils::ValidateUUID(const std::string &uuid)
{
CRegExp guidRE;
guidRE.RegComp(ADDON_GUID_RE);
return (guidRE.RegFind(uuid.c_str()) == 0);
}
-double StringUtils::CompareFuzzy(const CStdString &left, const CStdString &right)
+double StringUtils::CompareFuzzy(const std::string &left, const std::string &right)
{
return (0.5 + fstrcmp(left.c_str(), right.c_str(), 0.0) * (left.length() + right.length())) / 2.0;
}
-int StringUtils::FindBestMatch(const CStdString &str, const vector<string> &strings, double &matchscore)
+int StringUtils::FindBestMatch(const std::string &str, const vector<string> &strings, double &matchscore)
{
int best = -1;
matchscore = 0;
@@ -1117,7 +1121,7 @@ int StringUtils::FindBestMatch(const CStdString &str, const vector<string> &stri
return best;
}
-bool StringUtils::ContainsKeyword(const CStdString &str, const vector<string> &keywords)
+bool StringUtils::ContainsKeyword(const std::string &str, const vector<string> &keywords)
{
for (vector<string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
{