| Leonetienne/Hazelnupp Simple, easy to use, command line parameter interface

StringTools.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <sstream>
4 #include <vector>
5 #include <cmath>
6
7 namespace Hazelnp
8 {
9 namespace Internal
10 {
11 /** Internal helper class. Feel free to use it tho.
12 */
13 class StringTools
14 {
15 public:
16 //! Will return wether or not a given char is in a string
17 static bool Contains(const std::string& str, const char c);
18
19 //! Will replace a part of a string with another string
20 static std::string Replace(const std::string& str, const char find, const std::string& subst);
21
22 //! Will replace a part of a string with another string
23 static std::string Replace(const std::string& str, const std::string& find, const std::string& subst);
24
25 //! Will return true if the given string consists only of digits (including signage)
26 static bool IsNumeric(const std::string& str, const bool allowDecimalPoint = false);
27
28 //! Will convert the number in str to a number.
29 //! Returns wether or not the operation was successful.
30 //! Also returns wether the number is an integer, or floating point. If int, cast out_number to int.
31 static bool ParseNumber(const std::string& str, bool& out_isInt, long double& out_number);
32
33 //! Will split a string by a delimiter char. The delimiter will be excluded!
34 static std::vector<std::string> SplitString(const std::string& str, const char delimiter);
35
36 //! Will split a string by a delimiter string. The delimiter will be excluded!
37 static std::vector<std::string> SplitString(const std::string& str, const std::string& delimiter);
38
39 //! Will make a string all lower-case
40 static std::string ToLower(const std::string& str);
41 };
42 }
43 }
44
Hazelnp
Definition: CmdArgsInterface.h:9
Hazelnp::Internal::StringTools::Contains
static bool Contains(const std::string &str, const char c)
Will return wether or not a given char is in a string.
Definition: StringTools.cpp:5
Hazelnp::Internal::StringTools::ToLower
static std::string ToLower(const std::string &str)
Will make a string all lower-case.
Definition: StringTools.cpp:173
Hazelnp::Internal::StringTools
Internal helper class.
Definition: StringTools.h:13
Hazelnp::Internal::StringTools::Replace
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.
Definition: StringTools.cpp:14
Hazelnp::Internal::StringTools::ParseNumber
static bool ParseNumber(const std::string &str, bool &out_isInt, long double &out_number)
Will convert the number in str to a number.
Definition: StringTools.cpp:82
Hazelnp::Internal::StringTools::SplitString
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!
Definition: StringTools.cpp:125
Hazelnp::Internal::StringTools::IsNumeric
static bool IsNumeric(const std::string &str, const bool allowDecimalPoint=false)
Will return true if the given string consists only of digits (including signage)
Definition: StringTools.cpp:56