summaryrefslogtreecommitdiffstats
path: root/Src
diff options
context:
space:
mode:
authorLeonetienne <leon@etiennes.de>2022-05-16 23:57:26 +0200
committerLeonetienne <leon@etiennes.de>2022-05-16 23:57:26 +0200
commit954629f6bc3b7753c5be0c08e0cdb5caf1056d23 (patch)
tree33a95f60202135f9fcc689e081a64f2d274d7d99 /Src
parent1fe3eeb14470470d8c95c40c98a12c15320bcd57 (diff)
Adhere to new project structure
Diffstat (limited to 'Src')
-rw-r--r--Src/CMakeLists.txt9
-rw-r--r--Src/CharTools.cpp68
-rw-r--r--Src/CharTools.h35
-rw-r--r--Src/StringTools.cpp155
-rw-r--r--Src/StringTools.h43
5 files changed, 0 insertions, 310 deletions
diff --git a/Src/CMakeLists.txt b/Src/CMakeLists.txt
deleted file mode 100644
index e693251..0000000
--- a/Src/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-cmake_minimum_required(VERSION 3.16)
-project(StringTools)
-
-set(CMAKE_CXX_STANDARD 17)
-
-add_library(StringTools
- StringTools.cpp
- CharTools.cpp
-)
diff --git a/Src/CharTools.cpp b/Src/CharTools.cpp
deleted file mode 100644
index 5a7028c..0000000
--- a/Src/CharTools.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-#include "CharTools.h"
-#include <algorithm>
-
-bool CharTools::IsVowel(const char c, const std::string &vowels) {
- const char lc = MakeLower(c);
-
- return std::any_of(
- vowels.cbegin(),
- vowels.cend(),
- [lc](const char vowel) {
- return lc == vowel;
- }
- );
-}
-
-bool CharTools::IsLetter(const char c) {
- // Re-implementing IsUpper and MakeLower to prevent stack-overflow by endless recursion
- const char lowercase_c = !(c & (1<<5)) ? (c | (1<<5)) : c;
-
- return (lowercase_c >= 'a') && (lowercase_c <= 'z');
-}
-
-bool CharTools::IsDigit(const char c) {
- return (c >= '0') && (c <= '9');
-}
-
-bool CharTools::IsUpper(const char c) {
- if (!IsLetter(c))
- return false;
- else
- return !(c & (1<<5));
-}
-
-bool CharTools::IsLower(const char c) {
- // Can't just return !IsUpper(c), because it should still return false for digits and symbols...
-
- if (!IsLetter(c))
- return false;
- else
- return (c & (1<<5));
-}
-
-char CharTools::MakeUpper(char c) {
- if (!IsLetter(c))
- return c;
- else if (IsUpper(c))
- return c;
- else
- return c & ~(1<<5);
-}
-
-char CharTools::MakeLower(char c) {
- if (!IsLetter(c))
- return c;
- else if (!IsUpper(c))
- return c;
- else
- return c | (1<<5);
-}
-
-char CharTools::CopySign(char sign, char c) {
- if ((!IsLetter(c)) || (!IsLetter(sign)))
- return c;
- if (IsUpper(sign))
- return MakeUpper(c);
- else
- return MakeLower(c);
-}
diff --git a/Src/CharTools.h b/Src/CharTools.h
deleted file mode 100644
index 66c32c0..0000000
--- a/Src/CharTools.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef STRINGTOOLS_CHARTOOLS_H
-#define STRINGTOOLS_CHARTOOLS_H
-
-#include <string>
-
-/* Handy utensils to manipulate characters */
-
-class CharTools {
-public:
- //! Checks whether or not `c` is a vowel. You can define custom vowel characters.
- static bool IsVowel(const char c, const std::string &vowels = "euioay");
-
- //! Returns whether or not `c` is a letter.
- static bool IsLetter(const char c);
-
- //! Returns whether or not `c` is a digit.
- static bool IsDigit(const char c);
-
- //! Checks whether or not `c` is an uppercase character.
- static bool IsUpper(const char c);
-
- //! Checks whether or not `c` is a lowercase character.
- static bool IsLower(const char c);
-
- //! Will return `c` as an uppercase character.
- static char MakeUpper(char c);
-
- //! Will return `c` as a lowercase character.
- static char MakeLower(char c);
-
- //! Will return `c` with the same capitalization as `sign`.
- static char CopySign(char sign, char c);
-};
-
-#endif //STRINGTOOLS_CHARTOOLS_H
diff --git a/Src/StringTools.cpp b/Src/StringTools.cpp
deleted file mode 100644
index fe16c93..0000000
--- a/Src/StringTools.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-#include "StringTools.h"
-#include <sstream>
-
-std::string StringTools::Replace(const std::string& str, const char find, const std::string& subst) {
- std::stringstream ss;
-
- for (std::size_t i = 0; i < str.length(); i++)
- {
- if (str[i] != find)
- ss << str[i];
- else
- ss << subst;
- }
-
- return ss.str();
-}
-
-std::string StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) {
- if (find.length() == 0)
- return str;
-
- std::stringstream ss;
-
- std::size_t posFound = 0;
- std::size_t lastFound = 0;
-
- while (posFound != std::string::npos)
- {
- lastFound = posFound;
- posFound = str.find(find, posFound);
-
- if (posFound != std::string::npos)
- {
- ss << str.substr(lastFound, posFound - lastFound) << subst;
- posFound += find.length();
- }
- else
- {
- ss << str.substr(lastFound, (str.length()) - lastFound);
- }
- }
-
- return ss.str();
-}
-
-std::string StringTools::Replace(const std::string& str, const char find, const char subst) {
- std::stringstream ss;
- ss << subst;
-
- return Replace(str, find, ss.str());
-}
-
-std::string StringTools::Replace(const std::string& str, const std::string& find, const char subst) {
- std::stringstream ss;
- ss << subst;
-
- return Replace(str, find, ss.str());
-}
-
-std::string StringTools::Lower(const std::string& str) {
- std::stringstream ss;
-
- for (std::size_t i = 0; i < str.size(); i++)
- {
- const char c = str[i];
-
- // Quick-accept: regular letters
- if ((c >= 'A') && (c <= 'Z'))
- ss << (char)(c | 32);
-
- // Else: keep the character as is
- else ss << c;
- }
-
- return ss.str();
-}
-
-std::string StringTools::Upper(const std::string& str) {
- std::stringstream ss;
-
- for (std::size_t i = 0; i < str.size(); i++)
- {
- const char c = str[i];
-
- // Quick-accept: regular letters
- if ((c >= 'a') && (c <= 'z'))
- ss << (char)(c & ~32);
-
- // Else: keep the character as is
- else ss << c;
- }
-
- return ss.str();
-}
-
-std::vector<std::string> StringTools::Split(const std::string& str, const std::string& seperator) {
- std::vector<std::string> toRet;
- // Quick-accept: str length is 0
- if (str.length() == 0)
- toRet.push_back("");
-
- // Quick-accept: seperator length is 0
- else if (seperator.length() == 0) {
- for (const char c : str)
- toRet.push_back(std::string(&c, (&c) + 1));
- }
-
- else {
- std::size_t idx = 0;
- while (idx != std::string::npos) {
- std::size_t lastIdx = idx;
- idx = str.find(seperator, idx);
-
- // Grab our substring until the next finding of sep
- if (idx != std::string::npos) {
- toRet.push_back(str.substr(
- lastIdx,
- idx - lastIdx
- ));
-
- idx += seperator.length();
- }
- // No more seperator found. Grab the rest until the end of the string
- else {
- toRet.push_back(str.substr(
- lastIdx
- ));
- }
- }
- }
-
- return toRet;
-}
-
-std::string StringTools::PadLeft(const std::string& str, const char pad, const std::size_t len) {
- std::stringstream ss;
-
- for (std::size_t i = str.length(); i < len; i++)
- ss << pad;
-
- ss << str;
-
- return ss.str();
-}
-
-std::string StringTools::PadRight(const std::string& str, const char pad, const std::size_t len) {
- std::stringstream ss;
-
- ss << str;
-
- for (std::size_t i = str.length(); i < len; i++)
- ss << pad;
-
- return ss.str();
-}
diff --git a/Src/StringTools.h b/Src/StringTools.h
deleted file mode 100644
index e8de59d..0000000
--- a/Src/StringTools.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef STRINGTOOLS_STRINGTOOLS_H
-#define STRINGTOOLS_STRINGTOOLS_H
-
-#include <string>
-#include <vector>
-
-/* Handy utensils to manipulate strings */
-class StringTools
-{
-public:
- //! Will replace every occurence of `find` in `str` by `subst`.
- static std::string Replace(const std::string& str, const char find, const std::string& subst);
-
- //! Will replace every occurence of `find` in `str` by `subst`.
- static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
-
- //! Will replace every occurence of `find` in `str` by `subst`.
- static std::string Replace(const std::string& str, const char find, const char subst);
-
- //! Will replace every occurence of `find` in `str` by `subst`.
- static std::string Replace(const std::string& str, const std::string& find, const char subst);
-
- //! Will make a string all-lowercase.
- static std::string Lower(const std::string& str);
-
- //! Will make a string all-uppercase.
- static std::string Upper(const std::string& str);
-
- //! Will split a string by a string seperator
- static std::vector<std::string> Split(const std::string& str, const std::string& seperator);
-
- //! Will pad a string to the left to length l
- static std::string PadLeft(const std::string& str, const char pad, const std::size_t len);
-
- //! Will pad a string to the right to length l
- static std::string PadRight(const std::string& str, const char pad, const std::size_t len);
-
-private:
- // No instanciation! >:(
- StringTools();
-};
-
-#endif //STRINGTOOLS_STRINGTOOLS_H