Repository navigation
Expand file tree
/
Copy pathSimpleUri.cpp
More file actions
144 lines (134 loc) · 3.67 KB
/
Copy pathSimpleUri.cpp
File metadata and controls
144 lines (134 loc) · 3.67 KB
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
/*
* Copyright (C) 2012-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SimpleUri.h"
SimpleUri::SimpleUri(const std::wstring& _uri) : m_valid(false)
{
std::wstring temp = _uri;
m_valid = false;
// schema
size_t pos = temp.find(L"://");
if(pos == std::wstring::npos)
{
return;
}
m_scheme = temp.substr(0,pos);
// server and auth
pos += 3;
size_t pos2 = temp.find(L"/",pos);
if(pos2 == std::wstring::npos)
{
return;
}
std::wstring serverPart = temp.substr(pos, pos2-pos);
temp = temp.substr(pos2);
size_t serverSep = serverPart.find(L"@");
if(serverSep != std::wstring::npos)
{
m_auth = serverPart.substr(0,serverSep);
serverPart = serverPart.substr(serverSep+1);
}
size_t portSep = serverPart.find(L":");
if(portSep != std::wstring::npos)
{
m_port = serverPart.substr(portSep+1);
serverPart = serverPart.substr(0,portSep);
}
m_server = serverPart;
// fragment
size_t posAnker = temp.find(L"#");
if(posAnker != std::wstring::npos)
{
m_fragment = temp.substr(posAnker+1);
temp = temp.substr(0,posAnker);
}
// query
size_t posQuery = temp.find(L"?");
if(posQuery != std::wstring::npos)
{
m_query = temp.substr(posQuery+1);
temp = temp.substr(0,posQuery);
}
// path
m_path = temp;
// filename
size_t posLastSep = m_path.rfind(L"/");
if(posLastSep != std::wstring::npos)
{
m_filename = m_path.substr(posLastSep+1);
}
// file extension
size_t posFileExt = m_filename.rfind(L".");
if(posFileExt != std::wstring::npos)
{
m_fileExtension = m_filename.substr(posFileExt);
}
m_valid = true;
}
void SimpleUri::parseServerAndAuth()
{
}
bool SimpleUri::isValid()
{
return m_valid;
}
bool SimpleUri::isHttpOrHttpsSchema()
{
if(!m_valid)
{
return false;
}
if( (m_scheme.size()==4) &&
((m_scheme[0]==L'H')||(m_scheme[0]==L'h')) &&
((m_scheme[1]==L'T')||(m_scheme[1]==L't')) &&
((m_scheme[2]==L'T')||(m_scheme[2]==L't')) &&
((m_scheme[3]==L'P')||(m_scheme[3]==L'p')) )
{
return true;
}
if( (m_scheme.size()==5) &&
((m_scheme[0]==L'H')||(m_scheme[0]==L'h')) &&
((m_scheme[1]==L'T')||(m_scheme[1]==L't')) &&
((m_scheme[2]==L'T')||(m_scheme[2]==L't')) &&
((m_scheme[3]==L'P')||(m_scheme[3]==L'p')) &&
((m_scheme[4]==L'S')||(m_scheme[4]==L's')) )
{
return true;
}
return false;
}
std::wstring SimpleUri::getSchema()
{
return m_scheme;
}
std::wstring SimpleUri::getServer()
{
return m_server;
}
std::wstring SimpleUri::getPath()
{
return m_path;
}
std::wstring SimpleUri::getFilename()
{
return m_filename;
}
std::wstring SimpleUri::getFileExtension()
{
return m_fileExtension;
}