mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
69 lines
911 B
C++
69 lines
911 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <DB/IO/ReadHelpers.h>
|
|
#include <DB/Common/StringUtils.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
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 (isWordCharASCII(c))
|
|
res += c;
|
|
else
|
|
{
|
|
res += '%';
|
|
res += hex[c / 16];
|
|
res += hex[c % 16];
|
|
}
|
|
|
|
++pos;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
|
|
inline std::string unescapeForFileName(const std::string & s)
|
|
{
|
|
std::string res;
|
|
const char * pos = s.data();
|
|
const char * end = pos + s.size();
|
|
|
|
while (pos != end)
|
|
{
|
|
if (*pos != '%')
|
|
res += *pos;
|
|
else
|
|
{
|
|
/// пропустим '%'
|
|
if (++pos == end) break;
|
|
|
|
char val = unhex(*pos) * 16;
|
|
|
|
if (++pos == end) break;
|
|
|
|
val += unhex(*pos);
|
|
|
|
res += val;
|
|
}
|
|
|
|
++pos;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
}
|