try to better handle non-ascii file names
This commit is contained in:
+36
-1
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.9 2006-02-02 08:58:11 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: pathut.cpp,v 1.10 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -189,6 +189,41 @@ list<std::string> path_dirglob(const std::string &dir,
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string url_encode(const std::string url, string::size_type offs)
|
||||
{
|
||||
string out = url.substr(0, offs);
|
||||
const char *cp = url.c_str();
|
||||
for (string::size_type i = offs; i < url.size(); i++) {
|
||||
int c;
|
||||
char *h = "0123456789ABCDEF";
|
||||
c = cp[i];
|
||||
if(c <= 0x1f ||
|
||||
c >= 0x7f ||
|
||||
c == '<' ||
|
||||
c == '>' ||
|
||||
c == ' ' ||
|
||||
c == '\t'||
|
||||
c == '"' ||
|
||||
c == '#' ||
|
||||
c == '%' ||
|
||||
c == '{' ||
|
||||
c == '}' ||
|
||||
c == '|' ||
|
||||
c == '\\' ||
|
||||
c == '^' ||
|
||||
c == '~'||
|
||||
c == '[' ||
|
||||
c == ']' ||
|
||||
c == '`') {
|
||||
out += '%';
|
||||
out += h[(c >> 4) & 0xf];
|
||||
out += h[c & 0xf];
|
||||
} else {
|
||||
out += char(c);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#else // TEST_PATHUT
|
||||
|
||||
|
||||
+5
-1
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _PATHUT_H_INCLUDED_
|
||||
#define _PATHUT_H_INCLUDED_
|
||||
/* @(#$Id: pathut.h,v 1.7 2006-03-20 09:54:22 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: pathut.h,v 1.8 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -40,4 +40,8 @@ extern std::string path_canon(const std::string &s);
|
||||
/// Use glob(3) to return a list of file names matching pattern inside dir
|
||||
extern std::list<std::string> path_dirglob(const std::string &dir,
|
||||
const std::string pattern);
|
||||
/// Encode according to rfc 1738
|
||||
extern std::string url_encode(const std::string url,
|
||||
std::string::size_type offs);
|
||||
|
||||
#endif /* _PATHUT_H_INCLUDED_ */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.6 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.7 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -40,14 +40,15 @@ using std::string;
|
||||
#endif
|
||||
|
||||
bool transcode(const string &in, string &out, const string &icode,
|
||||
const string &ocode)
|
||||
const string &ocode, int *ecnt)
|
||||
{
|
||||
iconv_t ic;
|
||||
bool ret = false;
|
||||
const int OBSIZ = 8192;
|
||||
char obuf[OBSIZ], *op;
|
||||
bool icopen = false;
|
||||
|
||||
if (ecnt)
|
||||
*ecnt = 0;
|
||||
out.erase();
|
||||
size_t isiz = in.length();
|
||||
out.reserve(isiz);
|
||||
@@ -79,6 +80,8 @@ bool transcode(const string &in, string &out, const string &icode,
|
||||
ip - in.c_str(), out.length() + OBSIZ - osiz));
|
||||
out.append(obuf, OBSIZ - osiz);
|
||||
out += "?";
|
||||
if (ecnt)
|
||||
(*ecnt)++;
|
||||
ip++;isiz--;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _TRANSCODE_H_INCLUDED_
|
||||
#define _TRANSCODE_H_INCLUDED_
|
||||
/* @(#$Id: transcode.h,v 1.3 2006-01-30 11:15:28 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: transcode.h,v 1.4 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/**
|
||||
* A very minimal c++ized interface to iconv
|
||||
*/
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
extern bool transcode(const std::string &in, std::string &out,
|
||||
const std::string &icode,
|
||||
const std::string &ocode);
|
||||
const std::string &ocode,
|
||||
int *ecnt = 0);
|
||||
|
||||
#endif /* _TRANSCODE_H_INCLUDED_ */
|
||||
|
||||
Reference in New Issue
Block a user