diff options
Diffstat (limited to 'tinySAK/src/tsk_url.c')
-rwxr-xr-x | tinySAK/src/tsk_url.c | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/tinySAK/src/tsk_url.c b/tinySAK/src/tsk_url.c index 8734ab6..cf4417b 100755 --- a/tinySAK/src/tsk_url.c +++ b/tinySAK/src/tsk_url.c @@ -1,18 +1,18 @@ /* * Copyright (C) 2010-2015 Mamadou DIOP. -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -41,22 +41,23 @@ * @sa tsk_url_decode * */ -char* tsk_url_encode(const char* url) { - char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) * 3 + 1), *pbuf = buf; - while (*purl) { - if (isalnum(*purl) || *purl == '-' || *purl == '_' || *purl == '.' || *purl == '~'){ - *pbuf++ = *purl; - } - else if (*purl == ' '){ - *pbuf++ = '+'; - } - else{ - *pbuf++ = '%', *pbuf++ = tsk_b10tob16(*purl >> 4), *pbuf++ = tsk_b10tob16(*purl & 15); - } - purl++; - } - *pbuf = '\0'; - return buf; +char* tsk_url_encode(const char* url) +{ + char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) * 3 + 1), *pbuf = buf; + while (*purl) { + if (isalnum(*purl) || *purl == '-' || *purl == '_' || *purl == '.' || *purl == '~') { + *pbuf++ = *purl; + } + else if (*purl == ' ') { + *pbuf++ = '+'; + } + else { + *pbuf++ = '%', *pbuf++ = tsk_b10tob16(*purl >> 4), *pbuf++ = tsk_b10tob16(*purl & 15); + } + purl++; + } + *pbuf = '\0'; + return buf; } /**@ingroup tsk_url_group @@ -66,24 +67,25 @@ char* tsk_url_encode(const char* url) { * * @sa tsk_url_encode */ -char* tsk_url_decode(const char* url) { - char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) + 1), *pbuf = buf; - while (*purl) { - if (*purl == '%') { - if (purl[1] && purl[2]) { - *pbuf++ = tsk_b16tob10(purl[1]) << 4 | tsk_b16tob10(purl[2]); - purl += 2; - } - } - else if (*purl == '+') { - *pbuf++ = ' '; - } - else { - *pbuf++ = *purl; - } - purl++; - } - *pbuf = '\0'; - return buf; +char* tsk_url_decode(const char* url) +{ + char *purl = (char*)url, *buf = (char*)tsk_malloc(tsk_strlen(url) + 1), *pbuf = buf; + while (*purl) { + if (*purl == '%') { + if (purl[1] && purl[2]) { + *pbuf++ = tsk_b16tob10(purl[1]) << 4 | tsk_b16tob10(purl[2]); + purl += 2; + } + } + else if (*purl == '+') { + *pbuf++ = ' '; + } + else { + *pbuf++ = *purl; + } + purl++; + } + *pbuf = '\0'; + return buf; } |