Web Wispers 1.2.2 C++ Unit Test Coverage |
|
|
|
|
Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * https://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the URI class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WSPR_FCGI_URI_H
23 : : #define __SSRC_WSPR_FCGI_URI_H
24 : :
25 : : #include <ssrc/wispers-packages.h>
26 : :
27 : : #include <boost/regex.hpp>
28 : :
29 : : __BEGIN_NS_SSRC_WSPR_FCGI
30 : :
31 : : using std::string;
32 : :
33 [ + - ]: 1 : class URI {
34 : :
35 : : static const boost::regex URIPattern;
36 : :
37 : : enum URIPart {
38 : : URIScheme = 1, URIAuthority, URIPath, URIQuery, URIFragment
39 : : };
40 : :
41 : : string _uri;
42 : : boost::smatch _match_result;
43 : :
44 : 5 : string uri_part(const URIPart part) const {
45 : 5 : return _match_result[part].str();
46 : : }
47 : :
48 : : public:
49 : :
50 : 1 : URI(const string & uri) SSRC_DECL_THROW(std::invalid_argument) :
51 [ + - ]: 1 : _uri(uri), _match_result()
52 : : {
53 [ + - - + ]: 1 : if(!boost::regex_match(uri, _match_result, URIPattern))
54 [ # # # # ]: 0 : throw std::invalid_argument("bad uri");
55 : 1 : }
56 : :
57 : 1 : bool absolute() const {
58 : 1 : return _match_result[URIScheme].matched;
59 : : }
60 : :
61 : 1 : string uri() const { return _uri; }
62 : :
63 : 1 : string scheme() const { return uri_part(URIScheme); }
64 : :
65 : 1 : string authority() const { return uri_part(URIAuthority); }
66 : :
67 : 1 : string path() const { return uri_part(URIPath); }
68 : :
69 : 1 : string query() const { return uri_part(URIQuery); }
70 : :
71 : 1 : string fragment() const { return uri_part(URIFragment); }
72 : :
73 : : };
74 : :
75 : : __END_NS_SSRC_WSPR_FCGI
76 : :
77 : : #endif
|
Copyright © 2017 Savarese Software Research Corporation. All rights reserved