-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.h
53 lines (39 loc) · 1.14 KB
/
convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef __CONVERT_H__
#define __CONVERT_H__
#include <iostream>
#include <sstream>
#include <string>
#include "exceptions.h"
#include "unicode.h"
/// Convert value to string
/// \param x value
template <typename T>
inline std::wstring toString(const T &x)
{
#ifndef WIN32
std::wostringstream o;
if (! (o << x))
throw Exception(L"Can't convert " + fromMbcs(typeid(x).name())
+ L" to string");
return o.str();
#else // Mingw doesn't support std::wostringstream yet :-(
std::ostringstream o;
if (! (o << x))
throw Exception(L"Can't convert " + fromMbcs(typeid(x).name())
+ L" to string");
return fromMbcs(o.str());
#endif
}
/// Convert string to lower case.
std::wstring toLowerCase(const std::wstring &s);
/// Convert string to upper case
std::wstring toUpperCase(const std::wstring &s);
/// Convert integer to string.
std::wstring numToStr(int num);
/// Convert unsigned integer to string.
std::wstring numToStr(unsigned int num);
/// Convert string to integer
int strToInt(const std::wstring &str);
/// Conver string to double
double strToDouble(const std::wstring &str);
#endif