Fix Namespaces, add ends_with functions
This commit is contained in:
@@ -4,5 +4,3 @@
|
||||
.*.swp
|
||||
.AppleDouble
|
||||
lib
|
||||
Libraries
|
||||
fixPermissions.sh
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "Random.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Random {
|
||||
|
||||
std::string CreateRandomString(size_t length)
|
||||
{
|
||||
auto randchar = []() -> char
|
||||
{
|
||||
const char charset[] =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
const size_t max_index = (sizeof(charset) - 1);
|
||||
return charset[ rand() % max_index ];
|
||||
};
|
||||
std::string str(length,0);
|
||||
std::generate_n(str.begin(), length, randchar);
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace Random
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Utilities {
|
||||
namespace StringAlgorithm {
|
||||
namespace Internal {
|
||||
|
||||
size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth)
|
||||
@@ -48,6 +48,24 @@ bool istarts_with(const std::string& subject, const std::string& find)
|
||||
return starts_with(s, f);
|
||||
}
|
||||
|
||||
bool ends_with(const std::string& subject, const std::string& find)
|
||||
{
|
||||
if (subject.size() >= find.size() && subject.compare(subject.size() - find.size(), find.size(), find) == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool iends_with(const std::string& subject, const std::string& find)
|
||||
{
|
||||
std::string s(subject);
|
||||
std::string f(find);
|
||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||
std::transform(f.begin(), f.end(), f.begin(), ::tolower);
|
||||
|
||||
return ends_with(s, f);
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& subject, const char& delimiter)
|
||||
{
|
||||
std::stringstream ss(subject);
|
||||
@@ -100,4 +118,4 @@ std::string::const_iterator find_nth(const std::string& haystack, const std::str
|
||||
return iterator;
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
} // namespace StringAlgorithm
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Tribool.h"
|
||||
|
||||
|
||||
namespace Utilities {
|
||||
namespace Tribool {
|
||||
|
||||
Tribool::Tribool() : m_value(TriboolValue::Indeterminate)
|
||||
{
|
||||
@@ -135,4 +135,4 @@ Tribool operator!=(const Tribool& lhs, const Tribool::IndeterminateKeywordType&)
|
||||
return Tribool(Tribool::Indeterminate) != lhs;
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
} // namespace Tribool
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef RANDOM_H
|
||||
#define RANDOM_H
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Random {
|
||||
|
||||
std::string CreateRandomString(size_t length);
|
||||
|
||||
} // namespace Random
|
||||
|
||||
#endif // RANDOM_H
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Utilities {
|
||||
namespace StringAlgorithm {
|
||||
namespace Internal {
|
||||
|
||||
size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth);
|
||||
@@ -18,6 +18,9 @@ bool iequals(const std::string& str1, const std::string& str2);
|
||||
bool starts_with(const std::string& subject, const std::string& string);
|
||||
bool istarts_with(const std::string& subject, const std::string& string);
|
||||
|
||||
bool ends_with(const std::string& subject, const std::string& string);
|
||||
bool iends_with(const std::string& subject, const std::string& string);
|
||||
|
||||
std::vector<std::string> split(const std::string& subject, const char& delimiter);
|
||||
std::vector<std::string> split(const std::string& subject, const std::string delimiters);
|
||||
|
||||
@@ -28,6 +31,6 @@ bool icontains(const std::string& subject, const std::string& find);
|
||||
|
||||
std::string::const_iterator find_nth(const std::string& haystack, const std::string& needle, size_t nth);
|
||||
|
||||
} // namespace Utilities
|
||||
} // namespace StringAlgorithm
|
||||
|
||||
#endif // STRINGALGORITHM_H
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Utilities {
|
||||
namespace Tribool {
|
||||
|
||||
class Tribool
|
||||
{
|
||||
@@ -198,6 +198,6 @@ std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>&
|
||||
return in;
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
} // namespace Tribool
|
||||
|
||||
#endif // TRIBOOL_H
|
||||
|
||||
Reference in New Issue
Block a user