13
0

Remove unused ustring version of url_decode(). Rework

the other version to be a bit simpler, avoiding #4800.


git-svn-id: svn://localhost/ardour2/branches/3.0@11771 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2012-04-01 14:30:06 +00:00
parent 3240a93aad
commit 7f417fb44f
4 changed files with 16 additions and 90 deletions

View File

@ -3132,14 +3132,13 @@ Editor::convert_drop_to_paths (
if ((*i).substr (0,7) == "file://") {
string p = *i;
PBD::url_decode (p);
string const p = PBD::url_decode (*i);
// scan forward past three slashes
string::size_type slashcnt = 0;
string::size_type n = 0;
string::iterator x = p.begin();
string::const_iterator x = p.begin();
while (slashcnt < 3 && x != p.end()) {
if ((*x) == '/') {

View File

@ -178,94 +178,23 @@ int_from_hex (char hic, char loc)
return lo + (16 * hi);
}
void
url_decode (string& url)
string
url_decode (string const & url)
{
string::iterator last;
string::iterator next;
string decoded;
for (string::iterator i = url.begin(); i != url.end(); ++i) {
if ((*i) == '+') {
*i = ' ';
}
}
if (url.length() <= 3) {
return;
}
last = url.end();
--last; /* points at last char */
--last; /* points at last char - 1 */
for (string::iterator i = url.begin(); i != last; ) {
if (*i == '%') {
next = i;
url.erase (i);
i = next;
++next;
if (isxdigit (*i) && isxdigit (*next)) {
/* replace first digit with char */
*i = int_from_hex (*i,*next);
++i; /* points at 2nd of 2 digits */
url.erase (i);
}
for (string::size_type i = 0; i < url.length(); ++i) {
if (url[i] == '+') {
decoded += ' ';
} else if (url[i] == '%' && i <= url.length() - 3) {
decoded += char (int_from_hex (url[i + 1], url[i + 2]));
i += 2;
} else {
++i;
}
}
}
void
url_decode (ustring& url)
{
ustring::iterator last;
ustring::iterator next;
for (ustring::iterator i = url.begin(); i != url.end(); ++i) {
if ((*i) == '+') {
next = i;
++next;
url.replace (i, next, 1, ' ');
decoded += url[i];
}
}
if (url.length() <= 3) {
return;
}
last = url.end();
--last; /* points at last char */
--last; /* points at last char - 1 */
for (ustring::iterator i = url.begin(); i != last; ) {
if (*i == '%') {
next = i;
url.erase (i);
i = next;
++next;
if (isxdigit (*i) && isxdigit (*next)) {
/* replace first digit with char */
url.replace (i, next, 1, (gunichar) int_from_hex (*i,*next));
++i; /* points at 2nd of 2 digits */
url.erase (i);
}
} else {
++i;
}
}
return decoded;
}
#if 0

View File

@ -35,8 +35,7 @@ int atoi (const std::string&);
int32_t atol (const std::string&);
int64_t atoll (const std::string&);
double atof (const std::string&);
void url_decode (std::string&);
void url_decode (Glib::ustring&);
std::string url_decode (std::string const &);
std::string capitalize (const std::string&);

View File

@ -8,7 +8,6 @@ using namespace std;
void
ConvertTest::testUrlDecode ()
{
string url = "http://foo.bar.baz/A%20B%20C%20.html";
PBD::url_decode (url);
CPPUNIT_ASSERT_EQUAL (url, string ("http://foo.bar.baz/A B C .html"));
string const url = "http://foo.bar.baz/A%20B%20C%20+42.html";
CPPUNIT_ASSERT_EQUAL (PBD::url_decode (url), string ("http://foo.bar.baz/A B C 42.html"));
}