forked from jonmmorgan/wxwebconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsstr.h
162 lines (126 loc) · 3.31 KB
/
nsstr.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
///////////////////////////////////////////////////////////////////////////////
// Name: nsstr.h
// Purpose: wxwebconnect: embedded web browser control library
// Author: Benjamin I. Williams
// Modified by:
// Created: 2006-10-08
// RCS-ID:
// Copyright: (C) Copyright 2006-2010, Kirix Corporation, All Rights Reserved.
// Licence: wxWindows Library Licence, Version 3.1
///////////////////////////////////////////////////////////////////////////////
#ifndef __WXWEBCONNECT_NSSTR_H
#define __WXWEBCONNECT_NSSTR_H
struct nsStringContainer
{
void* v;
void* d1;
PRUint32 d2;
void* d3;
};
struct nsCStringContainer
{
void* v;
void* d1;
PRUint32 d2;
void* d3;
};
class nsAString
{
protected:
nsAString() { }
~nsAString() { }
};
class nsACString
{
protected:
nsACString() { }
~nsACString() { }
};
class nsString : public nsAString,
public nsStringContainer
{
public:
nsString()
{
NS_StringContainerInit(*this);
}
nsString(const PRUnichar* data, size_t len, PRUint32 flags)
{
NS_StringContainerInit2(*this, data, len, flags);
}
~nsString()
{
NS_StringContainerFinish(*this);
}
void Assign(const PRUnichar* str, int len = PR_UINT32_MAX)
{
NS_StringSetData(*this, str, len);
}
};
class nsCString : public nsACString,
public nsCStringContainer
{
public:
nsCString()
{
NS_CStringContainerInit(*this);
}
~nsCString()
{
NS_CStringContainerFinish(*this);
}
nsCString(const char* data, size_t len, PRUint32 flags)
{
NS_CStringContainerInit2(*this, data, len, flags);
}
const char* get() const
{
const char* ptr;
NS_CStringGetData(*this, &ptr);
return ptr;
}
void Assign(const char* str, int len = PR_UINT32_MAX)
{
NS_CStringContainerFinish(*this);
NS_CStringContainerInit2(*this, str, len);
}
};
class nsDependentString : public nsString
{
public:
nsDependentString(const PRUnichar* data, size_t len = PR_UINT32_MAX)
: nsString(data, len, 0x02/*NS_STRING_CONTAINER_INIT_DEPEND*/)
{
}
#ifndef _MSC_VER
// for platforms with 4-byte wchar_t
nsDependentString(const wchar_t* wdata, size_t specified_len = PR_UINT32_MAX)
: nsString()
{
size_t i, len = 0;
// determine length
while (*(wdata+len))
len++;
if (specified_len != PR_UINT32_MAX && specified_len < len)
len = specified_len;
PRUnichar* data = new PRUnichar[len+1];
for (i = 0; i < len; ++i)
data[i] = wdata[i];
Assign(data, len);
delete[] data;
}
#endif
};
class nsDependentCString : public nsCString
{
public:
nsDependentCString(const char* data, size_t len = PR_UINT32_MAX)
: nsCString(data, len, 0x02/*NS_CSTRING_CONTAINER_INIT_DEPEND*/)
{
}
};
typedef nsString nsEmbedString;
typedef nsCString nsEmbedCString;
#define NS_LITERAL_STRING(s) nsDependentString(L##s)
#define NS_LITERAL_CSTRING(s) nsDependentCString(s)
#endif