summaryrefslogtreecommitdiffstats
path: root/src/lib/base/String.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/base/String.cpp')
-rw-r--r--src/lib/base/String.cpp62
1 files changed, 29 insertions, 33 deletions
diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp
index 97b8997..1ab3623 100644
--- a/src/lib/base/String.cpp
+++ b/src/lib/base/String.cpp
@@ -35,17 +35,17 @@
namespace barrier {
namespace string {
-String
+std::string
format(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
- String result = vformat(fmt, args);
+ std::string result = vformat(fmt, args);
va_end(args);
return result;
}
-String
+std::string
vformat(const char* fmt, va_list args)
{
// find highest indexed substitution and the locations of substitutions
@@ -111,7 +111,7 @@ vformat(const char* fmt, va_list args)
}
// substitute
- String result;
+ std::string result;
result.reserve(resultLength);
size_t src = 0;
for (int i = 0; i < n; ++i) {
@@ -124,13 +124,13 @@ vformat(const char* fmt, va_list args)
return result;
}
-String
+std::string
sprintf(const char* fmt, ...)
{
char tmp[1024];
char* buffer = tmp;
int len = (int)(sizeof(tmp) / sizeof(tmp[0]));
- String result;
+ std::string result;
while (buffer != NULL) {
// try printing into the buffer
va_list args;
@@ -162,23 +162,23 @@ sprintf(const char* fmt, ...)
void
findReplaceAll(
- String& subject,
- const String& find,
- const String& replace)
+ std::string& subject,
+ const std::string& find,
+ const std::string& replace)
{
size_t pos = 0;
- while ((pos = subject.find(find, pos)) != String::npos) {
+ while ((pos = subject.find(find, pos)) != std::string::npos) {
subject.replace(pos, find.length(), replace);
pos += replace.length();
}
}
-String
-removeFileExt(String filename)
+std::string
+removeFileExt(std::string filename)
{
size_t dot = filename.find_last_of('.');
- if (dot == String::npos) {
+ if (dot == std::string::npos) {
return filename;
}
@@ -186,7 +186,7 @@ removeFileExt(String filename)
}
void
-toHex(String& subject, int width, const char fill)
+toHex(std::string& subject, int width, const char fill)
{
std::stringstream ss;
ss << std::hex;
@@ -198,18 +198,18 @@ toHex(String& subject, int width, const char fill)
}
void
-uppercase(String& subject)
+uppercase(std::string& subject)
{
std::transform(subject.begin(), subject.end(), subject.begin(), ::toupper);
}
void
-removeChar(String& subject, const char c)
+removeChar(std::string& subject, const char c)
{
subject.erase(std::remove(subject.begin(), subject.end(), c), subject.end());
}
-String
+std::string
sizeTypeToString(size_t n)
{
std::stringstream ss;
@@ -218,7 +218,7 @@ sizeTypeToString(size_t n)
}
size_t
-stringToSizeType(String string)
+stringToSizeType(std::string string)
{
std::istringstream iss(string);
size_t value;
@@ -226,14 +226,14 @@ stringToSizeType(String string)
return value;
}
-std::vector<String>
-splitString(String string, const char c)
+std::vector<std::string>
+splitString(std::string string, const char c)
{
- std::vector<String> results;
+ std::vector<std::string> results;
size_t head = 0;
size_t separator = string.find(c);
- while (separator != String::npos) {
+ while (separator != std::string::npos) {
if (head!=separator) {
results.push_back(string.substr(head, separator - head));
}
@@ -252,26 +252,22 @@ splitString(String string, const char c)
// CaselessCmp
//
-bool
-CaselessCmp::cmpEqual(
- const String::value_type& a,
- const String::value_type& b)
+bool CaselessCmp::cmpEqual(const std::string::value_type& a,
+ const std::string::value_type& b)
{
// should use std::tolower but not in all versions of libstdc++ have it
return tolower(a) == tolower(b);
}
-bool
-CaselessCmp::cmpLess(
- const String::value_type& a,
- const String::value_type& b)
+bool CaselessCmp::cmpLess(const std::string::value_type& a,
+ const std::string::value_type& b)
{
// should use std::tolower but not in all versions of libstdc++ have it
return tolower(a) < tolower(b);
}
bool
-CaselessCmp::less(const String& a, const String& b)
+CaselessCmp::less(const std::string& a, const std::string& b)
{
return std::lexicographical_compare(
a.begin(), a.end(),
@@ -280,13 +276,13 @@ CaselessCmp::less(const String& a, const String& b)
}
bool
-CaselessCmp::equal(const String& a, const String& b)
+CaselessCmp::equal(const std::string& a, const std::string& b)
{
return !(less(a, b) || less(b, a));
}
bool
-CaselessCmp::operator()(const String& a, const String& b) const
+CaselessCmp::operator()(const std::string& a, const std::string& b) const
{
return less(a, b);
}