Support conversion of linkshere
[dueringa_WikiWalker.git] / lib / LUrlParser / LUrlParser.h
blobe347b369cb25284b0d1b65c9475dc155e1e21b21
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:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
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.
28 #pragma once
30 #include <string>
32 namespace LUrlParser
34 enum LUrlParserError
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,
46 class clParseURL
48 public:
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;
59 clParseURL()
60 : m_ErrorCode( LUrlParserError_Uninitialized )
63 /// return 'true' if the parsing was successful
64 bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
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;
69 /// parse the URL
70 static clParseURL ParseURL( const std::string& URL );
72 private:
73 explicit clParseURL( LUrlParserError ErrorCode )
74 : m_ErrorCode( ErrorCode )
78 } // namespace LUrlParser