diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-12 12:39:21 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-12 12:39:21 +0200 |
commit | 8864cc5aee3b134b0ffc5f53c1593645f4109f8c (patch) | |
tree | ae06a5d64bd72521b447d1abc984f6d2e171e0cb /src/gmutil.c | |
parent | 7bc2f1b1dd089bfd362ad04dad47ab38c6d9ff37 (diff) |
Added option to show URL paths as encoded or decoded
IssueID #73
Diffstat (limited to 'src/gmutil.c')
-rw-r--r-- | src/gmutil.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/gmutil.c b/src/gmutil.c index 68525be9..afca4978 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -151,6 +151,42 @@ static iString *punyDecodeHost_(iRangecc host) { | |||
151 | return result; | 151 | return result; |
152 | } | 152 | } |
153 | 153 | ||
154 | void urlDecodePath_String(iString *d) { | ||
155 | iUrl url; | ||
156 | init_Url(&url, d); | ||
157 | if (isEmpty_Range(&url.path)) { | ||
158 | return; | ||
159 | } | ||
160 | iString *decoded = new_String(); | ||
161 | appendRange_String(decoded, (iRangecc){ constBegin_String(d), url.path.start }); | ||
162 | iString *path = newRange_String(url.path); | ||
163 | iString *decPath = urlDecode_String(path); | ||
164 | append_String(decoded, decPath); | ||
165 | delete_String(decPath); | ||
166 | delete_String(path); | ||
167 | appendRange_String(decoded, (iRangecc){ url.path.end, constEnd_String(d) }); | ||
168 | set_String(d, decoded); | ||
169 | delete_String(decoded); | ||
170 | } | ||
171 | |||
172 | void urlEncodePath_String(iString *d) { | ||
173 | iUrl url; | ||
174 | init_Url(&url, d); | ||
175 | if (isEmpty_Range(&url.path)) { | ||
176 | return; | ||
177 | } | ||
178 | iString *encoded = new_String(); | ||
179 | appendRange_String(encoded , (iRangecc){ constBegin_String(d), url.path.start }); | ||
180 | iString *path = newRange_String(url.path); | ||
181 | iString *encPath = urlEncodeExclude_String(path, "%/ "); | ||
182 | append_String(encoded, encPath); | ||
183 | delete_String(encPath); | ||
184 | delete_String(path); | ||
185 | appendRange_String(encoded, (iRangecc){ url.path.end, constEnd_String(d) }); | ||
186 | set_String(d, encoded); | ||
187 | delete_String(encoded); | ||
188 | } | ||
189 | |||
154 | const iString *absoluteUrl_String(const iString *d, const iString *urlMaybeRelative) { | 190 | const iString *absoluteUrl_String(const iString *d, const iString *urlMaybeRelative) { |
155 | iUrl orig; | 191 | iUrl orig; |
156 | iUrl rel; | 192 | iUrl rel; |