2020-08-08 18:55:14 +00:00
|
|
|
#include <Parsers/formatSettingName.h>
|
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
#include <Common/quoteString.h>
|
|
|
|
#include <common/find_symbols.h>
|
2020-09-17 22:45:12 +00:00
|
|
|
#include <ostream>
|
2020-08-08 18:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
void formatSettingName(const String & setting_name, std::ostream & out)
|
|
|
|
{
|
|
|
|
if (isValidIdentifier(setting_name))
|
|
|
|
{
|
|
|
|
out << setting_name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string_view> parts;
|
|
|
|
splitInto<'.'>(parts, setting_name);
|
|
|
|
bool all_parts_are_identifiers = std::all_of(parts.begin(), parts.end(), isValidIdentifier);
|
|
|
|
if (all_parts_are_identifiers && !parts.empty())
|
|
|
|
{
|
|
|
|
bool need_dot = false;
|
|
|
|
for (const auto & part : parts)
|
|
|
|
{
|
|
|
|
if (std::exchange(need_dot, true))
|
|
|
|
out << ".";
|
|
|
|
out << part;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out << backQuote(setting_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|