Check-in [f523284c49]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1 Hash:f523284c49384c079bbf83c46642e8aa50cda413
Date: 2008-09-18 16:09:50
User: stephan
Comment:added exception handling to test case.
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to url.cpp

Old (097a71e90f68aee7) New (0632db388b79a9f9)
1 #include "parsepp.hpp" 1 #include "parsepp.hpp"
2 #include "parsepp_url.hpp" <
3 #include <map> <
4 #include <string> <
5 2
6 #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " 3 #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : "
7 #define COUT std::cout << __FILE__ << ":" << std::dec << __LINE__ << " : " 4 #define COUT std::cout << __FILE__ << ":" << std::dec << __LINE__ << " : "
8 #define DOUT if(0) COUT 5 #define DOUT if(0) COUT
> 6
> 7 #include "parsepp_url.hpp"
> 8 #include <map>
> 9 #include <string>
> 10
9 11
10 12
11 int main( int argc, char ** argv ) 13 int main( int argc, char ** argv )
12 { 14 {
13 std::string scr = "abc=def&ghi=value #2"; 15 std::string scr = "abc=def&ghi=value #2";
14 std::string line; 16 std::string line;
15 using namespace Ps; 17 using namespace Ps;
16 url::url_state state; 18 url::url_state state;
17 for ( int arg = 0; arg < argc; ++arg ) { | 19 try
18 if( (argc>1) && (0==arg) ) continue; | 20 {
19 line = (argc>1) ? argv[ arg ] : scr.c_str(); | 21 for ( int arg = 0; arg < argc; ++arg ) {
20 COUT << "Trying: " << line << '\n'; | 22 if( (argc>1) && (0==arg) ) continue;
21 if ( Ps::url::parse_url( line, state ) ) { | 23 line = (argc>1) ? argv[ arg ] : scr.c_str();
22 COUT << "Parsed OK: " << line << '\n'; | 24 COUT << "Trying: " << line << '\n';
23 } | 25 if ( Ps::url::parse_url( line, state ) ) {
24 else { | 26 COUT << "Parsed OK: " << line << '\n';
25 COUT << "Parsed FAILED: " << line << '\n'; | 27 }
26 return 1; | 28 else {
27 } | 29 COUT << "Parsed FAILED: " << line << '\n';
28 COUT << "URL parts:\n"; | 30 return 1;
29 typedef url::url_state::kvpmap MT; | 31 }
30 MT::const_iterator it = state.parts.begin(); | 32 COUT << "URL parts:\n";
31 MT::const_iterator et = state.parts.end(); | 33 typedef url::url_state::kvpmap MT;
32 for( ; it != et; ++it ) | 34 MT::const_iterator it = state.parts.begin();
33 { | 35 MT::const_iterator et = state.parts.end();
34 COUT << '\t' << (*it).first << '=' << (*it).second << '\n'; | 36 for( ; it != et; ++it )
35 } | 37 {
36 COUT << "kvp map entry count: "<<state.params.size()<<std::endl; | 38 COUT << '\t' << (*it).first << '=' << (*it).second << '\n';
37 it = state.params.begin(); | 39 }
38 et = state.params.end(); | 40 COUT << "kvp map entry count: "<<state.params.size()<<std::endl;
39 for( ; it != et; ++it ) | 41 it = state.params.begin();
40 { | 42 et = state.params.end();
41 COUT << '\t' << (*it).first << '=' << (*it).second << '\n'; | 43 for( ; it != et; ++it )
| 44 {
| 45 COUT << '\t' << (*it).first << '=' << (*it).second << '\n';
| 46 }
| 47 state.clear();
42 } 48 }
43 state.clear(); <
44 } 49 }
45 | 50 catch( std::exception const & ex )
46 | 51 {
| 52 CERR << "Parse exception:\n" << ex.what() << '\n';
| 53 return 1;
| 54 }
47 return 0; 55 return 0;
48 } 56 }