From 2a61fa980ab145b75886c566deb8e59cf905f0aa Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Wed, 4 Aug 2021 21:17:34 +0200 Subject: [PATCH] Put stringtools into 'internal' namespace --- Hazelnupp/CmdArgsInterface.cpp | 4 +- Hazelnupp/StringTools.cpp | 16 +++---- Hazelnupp/StringTools.h | 50 ++++++++++--------- INCLUDE/Hazelnupp.cpp | 20 ++++---- INCLUDE/Hazelnupp.h | 88 ++++++++++++++++++---------------- 5 files changed, 93 insertions(+), 85 deletions(-) diff --git a/Hazelnupp/CmdArgsInterface.cpp b/Hazelnupp/CmdArgsInterface.cpp index 531ca2b..39d998a 100644 --- a/Hazelnupp/CmdArgsInterface.cpp +++ b/Hazelnupp/CmdArgsInterface.cpp @@ -243,7 +243,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector& values, cons const std::string& val = values[0]; // String - if (!StringTools::IsNumeric(val, true)) + if (!Internal::StringTools::IsNumeric(val, true)) { rawInputType = DATA_TYPE::STRING; @@ -285,7 +285,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector& values, cons bool isInt; long double num; - if (StringTools::ParseNumber(val, isInt, num)) + if (Internal::StringTools::ParseNumber(val, isInt, num)) { rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT; diff --git a/Hazelnupp/StringTools.cpp b/Hazelnupp/StringTools.cpp index 300c507..9157b43 100644 --- a/Hazelnupp/StringTools.cpp +++ b/Hazelnupp/StringTools.cpp @@ -2,7 +2,7 @@ using namespace Hazelnp; -bool StringTools::Contains(const std::string& str, const char c) +bool Internal::StringTools::Contains(const std::string& str, const char c) { for (const char& i : str) if (i == c) @@ -11,7 +11,7 @@ bool StringTools::Contains(const std::string& str, const char c) return false; } -std::string StringTools::Replace(const std::string& str, const char find, const std::string& subst) +std::string Internal::StringTools::Replace(const std::string& str, const char find, const std::string& subst) { std::stringstream ss; @@ -24,7 +24,7 @@ std::string StringTools::Replace(const std::string& str, const char find, const return ss.str(); } -std::string StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) +std::string Internal::StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) { if (find.length() == 0) return str; @@ -53,7 +53,7 @@ std::string StringTools::Replace(const std::string& str, const std::string& find } -bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint) +bool Internal::StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint) { if (str.length() == 0) return false; @@ -79,7 +79,7 @@ bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint return digitCount > 0; } -bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long double& out_number) +bool Internal::StringTools::ParseNumber(const std::string& str, bool& out_isInt, long double& out_number) { bool isDecimal = false; @@ -122,14 +122,14 @@ bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long doub return true; } -std::vector StringTools::SplitString(const std::string& str, const char delimiter) +std::vector Internal::StringTools::SplitString(const std::string& str, const char delimiter) { if (str.length() == 0) return std::vector(); return SplitString(str, delimiter); } -std::vector StringTools::SplitString(const std::string& str, const std::string& delimiter) +std::vector Internal::StringTools::SplitString(const std::string& str, const std::string& delimiter) { if (str.length() == 0) return std::vector(); @@ -170,7 +170,7 @@ std::vector StringTools::SplitString(const std::string& str, const return parts; } -std::string StringTools::ToLower(const std::string& str) +std::string Internal::StringTools::ToLower(const std::string& str) { std::stringstream ss; for (std::size_t i = 0; i < str.length(); i++) diff --git a/Hazelnupp/StringTools.h b/Hazelnupp/StringTools.h index 25533d7..374eba0 100644 --- a/Hazelnupp/StringTools.h +++ b/Hazelnupp/StringTools.h @@ -6,35 +6,39 @@ namespace Hazelnp { - /** Internal helper class. Feel free to use it tho. - */ - class StringTools + namespace Internal { - public: - //! Will return wether or not a given char is in a string - static bool Contains(const std::string& str, const char c); + /** Internal helper class. Feel free to use it tho. + */ + class StringTools + { + public: + //! Will return wether or not a given char is in a string + static bool Contains(const std::string& str, const char c); - //! Will replace a part of a string with another string - static std::string Replace(const std::string& str, const char find, const std::string& subst); + //! Will replace a part of a string with another string + static std::string Replace(const std::string& str, const char find, const std::string& subst); - //! Will replace a part of a string with another string - static std::string Replace(const std::string& str, const std::string& find, const std::string& subst); + //! Will replace a part of a string with another string + static std::string Replace(const std::string& str, const std::string& find, const std::string& subst); - //! Will return true if the given string consists only of digits (including signage) - static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false); + //! Will return true if the given string consists only of digits (including signage) + static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false); - //! Will convert the number in str to a number. - //! Returns wether or not the operation was successful. - //! Also returns wether the number is an integer, or floating point. If int, cast out_number to int. - static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number); + //! Will convert the number in str to a number. + //! Returns wether or not the operation was successful. + //! Also returns wether the number is an integer, or floating point. If int, cast out_number to int. + static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number); - //! Will split a string by a delimiter char. The delimiter will be excluded! - static std::vector SplitString(const std::string& str, const char delimiter); + //! Will split a string by a delimiter char. The delimiter will be excluded! + static std::vector SplitString(const std::string& str, const char delimiter); - //! Will split a string by a delimiter string. The delimiter will be excluded! - static std::vector SplitString(const std::string& str, const std::string& delimiter); + //! Will split a string by a delimiter string. The delimiter will be excluded! + static std::vector SplitString(const std::string& str, const std::string& delimiter); - //! Will make a string all lower-case - static std::string ToLower(const std::string& str); - }; + //! Will make a string all lower-case + static std::string ToLower(const std::string& str); + }; + } } + diff --git a/INCLUDE/Hazelnupp.cpp b/INCLUDE/Hazelnupp.cpp index e3f50e2..ae97068 100644 --- a/INCLUDE/Hazelnupp.cpp +++ b/INCLUDE/Hazelnupp.cpp @@ -238,7 +238,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector& values, cons const std::string& val = values[0]; // String - if (!StringTools::IsNumeric(val, true)) + if (!Internal::StringTools::IsNumeric(val, true)) { rawInputType = DATA_TYPE::STRING; @@ -280,7 +280,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector& values, cons bool isInt; long double num; - if (StringTools::ParseNumber(val, isInt, num)) + if (Internal::StringTools::ParseNumber(val, isInt, num)) { rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT; @@ -910,7 +910,7 @@ const ::Value* Parameter::GetValue() const using namespace Hazelnp; -bool StringTools::Contains(const std::string& str, const char c) +bool Internal::StringTools::Contains(const std::string& str, const char c) { for (const char& i : str) if (i == c) @@ -919,7 +919,7 @@ bool StringTools::Contains(const std::string& str, const char c) return false; } -std::string StringTools::Replace(const std::string& str, const char find, const std::string& subst) +std::string Internal::StringTools::Replace(const std::string& str, const char find, const std::string& subst) { std::stringstream ss; @@ -932,7 +932,7 @@ std::string StringTools::Replace(const std::string& str, const char find, const return ss.str(); } -std::string StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) +std::string Internal::StringTools::Replace(const std::string& str, const std::string& find, const std::string& subst) { if (find.length() == 0) return str; @@ -961,7 +961,7 @@ std::string StringTools::Replace(const std::string& str, const std::string& find } -bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint) +bool Internal::StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint) { if (str.length() == 0) return false; @@ -987,7 +987,7 @@ bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint return digitCount > 0; } -bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long double& out_number) +bool Internal::StringTools::ParseNumber(const std::string& str, bool& out_isInt, long double& out_number) { bool isDecimal = false; @@ -1030,14 +1030,14 @@ bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long doub return true; } -std::vector StringTools::SplitString(const std::string& str, const char delimiter) +std::vector Internal::StringTools::SplitString(const std::string& str, const char delimiter) { if (str.length() == 0) return std::vector(); return SplitString(str, delimiter); } -std::vector StringTools::SplitString(const std::string& str, const std::string& delimiter) +std::vector Internal::StringTools::SplitString(const std::string& str, const std::string& delimiter) { if (str.length() == 0) return std::vector(); @@ -1078,7 +1078,7 @@ std::vector StringTools::SplitString(const std::string& str, const return parts; } -std::string StringTools::ToLower(const std::string& str) +std::string Internal::StringTools::ToLower(const std::string& str) { std::stringstream ss; for (std::size_t i = 0; i < str.length(); i++) diff --git a/INCLUDE/Hazelnupp.h b/INCLUDE/Hazelnupp.h index 1f2e039..80c488a 100644 --- a/INCLUDE/Hazelnupp.h +++ b/INCLUDE/Hazelnupp.h @@ -13,6 +13,52 @@ namespace Hazelnp } } +/*** ../Hazelnupp/StringTools.h ***/ + +#include +#include +#include +#include + +namespace Hazelnp +{ + namespace Internal + { + /** Internal helper class. Feel free to use it tho. + */ + class StringTools + { + public: + //! Will return wether or not a given char is in a string + static bool Contains(const std::string& str, const char c); + + //! Will replace a part of a string with another string + static std::string Replace(const std::string& str, const char find, const std::string& subst); + + //! Will replace a part of a string with another string + static std::string Replace(const std::string& str, const std::string& find, const std::string& subst); + + //! Will return true if the given string consists only of digits (including signage) + static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false); + + //! Will convert the number in str to a number. + //! Returns wether or not the operation was successful. + //! Also returns wether the number is an integer, or floating point. If int, cast out_number to int. + static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number); + + //! Will split a string by a delimiter char. The delimiter will be excluded! + static std::vector SplitString(const std::string& str, const char delimiter); + + //! Will split a string by a delimiter string. The delimiter will be excluded! + static std::vector SplitString(const std::string& str, const std::string& delimiter); + + //! Will make a string all lower-case + static std::string ToLower(const std::string& str); + }; + } +} + + /*** ../Hazelnupp/DataType.h ***/ #include @@ -530,48 +576,6 @@ namespace Hazelnp }; } -/*** ../Hazelnupp/StringTools.h ***/ - -#include -#include -#include -#include - -namespace Hazelnp -{ - /** Internal helper class. Feel free to use it tho. - */ - class StringTools - { - public: - //! Will return wether or not a given char is in a string - static bool Contains(const std::string& str, const char c); - - //! Will replace a part of a string with another string - static std::string Replace(const std::string& str, const char find, const std::string& subst); - - //! Will replace a part of a string with another string - static std::string Replace(const std::string& str, const std::string& find, const std::string& subst); - - //! Will return true if the given string consists only of digits (including signage) - static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false); - - //! Will convert the number in str to a number. - //! Returns wether or not the operation was successful. - //! Also returns wether the number is an integer, or floating point. If int, cast out_number to int. - static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number); - - //! Will split a string by a delimiter char. The delimiter will be excluded! - static std::vector SplitString(const std::string& str, const char delimiter); - - //! Will split a string by a delimiter string. The delimiter will be excluded! - static std::vector SplitString(const std::string& str, const std::string& delimiter); - - //! Will make a string all lower-case - static std::string ToLower(const std::string& str); - }; -} - /*** ../Hazelnupp/CmdArgsInterface.h ***/ #include