Put stringtools into 'internal' namespace

This commit is contained in:
Leonetienne 2021-08-04 21:17:34 +02:00
parent ac38fe081c
commit 2a61fa980a
5 changed files with 93 additions and 85 deletions

View File

@ -243,7 +243,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& 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<std::string>& 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;

View File

@ -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<std::string> StringTools::SplitString(const std::string& str, const char delimiter)
std::vector<std::string> Internal::StringTools::SplitString(const std::string& str, const char delimiter)
{
if (str.length() == 0) return std::vector<std::string>();
return SplitString(str, delimiter);
}
std::vector<std::string> StringTools::SplitString(const std::string& str, const std::string& delimiter)
std::vector<std::string> Internal::StringTools::SplitString(const std::string& str, const std::string& delimiter)
{
if (str.length() == 0) return std::vector<std::string>();
@ -170,7 +170,7 @@ std::vector<std::string> 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++)

View File

@ -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<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter char. The delimiter will be excluded!
static std::vector<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter string. The delimiter will be excluded!
static std::vector<std::string> 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<std::string> 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);
};
}
}

View File

@ -238,7 +238,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& 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<std::string>& 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<std::string> StringTools::SplitString(const std::string& str, const char delimiter)
std::vector<std::string> Internal::StringTools::SplitString(const std::string& str, const char delimiter)
{
if (str.length() == 0) return std::vector<std::string>();
return SplitString(str, delimiter);
}
std::vector<std::string> StringTools::SplitString(const std::string& str, const std::string& delimiter)
std::vector<std::string> Internal::StringTools::SplitString(const std::string& str, const std::string& delimiter)
{
if (str.length() == 0) return std::vector<std::string>();
@ -1078,7 +1078,7 @@ std::vector<std::string> 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++)

View File

@ -13,6 +13,52 @@ namespace Hazelnp
}
}
/*** ../Hazelnupp/StringTools.h ***/
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
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<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter string. The delimiter will be excluded!
static std::vector<std::string> 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 <string>
@ -530,48 +576,6 @@ namespace Hazelnp
};
}
/*** ../Hazelnupp/StringTools.h ***/
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
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<std::string> SplitString(const std::string& str, const char delimiter);
//! Will split a string by a delimiter string. The delimiter will be excluded!
static std::vector<std::string> 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 <unordered_map>