From 954629f6bc3b7753c5be0c08e0cdb5caf1056d23 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Mon, 16 May 2022 23:57:26 +0200 Subject: Adhere to new project structure --- StringTools/include/StringTools/CharTools.h | 35 ++++++++++++++++++++++ StringTools/include/StringTools/StringTools.h | 43 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 StringTools/include/StringTools/CharTools.h create mode 100644 StringTools/include/StringTools/StringTools.h (limited to 'StringTools/include') diff --git a/StringTools/include/StringTools/CharTools.h b/StringTools/include/StringTools/CharTools.h new file mode 100644 index 0000000..66c32c0 --- /dev/null +++ b/StringTools/include/StringTools/CharTools.h @@ -0,0 +1,35 @@ +#ifndef STRINGTOOLS_CHARTOOLS_H +#define STRINGTOOLS_CHARTOOLS_H + +#include + +/* 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/StringTools/include/StringTools/StringTools.h b/StringTools/include/StringTools/StringTools.h new file mode 100644 index 0000000..818df4c --- /dev/null +++ b/StringTools/include/StringTools/StringTools.h @@ -0,0 +1,43 @@ +#ifndef STRINGTOOLS_STRINGTOOLS_H +#define STRINGTOOLS_STRINGTOOLS_H + +#include +#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. + 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 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 -- cgit v1.2.3