From 7726d64530f82fc9b8ac08f484491335bd7ca2a4 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sat, 12 Feb 2022 16:04:48 +0100 Subject: Optimized directory structure --- Src/StringTools/CMakeLists.txt | 6 --- Src/StringTools/StringTools.cpp | 100 ---------------------------------------- Src/StringTools/StringTools.h | 29 ------------ 3 files changed, 135 deletions(-) delete mode 100644 Src/StringTools/CMakeLists.txt delete mode 100644 Src/StringTools/StringTools.cpp delete mode 100644 Src/StringTools/StringTools.h (limited to 'Src/StringTools') diff --git a/Src/StringTools/CMakeLists.txt b/Src/StringTools/CMakeLists.txt deleted file mode 100644 index 4aacd6e..0000000 --- a/Src/StringTools/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(StringTools) - -set(CMAKE_CXX_STANDARD 17) - -add_library(StringTools StringTools.cpp) diff --git a/Src/StringTools/StringTools.cpp b/Src/StringTools/StringTools.cpp deleted file mode 100644 index bb5faf3..0000000 --- a/Src/StringTools/StringTools.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "StringTools.h" -#include - -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(); -} diff --git a/Src/StringTools/StringTools.h b/Src/StringTools/StringTools.h deleted file mode 100644 index 589c047..0000000 --- a/Src/StringTools/StringTools.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include - -/* 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. Only works with latin and german umlautes, plus some extras. - static std::string Lower(const std::string& str); - - //! Will make a string all-uppercase. Only works with latin and german umlautes, plus some extras. - static std::string Upper(const std::string& str); - -private: - // No instanciation! >:( - StringTools(); -}; -- cgit v1.2.3