-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathName.cpp
41 lines (33 loc) · 833 Bytes
/
Name.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
#include "Name.h"
#include <cstring>
namespace Bxml {
Name::Name(char* data, size_t length)
{
uint16* nameHashPtr = reinterpret_cast<uint16*>(data);
nameHash = *nameHashPtr;
uint16* lengthPtr = reinterpret_cast<uint16*>(data + sizeof uint16);
this->length = *lengthPtr;
string = new wchar_t[this->length+1];
wchar_t* stringSrc = reinterpret_cast<wchar_t*>(data + 2*(sizeof uint16));
wcsncpy(string, stringSrc, this->length+1);
}
Name::~Name(void)
{
delete []string;
if (Xml != NULL) {
delete Xml;
}
}
size_t Name::getSize(void) {
return ((size_t) this->length) + 2*(sizeof uint16) + sizeof (wchar_t);
}
size_t Name::getLength(void) {
return (size_t) this->length;
}
std::wstring* Name::toXml() {
if (Xml == NULL) {
Xml = new std::wstring(string);
}
return Xml;
}
}