OpenTwin
0.1
OpenTwin
Loading...
Searching...
No Matches
String.hpp
Go to the documentation of this file.
1
4
// ###########################################################################################################################################################################################################################################################################################################################
5
6
#pragma once
7
8
// OpenTwin header
9
#include "
OTCore/String.h
"
10
11
// std header
12
#include <sstream>
13
#include <iomanip>
14
15
template
<
class
T> T
ot::String::toNumber
(
const
std::string& _string,
bool
& _failed) {
16
T
result
=
static_cast<
T
>
(0);
17
std::stringstream ss(_string);
18
_failed =
false
;
19
20
// Create value and write from string stream
21
ss >>
result
;
22
23
if
(ss.fail()) {
24
// Convert failed
25
_failed =
true
;
26
}
27
else
{
28
// Ensure all data was converted
29
std::string rest;
30
ss >> rest;
31
if
(!rest.empty()) {
32
_failed =
true
;
33
}
34
}
35
36
return
result
;
37
}
38
39
template
<
class
T>
inline
bool
ot::String::isNumber
(
const
std::string& _string) {
40
bool
failed =
false
;
41
String::toNumber<T>(_string, failed);
42
return
!failed;
43
}
44
45
template
<
class
T>
inline
std::string
ot::String::numberToHexString
(T _number,
char
_fill,
int
_length) {
46
std::stringstream ss;
47
ss << std::hex << std::setw(_length) << std::setfill(_fill) << _number;
48
return
std::move(ss.str());
49
}
result
int result
Definition
dllmain.cpp:82
String.h
ot::String::isNumber
static bool isNumber(const std::string &_string)
Returns true if the provided string is a number.
Definition
String.hpp:39
ot::String::toNumber
static T toNumber(const std::string &_string, bool &_failed)
Convert the provided string to a number.
Definition
String.hpp:15
ot::String::numberToHexString
static std::string numberToHexString(T _number, char _fill='0', int _length=16)
Returns a hex string representing the provided number.
Definition
String.hpp:45
Libraries
OTCore
include
OTCore
String.hpp
Generated by
1.10.0