summaryrefslogtreecommitdiff
path: root/externals/lurlparser/LUrlParser.h
diff options
context:
space:
mode:
Diffstat (limited to 'externals/lurlparser/LUrlParser.h')
-rw-r--r--externals/lurlparser/LUrlParser.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/externals/lurlparser/LUrlParser.h b/externals/lurlparser/LUrlParser.h
new file mode 100644
index 000000000..25d210981
--- /dev/null
+++ b/externals/lurlparser/LUrlParser.h
@@ -0,0 +1,78 @@
1/*
2 * Lightweight URL & URI parser (RFC 1738, RFC 3986)
3 * https://github.com/corporateshark/LUrlParser
4 *
5 * The MIT License (MIT)
6 *
7 * Copyright (C) 2015 Sergey Kosarevsky (sk@linderdaum.com)
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#pragma once
29
30#include <string>
31
32namespace LUrlParser
33{
34enum LUrlParserError
35{
36 LUrlParserError_Ok = 0,
37 LUrlParserError_Uninitialized = 1,
38 LUrlParserError_NoUrlCharacter = 2,
39 LUrlParserError_InvalidSchemeName = 3,
40 LUrlParserError_NoDoubleSlash = 4,
41 LUrlParserError_NoAtSign = 5,
42 LUrlParserError_UnexpectedEndOfLine = 6,
43 LUrlParserError_NoSlash = 7,
44};
45
46class clParseURL
47{
48public:
49 LUrlParserError m_ErrorCode;
50 std::string m_Scheme;
51 std::string m_Host;
52 std::string m_Port;
53 std::string m_Path;
54 std::string m_Query;
55 std::string m_Fragment;
56 std::string m_UserName;
57 std::string m_Password;
58
59 clParseURL()
60 : m_ErrorCode( LUrlParserError_Uninitialized )
61 {}
62
63 /// return 'true' if the parsing was successful
64 bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
65
66 /// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
67 bool GetPort( int* OutPort ) const;
68
69 /// parse the URL
70 static clParseURL ParseURL( const std::string& URL );
71
72private:
73 explicit clParseURL( LUrlParserError ErrorCode )
74 : m_ErrorCode( ErrorCode )
75 {}
76};
77
78} // namespace LUrlParser