Change exiv2::urlencode signature to return std::string

The goal of this change is to remove the responsibility from the client code to
free the memory of the returned string.
This commit is contained in:
Luis Díaz Más
2017-11-28 17:32:42 +01:00
parent fd5f131f4e
commit 8b049922d7
4 changed files with 10 additions and 11 deletions
+5 -3
View File
@@ -71,7 +71,7 @@ namespace Exiv2 {
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
} // from_hex
char* urlencode(char* str) {
std::string urlencode(char* str) {
char* pstr = str;
char* buf = (char*)malloc(strlen(str) * 3 + 1);
char* pbuf = buf;
@@ -85,8 +85,10 @@ namespace Exiv2 {
pstr++;
}
*pbuf = '\0';
return buf;
} // urlencode
std::string ret(buf);
free(buf);
return ret;
}
char* urldecode(const char* str) {
const char* pstr = str;