diff --git a/.gitignore b/.gitignore index 5c150de..851ef09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ .*.swp .AppleDouble lib -Libraries -fixPermissions.sh diff --git a/Utilities/Random.cpp b/Utilities/Random.cpp new file mode 100644 index 0000000..a0dfd0b --- /dev/null +++ b/Utilities/Random.cpp @@ -0,0 +1,23 @@ +#include "Random.h" +#include + + +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 diff --git a/Utilities/StringAlgorithm.cpp b/Utilities/StringAlgorithm.cpp index fc65a55..33c40b4 100644 --- a/Utilities/StringAlgorithm.cpp +++ b/Utilities/StringAlgorithm.cpp @@ -5,7 +5,7 @@ #include -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 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 diff --git a/Utilities/Tribool.cpp b/Utilities/Tribool.cpp index 4634229..6b3c564 100644 --- a/Utilities/Tribool.cpp +++ b/Utilities/Tribool.cpp @@ -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 diff --git a/include/Random.h b/include/Random.h new file mode 100644 index 0000000..c26ec22 --- /dev/null +++ b/include/Random.h @@ -0,0 +1,13 @@ +#ifndef RANDOM_H +#define RANDOM_H + +#include + + +namespace Random { + +std::string CreateRandomString(size_t length); + +} // namespace Random + +#endif // RANDOM_H diff --git a/include/StringAlgorithm.h b/include/StringAlgorithm.h index 2b70ba3..7e5825c 100644 --- a/include/StringAlgorithm.h +++ b/include/StringAlgorithm.h @@ -5,7 +5,7 @@ #include -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 split(const std::string& subject, const char& delimiter); std::vector 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 diff --git a/include/Tribool.h b/include/Tribool.h index 1a82bfc..c320a13 100644 --- a/include/Tribool.h +++ b/include/Tribool.h @@ -4,7 +4,7 @@ #include -namespace Utilities { +namespace Tribool { class Tribool { @@ -198,6 +198,6 @@ std::basic_istream& operator>>(std::basic_istream& return in; } -} // namespace Utilities +} // namespace Tribool #endif // TRIBOOL_H