aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/formatSettingName.cpp
blob: efbfffddd7b3910e831b3cb86c2e9184cb6b80bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <Parsers/formatSettingName.h>
#include <Common/StringUtils/StringUtils.h>
#include <Common/quoteString.h>
#include <base/find_symbols.h>
#include <IO/Operators.h>


namespace DB
{

void formatSettingName(const String & setting_name, WriteBuffer & 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);
}

}