Put stringtools into 'internal' namespace
This commit is contained in:
parent
ac38fe081c
commit
2a61fa980a
@ -243,7 +243,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, cons
|
|||||||
const std::string& val = values[0];
|
const std::string& val = values[0];
|
||||||
|
|
||||||
// String
|
// String
|
||||||
if (!StringTools::IsNumeric(val, true))
|
if (!Internal::StringTools::IsNumeric(val, true))
|
||||||
{
|
{
|
||||||
rawInputType = DATA_TYPE::STRING;
|
rawInputType = DATA_TYPE::STRING;
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, cons
|
|||||||
bool isInt;
|
bool isInt;
|
||||||
long double num;
|
long double num;
|
||||||
|
|
||||||
if (StringTools::ParseNumber(val, isInt, num))
|
if (Internal::StringTools::ParseNumber(val, isInt, num))
|
||||||
{
|
{
|
||||||
rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT;
|
rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
using namespace Hazelnp;
|
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)
|
for (const char& i : str)
|
||||||
if (i == c)
|
if (i == c)
|
||||||
@ -11,7 +11,7 @@ bool StringTools::Contains(const std::string& str, const char c)
|
|||||||
return false;
|
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;
|
std::stringstream ss;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ std::string StringTools::Replace(const std::string& str, const char find, const
|
|||||||
return ss.str();
|
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;
|
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;
|
if (str.length() == 0) return false;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint
|
|||||||
return digitCount > 0;
|
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;
|
bool isDecimal = false;
|
||||||
|
|
||||||
@ -122,14 +122,14 @@ bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long doub
|
|||||||
return true;
|
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>();
|
if (str.length() == 0) return std::vector<std::string>();
|
||||||
|
|
||||||
return SplitString(str, delimiter);
|
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>();
|
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;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringTools::ToLower(const std::string& str)
|
std::string Internal::StringTools::ToLower(const std::string& str)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (std::size_t i = 0; i < str.length(); i++)
|
for (std::size_t i = 0; i < str.length(); i++)
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace Hazelnp
|
namespace Hazelnp
|
||||||
|
{
|
||||||
|
namespace Internal
|
||||||
{
|
{
|
||||||
/** Internal helper class. Feel free to use it tho.
|
/** Internal helper class. Feel free to use it tho.
|
||||||
*/
|
*/
|
||||||
@ -38,3 +40,5 @@ namespace Hazelnp
|
|||||||
static std::string ToLower(const std::string& str);
|
static std::string ToLower(const std::string& str);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, cons
|
|||||||
const std::string& val = values[0];
|
const std::string& val = values[0];
|
||||||
|
|
||||||
// String
|
// String
|
||||||
if (!StringTools::IsNumeric(val, true))
|
if (!Internal::StringTools::IsNumeric(val, true))
|
||||||
{
|
{
|
||||||
rawInputType = DATA_TYPE::STRING;
|
rawInputType = DATA_TYPE::STRING;
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ Value* CmdArgsInterface::ParseValue(const std::vector<std::string>& values, cons
|
|||||||
bool isInt;
|
bool isInt;
|
||||||
long double num;
|
long double num;
|
||||||
|
|
||||||
if (StringTools::ParseNumber(val, isInt, num))
|
if (Internal::StringTools::ParseNumber(val, isInt, num))
|
||||||
{
|
{
|
||||||
rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT;
|
rawInputType = isInt ? DATA_TYPE::INT : DATA_TYPE::FLOAT;
|
||||||
|
|
||||||
@ -910,7 +910,7 @@ const ::Value* Parameter::GetValue() const
|
|||||||
|
|
||||||
using namespace Hazelnp;
|
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)
|
for (const char& i : str)
|
||||||
if (i == c)
|
if (i == c)
|
||||||
@ -919,7 +919,7 @@ bool StringTools::Contains(const std::string& str, const char c)
|
|||||||
return false;
|
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;
|
std::stringstream ss;
|
||||||
|
|
||||||
@ -932,7 +932,7 @@ std::string StringTools::Replace(const std::string& str, const char find, const
|
|||||||
return ss.str();
|
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;
|
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;
|
if (str.length() == 0) return false;
|
||||||
|
|
||||||
@ -987,7 +987,7 @@ bool StringTools::IsNumeric(const std::string& str, const bool allowDecimalPoint
|
|||||||
return digitCount > 0;
|
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;
|
bool isDecimal = false;
|
||||||
|
|
||||||
@ -1030,14 +1030,14 @@ bool StringTools::ParseNumber(const std::string& str, bool& out_isInt, long doub
|
|||||||
return true;
|
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>();
|
if (str.length() == 0) return std::vector<std::string>();
|
||||||
|
|
||||||
return SplitString(str, delimiter);
|
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>();
|
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;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringTools::ToLower(const std::string& str)
|
std::string Internal::StringTools::ToLower(const std::string& str)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (std::size_t i = 0; i < str.length(); i++)
|
for (std::size_t i = 0; i < str.length(); i++)
|
||||||
|
@ -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 ***/
|
/*** ../Hazelnupp/DataType.h ***/
|
||||||
|
|
||||||
#include <string>
|
#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 ***/
|
/*** ../Hazelnupp/CmdArgsInterface.h ***/
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user