2011-11-05 23:31:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2015-11-25 03:11:17 +00:00
|
|
|
#include <DB/IO/ReadHelpers.h>
|
2011-11-05 23:31:19 +00:00
|
|
|
|
|
|
|
|
2015-11-25 03:11:17 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2011-11-05 23:31:19 +00:00
|
|
|
inline std::string escapeForFileName(const std::string & s)
|
|
|
|
{
|
|
|
|
std::string res;
|
|
|
|
const char * pos = s.data();
|
|
|
|
const char * end = pos + s.size();
|
|
|
|
|
|
|
|
static const char * hex = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
while (pos != end)
|
|
|
|
{
|
|
|
|
char c = *pos;
|
|
|
|
|
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_'))
|
|
|
|
res += c;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res += '%';
|
|
|
|
res += hex[c / 16];
|
|
|
|
res += hex[c % 16];
|
|
|
|
}
|
|
|
|
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2013-04-15 00:42:29 +00:00
|
|
|
|
2013-04-18 11:49:46 +00:00
|
|
|
|
2013-04-15 10:10:55 +00:00
|
|
|
inline std::string unescapeForFileName(const std::string & s)
|
2013-04-15 00:42:29 +00:00
|
|
|
{
|
|
|
|
std::string res;
|
|
|
|
const char * pos = s.data();
|
|
|
|
const char * end = pos + s.size();
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-15 00:42:29 +00:00
|
|
|
while (pos != end)
|
|
|
|
{
|
2013-04-18 12:21:54 +00:00
|
|
|
if (*pos != '%')
|
|
|
|
res += *pos;
|
2013-04-15 00:42:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/// пропустим '%'
|
|
|
|
if (++pos == end) break;
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-18 12:21:54 +00:00
|
|
|
char val = unhex(*pos) * 16;
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-15 00:42:29 +00:00
|
|
|
if (++pos == end) break;
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-18 12:21:54 +00:00
|
|
|
val += unhex(*pos);
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-18 12:21:54 +00:00
|
|
|
res += val;
|
2013-04-15 00:42:29 +00:00
|
|
|
}
|
2015-11-25 03:11:17 +00:00
|
|
|
|
2013-04-15 00:42:29 +00:00
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2015-11-25 03:11:17 +00:00
|
|
|
|
|
|
|
}
|