OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
11
12// std header
13#include <list>
14#include <string>
15#include <sstream>
16#include <iomanip>
17
18namespace ot {
19
23 public:
24
26 static std::string toLower(const std::string& _string);
27
29 static std::string evaluateEscapeCharacters(const std::string& _string);
30
35 static std::list<std::string> split(const std::string& _str, char _splitBy, bool _skipEmpty = false);
36
41 static std::list<std::string> split(const std::string& _str, const std::string& _splitBy, bool _skipEmpty = false);
42
47 static std::list<std::wstring> split(const std::wstring& _str, wchar_t _splitBy, bool _skipEmpty = false);
48
53 static std::list<std::wstring> split(const std::wstring& _str, const std::wstring& _splitBy, bool _skipEmpty = false);
54
55 static std::list<std::string> smartSplit(const std::string& _str, const std::string& _splitBy, bool _evaluateEscapeCharacters = true, bool _skipEmpty = false);
56
58 static std::string replace(const std::string& _str, const std::string& _what, const std::string& _with);
59
61 static std::wstring replace(const std::wstring& _str, const std::wstring& _what, const std::wstring& _with);
62
64 static char* getCStringCopy(const std::string& _str);
65
67 static wchar_t* getCStringCopy(const std::wstring& _str);
68
72 template <class T> static inline T toNumber(const std::string& _string, bool& _failed);
73
78 template <class T> static inline std::string numberToHexString(T _number, char _fill = '0', int _length = 16);
79 };
80}
81
82template <class T> T ot::String::toNumber(const std::string& _string, bool& _failed) {
83 std::stringstream ss(_string);
84 T v;
85 ss >> v;
86 _failed = false;
87 if (ss.fail()) { _failed = true; }
88 std::string rest;
89 ss >> rest;
90 if (!rest.empty()) { _failed = true; }
91 return v;
92}
93
94template <class T> inline std::string ot::String::numberToHexString(T _number, char _fill, int _length) {
95 std::stringstream ss;
96 ss << std::hex << std::setw(_length) << std::setfill(_fill) << _number;
97 return std::move(ss.str());
98}
#define OT_CORE_API_EXPORT
Dll import.
Definition CoreAPIExport.h:8
This file contains defines that may be used simplyfy class creation.
#define OT_DECL_NODEFAULT(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:22
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
Definition String.h:20
static T toNumber(const std::string &_string, bool &_failed)
Convert the provided string to a number.
Definition String.h:82
static std::string numberToHexString(T _number, char _fill='0', int _length=16)
Returns a hex string representing the provided number.
Definition String.h:94
Definition Connector.h:8