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://") { if ((*i).substr (0,7) == "file://") {
string p = *i; string const p = PBD::url_decode (*i);
PBD::url_decode (p);
// scan forward past three slashes // scan forward past three slashes
string::size_type slashcnt = 0; string::size_type slashcnt = 0;
string::size_type n = 0; string::size_type n = 0;
string::iterator x = p.begin(); string::const_iterator x = p.begin();
while (slashcnt < 3 && x != p.end()) { while (slashcnt < 3 && x != p.end()) {
if ((*x) == '/') { if ((*x) == '/') {

View file

@ -178,94 +178,23 @@ int_from_hex (char hic, char loc)
return lo + (16 * hi); return lo + (16 * hi);
} }
void string
url_decode (string& url) url_decode (string const & url)
{ {
string::iterator last; string decoded;
string::iterator next;
for (string::iterator i = url.begin(); i != url.end(); ++i) { for (string::size_type i = 0; i < url.length(); ++i) {
if ((*i) == '+') { if (url[i] == '+') {
*i = ' '; decoded += ' ';
} } else if (url[i] == '%' && i <= url.length() - 3) {
} decoded += char (int_from_hex (url[i + 1], url[i + 2]));
i += 2;
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);
}
} else { } else {
++i; decoded += url[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, ' ');
} }
} }
if (url.length() <= 3) { return decoded;
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;
}
}
} }
#if 0 #if 0

View file

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

View file

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