-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeString.h
More file actions
58 lines (43 loc) · 1.81 KB
/
NativeString.h
File metadata and controls
58 lines (43 loc) · 1.81 KB
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
54
55
56
57
58
#ifndef NATIVE_STRING_H_32139idfjksfdjfsd
#define NATIVE_STRING_H_32139idfjksfdjfsd
#include <string>
#include <ostream>
namespace die {
class NativeString {
public:
enum Encoding { utf8=0, utf16=1, utf32=2, }; // add more encodings according to the supported implementations
union {
std::string str;
std::wstring wstr;
};
NativeString();
~NativeString();
NativeString(NativeString const & other);
NativeString & operator=(NativeString const & other);
NativeString(std::string const & strUTF8);
NativeString(std::wstring const & strUTF16);
NativeString(char const * strUTF8);
NativeString(char const * strUTF8, size_t size);
NativeString(wchar_t const * strUTF16);
NativeString(Encoding encoding, std::string const & strEncoded);
std::string toUTF8() const;
std::wstring toUTF16() const;
int toInt() const;
float toFloat() const;
double toDouble() const;
static NativeString toString(int value);
static NativeString toString(float value);
static NativeString toString(double value);
bool empty() const;
NativeString & operator+=(NativeString const & other);
bool operator==(NativeString const & other) const;
bool operator!=(NativeString const & other) const;
static Encoding const nativeEncoding;
};
inline NativeString operator+(NativeString a, NativeString const & b) { return a+=b; }
bool operator<(NativeString const & a, NativeString const & b);
inline std::ostream & operator<<(std::ostream & os, NativeString const & str) { return os << str.toUTF8(); }
inline std::wostream & operator<<(std::wostream & os, NativeString const & str) { return os << str.toUTF16(); }
}
inline die::NativeString operator"" _dies(char const * str, size_t size) { return die::NativeString(str,size); }
#endif