FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/misc/uric.cpp at master · Shekn/daScript · GitHub
Shekn
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
src
/
misc
/
uric.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
243 lines (211 loc) · 6.76 KB
Breadcrumbs
daScript
/
src
/
misc
/
uric.cpp
Copy path
File metadata and controls
243 lines (211 loc) · 6.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/misc/uric.h
"
namespace
das
{
Uri::Uri
(UriUriA && uriA) {
uri = uriA;
memset
(&uriA,
0
,
sizeof
(UriUriA));
isEmpty =
false
;
lastOp =
0
;
}
Uri::Uri
() {
memset
(&uri,
0
,
sizeof
(UriUriA));
isEmpty =
true
;
}
Uri::Uri
(
const
char
* uriString) {
memset
(&uri,
0
,
sizeof
(UriUriA));
parse
(uriString);
}
Uri::Uri
(
const
string & uriS) {
memset
(&uri,
0
,
sizeof
(UriUriA));
parse
(uriS.
c_str
());
}
Uri::Uri
(
const
Uri & uriA) {
memset
(&uri,
0
,
sizeof
(UriUriA));
clone
(uriA);
}
Uri::Uri
(Uri && uriA) {
memset
(&uri,
0
,
sizeof
(UriUriA));
if
( !uriA.
isEmpty
) {
memcpy
(&uri,&uriA.
uri
,
sizeof
(UriUriA));
uriA.
isEmpty
=
true
;
lastOp = uriA.
lastOp
;
errorPos = uriA.
errorPos
;
isEmpty =
false
;
}
}
Uri & Uri::
operator
= (
const
Uri & uriA ) {
reset
();
clone
(uriA);
return
*
this
;
}
Uri & Uri::
operator
= ( Uri && uriA ) {
reset
();
if
( !uriA.
isEmpty
) {
memcpy
(&uri,&uriA.
uri
,
sizeof
(UriUriA));
uriA.
isEmpty
=
true
;
lastOp = uriA.
lastOp
;
errorPos = uriA.
errorPos
;
isEmpty =
false
;
}
return
*
this
;
}
Uri & Uri::
operator
= (
const
char
* uriString ) {
reset
();
parse
(uriString);
return
*
this
;
}
Uri & Uri::
operator
= (
const
string & uriS ) {
reset
();
parse
(uriS.
c_str
());
return
*
this
;
}
Uri::~Uri
() {
reset
();
}
Uri
Uri::addBaseUri
(
const
Uri & base )
const
{
UriUriA absoluteDest;
auto
lOp =
uriAddBaseUriA
(&absoluteDest, &uri, &base.
uri
);
if
( lOp !=
URI_SUCCESS
) {
uriFreeUriMembersA
(&absoluteDest);
Uri failed;
failed.
lastOp
= lOp;
return
failed;
}
return
Uri
(
das::move
(absoluteDest));
}
Uri
Uri::strip
(
bool
query,
bool
fragment)
const
{
UriUriA saveUri = uri;
if
( query ) {
uri.
query
.
first
=
nullptr
;
uri.
query
.
afterLast
=
nullptr
;
}
if
( fragment ) {
uri.
fragment
.
first
=
nullptr
;
uri.
fragment
.
afterLast
=
nullptr
;
}
auto
text =
str
();
uri = saveUri;
return
Uri
(text);
}
Uri
Uri::removeBaseUri
(
const
Uri & base )
const
{
UriUriA dest;
auto
lOp =
uriRemoveBaseUriA
(&dest, &uri, &base.
uri
,
URI_FALSE
);
if
( lOp !=
URI_SUCCESS
) {
uriFreeUriMembersA
(&dest);
Uri failed;
failed.
lastOp
= lOp;
return
failed;
}
return
Uri
(
das::move
(dest));
}
bool
Uri::normalize
() {
const
unsigned
int
dirtyParts =
uriNormalizeSyntaxMaskRequiredA
(&uri);
lastOp =
uriNormalizeSyntaxExA
(&uri, dirtyParts);
return
lastOp ==
URI_SUCCESS
;
}
void
Uri::reset
() {
if
( !isEmpty ) {
uriFreeUriMembersA
(&uri);
isEmpty =
true
;
}
errorPos =
0
;
lastOp =
URI_SUCCESS
;
}
bool
Uri::parse
(
const
char
* uriString ) {
if
( uriString==
nullptr
) uriString =
"
"
;
reset
();
lastOp =
uriParseSingleUriA
(&uri, uriString, &errorPos);
if
( lastOp !=
URI_SUCCESS
)
return
false
;
uriMakeOwnerA
(&uri);
isEmpty =
false
;
lastOp =
URI_SUCCESS
;
return
true
;
}
void
Uri::clone
(
const
Uri & uriS ) {
reset
();
if
( !uriS.
isEmpty
)
parse
(uriS.
str
().
c_str
());
}
int
Uri::size
()
const
{
if
( isEmpty )
return
0
;
int
charsRequired;
lastOp =
uriToStringCharsRequiredA
(&uri, &charsRequired);
return
(lastOp !=
URI_SUCCESS
) ?
0
: charsRequired;
}
string
Uri::str
()
const
{
int
charsRequired =
size
();
if
(lastOp !=
URI_SUCCESS
)
return
"
"
;
charsRequired++;
vector<
char
> result;
result.
reserve
(charsRequired);
lastOp =
uriToStringA
(result.
data
(), &uri, charsRequired,
nullptr
);
return
result.
data
();
}
string
Uri::toUnixFileName
()
const
{
auto
uriS =
str
();
vector<
char
> result;
result.
reserve
(uriS.
length
()+
1
);
lastOp =
uriUriStringToUnixFilenameA
(uriS.
c_str
(), result.
data
());
return
result.
data
();
}
string
Uri::toWindowsFileName
()
const
{
auto
uriS =
str
();
vector<
char
> result;
result.
reserve
(uriS.
length
()+
1
);
lastOp =
uriUriStringToWindowsFilenameA
(uriS.
c_str
(), result.
data
());
return
result.
data
();
}
string
Uri::toFileName
()
const
{
#
ifdef
_WIN32
return
toWindowsFileName
();
#
else
return
toUnixFileName
();
#
endif
}
bool
Uri::fromUnixFileNameStr
(
const
char
* fileName,
int
len ) {
vector<
char
> result;
if
( len==-
1
) len =
int
(
strlen
(fileName));
result.
reserve
(
3
*len +
1
);
lastOp =
uriUnixFilenameToUriStringA
(fileName, result.
data
());
if
( lastOp !=
URI_SUCCESS
)
return
false
;
return
parse
(result.
data
());
}
bool
Uri::fromWindowsFileNameStr
(
const
char
* fileName,
int
len ) {
vector<
char
> result;
if
( len==-
1
) len =
int
(
strlen
(fileName));
result.
reserve
(
8
+
3
*len +
1
);
lastOp =
uriWindowsFilenameToUriStringA
(fileName, result.
data
());
if
( lastOp !=
URI_SUCCESS
)
return
false
;
return
parse
(result.
data
());
}
bool
Uri::fromFileNameStr
(
const
char
* fileName,
int
len ) {
#
ifdef
_WIN32
return
fromWindowsFileNameStr
(fileName,len);
#
else
return
fromUnixFileNameStr
(fileName,len);
#
endif
}
bool
Uri::fromUnixFileName
(
const
string & fileName ) {
return
fromUnixFileNameStr
(fileName.
c_str
(),
int
(fileName.
length
()));
}
bool
Uri::fromWindowsFileName
(
const
string & fileName ) {
return
fromWindowsFileNameStr
(fileName.
c_str
(),
int
(fileName.
length
()));
}
bool
Uri::fromFileName
(
const
string & fileName ) {
return
fromFileNameStr
(fileName.
c_str
(),
int
(fileName.
length
()));
}
vector<pair<string,string>>
Uri::query
()
const
{
vector<pair<string,string>> res;
if
( !isEmpty ) {
UriQueryListA * queryList;
int
itemCount;
lastOp =
uriDissectQueryMallocA
(&queryList, &itemCount, uri.
query
.
first
,uri.
query
.
afterLast
);
if
( lastOp ==
URI_SUCCESS
) {
for
(
auto
q=queryList; q!=
nullptr
; q=q->
next
) {
res.
push_back
(make_pair<string,string>(q->
key
? q->
key
:
"
"
,q->
value
? q->
value
:
"
"
));
}
}
uriFreeQueryListA
(queryList);
}
return
res;
}
}
Back
|
FazBrowse Home
|
New Git URL