-
Notifications
You must be signed in to change notification settings - Fork 2
/
UTF16String.cpp
38 lines (30 loc) · 1.01 KB
/
UTF16String.cpp
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
#include "UTF16String.h"
#include <cwchar>
#include <cstring>
namespace VoikkoNan
{
UTF16String::UTF16String(const wchar_t *str) : String::ExternalStringResource() {
_length = wcslen(str);
_data = new uint16_t[_length + 1];
if (sizeof(uint16_t) != sizeof(wchar_t)) {
size_t i = 0;
for (; i < _length; i++) {
_data[i] = str[i];
}
_data[i] = '\0';
} else {
memcpy(_data, str, sizeof(wchar_t) * (_length + 1));
}
}
UTF16String::UTF16String(uint16_t *str) : String::ExternalStringResource(), _data(str) {
_length = 0;
for (; str[_length] != 0; _length++);
}
UTF16String::UTF16String(uint16_t *str, const size_t len)
: String::ExternalStringResource(), _data(str), _length(len) {}
UTF16String::~UTF16String() {
delete[] _data;
}
const uint16_t* UTF16String::data() const { return _data; }
size_t UTF16String::length() const { return _length; }
}