-
Notifications
You must be signed in to change notification settings - Fork 37
/
AIMPString.cpp
51 lines (41 loc) · 1.5 KB
/
AIMPString.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
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "AIMPString.h"
#include <codecvt>
IAIMPCore *AIMPString::m_core = nullptr;
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> wStrConverter;
AIMPString::AIMPString() {
if (!m_core)
return;
m_core->CreateObject(IID_IAIMPString, reinterpret_cast<void **>(&m_string));
}
AIMPString::AIMPString(const std::wstring &string) {
if (!m_core)
return;
if (SUCCEEDED(m_core->CreateObject(IID_IAIMPString, reinterpret_cast<void **>(&m_string)))) {
m_string->SetData(const_cast<wchar_t *>(string.data()), string.size());
}
}
AIMPString::AIMPString(const wchar_t *string) {
if (!m_core)
return;
if (SUCCEEDED(m_core->CreateObject(IID_IAIMPString, reinterpret_cast<void **>(&m_string)))) {
m_string->SetData(const_cast<wchar_t *>(string), wcslen(string));
}
}
AIMPString::AIMPString(const rapidjson::Value &val) {
if (!m_core)
return;
if (SUCCEEDED(m_core->CreateObject(IID_IAIMPString, reinterpret_cast<void **>(&m_string)))) {
if (val.IsString() && val.GetStringLength() > 0) {
const char *ptr = val.GetString();
std::wstring str = wStrConverter.from_bytes(ptr, ptr + val.GetStringLength());
m_string->SetData(const_cast<wchar_t *>(str.data()), str.size());
} else {
m_string->Release();
m_string = nullptr;
}
}
}
AIMPString::~AIMPString() {
if (m_string)
m_string->Release();
}