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