forked from spring/spring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUriParser.cpp
More file actions
49 lines (43 loc) · 1.4 KB
/
UriParser.cpp
File metadata and controls
49 lines (43 loc) · 1.4 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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "UriParser.h"
#include "StringUtil.h"
static void SplitString(const std::string& text, const char* sepChar, std::string& s1, std::string& s2, std::string& all)
{
const size_t q = text.find(sepChar);
if (q != std::string::npos) {
s1 = text.substr(0, q);
s2 = text.substr(q + 1);
return;
}
all = text;
}
bool ParseSpringUri(const std::string& uri, std::string& username, std::string& password, std::string& host, int& port)
{
// see http://cpp-netlib.org/0.10.1/in_depth/uri.html (2014)
if (uri.find("spring://") == std::string::npos)
return false; // wrong scheme
const std::string full = uri.substr(std::string("spring://").length());
std::string authority, query, user_info, server, portStr;
bool error = false;
SplitString(full, "/", authority, query, authority);
SplitString(authority, "@", user_info, server, server);
SplitString(user_info, ":", username, password, username);
SplitString(server, ":", host, portStr, host);
if (portStr.empty())
return true;
port = StringToInt(portStr, &error);
if (error) {
port = 0;
return false;
}
//FIXME pass query
return true;
}
bool ParseRapidUri(const std::string& uri, std::string& tag)
{
if (uri.find("rapid://") == std::string::npos) {
return false; // wrong scheme
}
tag = uri.substr(std::string("rapid://").length());
return !tag.empty();
}