-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuri.cpp
More file actions
64 lines (52 loc) · 1.18 KB
/
Copy pathuri.cpp
File metadata and controls
64 lines (52 loc) · 1.18 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
#include <string>
#include "uri.hpp"
namespace jdd{
URI::URI(string uri):
uri(uri)
{
}
URI::operator string () const
{
return uri;
}
string URI::operator = (const string &rhv)
{
uri = rhv;
return rhv;
}
string URI::scheme() const
{
return uri.substr(0, uri.find(":"));
}
string URI::path() const
{
unsigned int pathPos = uri.find(":");
if(pathPos == string::npos) return "";
else pathPos++;
unsigned int pathLen = uri.find_first_of("?#") - pathPos;
return uri.substr(pathPos, pathLen);
}
string URI::query() const
{
unsigned int qPos = uri.find("?");
if(qPos == string::npos) return "";
else qPos++;
unsigned int qLen = uri.find_first_of("#") - qPos;
return uri.substr(qPos, qLen);
}
string URI::queryVal(string key, string defaultVal) const
{
string q = query();
unsigned int keyPos = q.find(key);
if(keyPos == string::npos) return defaultVal;
unsigned int valPos = keyPos + key.length() + 1;
unsigned int valLen = q.find_first_of("&#", valPos) - valPos;
return q.substr(valPos, valLen);
}
//==============================================================================
ostream& operator<<(ostream& os, const jdd::URI& uri)
{
os << (string)uri;
return os;
}
}// end namespace