MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / parse

Method parse

src/Chain/libraries/glua/lnetlib.cpp:30–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 namespace net
29 {
30 Uri Uri::parse(const std::wstring &uri)
31 {
32 Uri result;
33
34 typedef std::wstring::const_iterator iterator_t;
35
36 if (uri.length() == 0)
37 return result;
38
39 auto uriEnd = uri.end();
40
41 // get query start
42 auto queryStart = std::find(uri.begin(), uriEnd, L'?');
43
44 // protocol
45 auto protocolStart = uri.begin();
46 auto protocolEnd = std::find(protocolStart, uriEnd, L':'); //"://");
47
48 if (protocolEnd != uriEnd)
49 {
50 std::wstring prot = &*(protocolEnd);
51 if ((prot.length() > 3) && (prot.substr(0, 3) == L"://"))
52 {
53 result.protocol = std::wstring(protocolStart, protocolEnd);
54 protocolEnd += 3; // ://
55 }
56 else
57 protocolEnd = uri.begin(); // no protocol
58 }
59 else
60 protocolEnd = uri.begin(); // no protocol
61 auto hostStart = protocolEnd;
62 auto pathStart = std::find(hostStart, uriEnd, L'/'); // get pathStart
63
64 auto hostEnd = std::find(protocolEnd,
65 (pathStart != uriEnd) ? pathStart : queryStart,
66 L':'); // check for port
67
68 result.host = std::wstring(hostStart, hostEnd);
69
70 if ((hostEnd != uriEnd) && ((&*(hostEnd))[0] == L':')) // we have a port
71 {
72 hostEnd++;
73 auto portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
74 result.port = std::wstring(hostEnd, portEnd);
75 }
76 if (pathStart != uriEnd)
77 result.path = std::wstring(pathStart, queryStart);
78 if (queryStart != uriEnd)
79 result.query_string = std::wstring(queryStart, uri.end());
80
81 return result;
82 }
83 }
84}
85

Calls 6

wstringFunction · 0.85
findFunction · 0.50
lengthMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected