-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpstring.cpp
More file actions
72 lines (61 loc) · 1015 Bytes
/
Copy pathpstring.cpp
File metadata and controls
72 lines (61 loc) · 1015 Bytes
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "pstring.h"
PString::PString()
: m_size(0)
{
m_buf[0] = '\0';
}
PString::PString(const char* s)
{
this->assign(s, strlen(s));
}
uint32_t PString::GetMsgSize()
{
return sizeof(uint32_t) + m_size;
}
const char* PString::c_str() const
{
return m_buf;
}
char* PString::data()
{
return m_buf;
}
int PString::size() const
{
return m_size;
}
bool PString::operator<(const PString& rstr) const
{
if (m_size == rstr.size())
{
int n = memcmp(m_buf, rstr.c_str(), m_size);
if (n < 0)
{
return true;
}
else
{
return false;
}
}
else
{
return m_size < rstr.size();
}
}
void PString::assign(const char* s, int sSize)
{
m_size = 0;
this->append(s, sSize);
}
void PString::append(const char* s, int sSize)
{
memcpy(m_buf + m_size, s, sSize);
m_size += sSize;
m_buf[m_size] = '\0';
}
PString& PString::operator = (const PString& rstr)
{
this->assign(rstr.c_str(), rstr.size());
return *this;
}