소스 검색

Fix Namespaces, add ends_with functions

JDierkse 5 년 전
부모
커밋
ce71fc10b9
7개의 변경된 파일65개의 추가작업 그리고 10개의 파일을 삭제
  1. 0 2
      .gitignore
  2. 23 0
      Utilities/Random.cpp
  3. 20 2
      Utilities/StringAlgorithm.cpp
  4. 2 2
      Utilities/Tribool.cpp
  5. 13 0
      include/Random.h
  6. 5 2
      include/StringAlgorithm.h
  7. 2 2
      include/Tribool.h

+ 0 - 2
.gitignore

@@ -4,5 +4,3 @@
 .*.swp
 .AppleDouble
 lib
-Libraries
-fixPermissions.sh

+ 23 - 0
Utilities/Random.cpp

@@ -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

+ 20 - 2
Utilities/StringAlgorithm.cpp

@@ -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

+ 2 - 2
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

+ 13 - 0
include/Random.h

@@ -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 - 2
include/StringAlgorithm.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
include/Tribool.h

@@ -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