author | Michael Krelin <hacker@klever.net> | 2005-07-20 23:17:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-07-20 23:17:25 (UTC) |
commit | 84a0285be7c7a57cfc00cb31a4a1da9902fa1b34 (patch) (unidiff) | |
tree | 608822c31cbedeb35c7341b88456dd9c826b4d27 /lib/util.cc | |
parent | 9634a1491130ef24130454e951672301e805351f (diff) | |
download | libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.zip libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.gz libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.bz2 |
moved util::canonicalize_url to consumer class
-rw-r--r-- | lib/util.cc | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/lib/util.cc b/lib/util.cc index 1e7335c..d78b5e0 100644 --- a/lib/util.cc +++ b/lib/util.cc | |||
@@ -70,57 +70,32 @@ namespace opkele { | |||
70 | &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday, | 70 | &tm_t.tm_year,&tm_t.tm_mon,&tm_t.tm_mday, |
71 | &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec | 71 | &tm_t.tm_hour,&tm_t.tm_min,&tm_t.tm_sec |
72 | ) != 6 ) | 72 | ) != 6 ) |
73 | throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); | 73 | throw failed_conversion(OPKELE_CP_ "failed to sscanf()"); |
74 | tm_t.tm_mon--; | 74 | tm_t.tm_mon--; |
75 | tm_t.tm_year-=1900; | 75 | tm_t.tm_year-=1900; |
76 | time_t rv = mktime(&tm_t); | 76 | time_t rv = mktime(&tm_t); |
77 | if(rv==(time_t)-1) | 77 | if(rv==(time_t)-1) |
78 | throw failed_conversion(OPKELE_CP_ "failed to mktime()"); | 78 | throw failed_conversion(OPKELE_CP_ "failed to mktime()"); |
79 | return rv; | 79 | return rv; |
80 | } | 80 | } |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * | 83 | * |
84 | */ | 84 | */ |
85 | 85 | ||
86 | string canonicalize_url(const string& url) { | ||
87 | string rv = url; | ||
88 | // strip leading and trailing spaces | ||
89 | string::size_type i = rv.find_first_not_of(" \t\r\n"); | ||
90 | if(i==string::npos) | ||
91 | throw bad_input(OPKELE_CP_ "empty URL"); | ||
92 | if(i) | ||
93 | rv.erase(0,i); | ||
94 | i = rv.find_last_not_of(" \t\r\n"); | ||
95 | assert(i!=string::npos); | ||
96 | if(i<(rv.length()-1)) | ||
97 | rv.erase(i+1); | ||
98 | // add missing http:// | ||
99 | i = rv.find("://"); | ||
100 | if(i==string::npos) { // primitive. but do we need more? | ||
101 | rv.insert(0,"http://"); | ||
102 | i = sizeof("http://")-1; | ||
103 | }else{ | ||
104 | i += sizeof("://")-1; | ||
105 | } | ||
106 | if(rv.find('/',i)==string::npos) | ||
107 | rv += '/'; | ||
108 | return rv; | ||
109 | } | ||
110 | |||
111 | string url_encode(const string& str) { | 86 | string url_encode(const string& str) { |
112 | char * t = curl_escape(str.c_str(),str.length()); | 87 | char * t = curl_escape(str.c_str(),str.length()); |
113 | if(!t) | 88 | if(!t) |
114 | throw failed_conversion(OPKELE_CP_ "failed to curl_escape()"); | 89 | throw failed_conversion(OPKELE_CP_ "failed to curl_escape()"); |
115 | string rv(t); | 90 | string rv(t); |
116 | curl_free(t); | 91 | curl_free(t); |
117 | return rv; | 92 | return rv; |
118 | } | 93 | } |
119 | 94 | ||
120 | string long_to_string(long l) { | 95 | string long_to_string(long l) { |
121 | char rv[32]; | 96 | char rv[32]; |
122 | int r=snprintf(rv,sizeof(rv),"%ld",l); | 97 | int r=snprintf(rv,sizeof(rv),"%ld",l); |
123 | if(r<0 || r>=sizeof(rv)) | 98 | if(r<0 || r>=sizeof(rv)) |
124 | throw failed_conversion(OPKELE_CP_ "failed to snprintf()"); | 99 | throw failed_conversion(OPKELE_CP_ "failed to snprintf()"); |
125 | return rv; | 100 | return rv; |
126 | } | 101 | } |