update code style.

This commit is contained in:
FriendLey 2023-04-09 17:24:54 +08:00
parent 47fd6b6650
commit fe21f301f0

View File

@ -6,43 +6,40 @@
namespace DB namespace DB
{ {
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
namespace
{
struct SoundexImpl struct SoundexImpl
{ {
static constexpr auto name = "soundex"; static constexpr auto name = "soundex";
static constexpr size_t length = 4; static constexpr size_t length = 4;
// enum { length = 4 }; // enum { length = 4 };
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */ /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
/* :::::::::::::::::::::::::: */ /* :::::::::::::::::::::::::: */
static constexpr auto soundex_map = "01230120022455012623010202"; static constexpr auto soundex_map = "01230120022455012623010202";
static char get_scode(const char **ptr, const char *in_end) { static char get_scode(const char ** ptr, const char * in_end)
while (*ptr < in_end && !std::isalpha(**ptr)) { {
while (*ptr < in_end && !std::isalpha(**ptr))
{
(*ptr)++; (*ptr)++;
} }
if (*ptr == in_end) return 0; if (*ptr == in_end)
return 0;
return soundex_map[std::toupper(**ptr) - 'A']; return soundex_map[std::toupper(**ptr) - 'A'];
} }
static void apply(const char* begin, const size_t size, unsigned char * out_char_data) static void apply(const char * begin, const size_t size, unsigned char * out_char_data)
{ {
const char * in_cur = begin;
const char* in_cur = begin; const char * in_end = begin + size;
const char* in_end = begin + size;
unsigned char * out_end = out_char_data + length; unsigned char * out_end = out_char_data + length;
while (in_cur < in_end && !std::isalpha(*in_cur)) { while (in_cur < in_end && !std::isalpha(*in_cur))
{
in_cur++; in_cur++;
} }
if (in_cur < in_end) { if (in_cur < in_end)
*out_char_data++ = std::toupper(*in_cur); {
*out_char_data++ = std::toupper(*in_cur);
} }
char last_ch = get_scode(&in_cur, in_end); char last_ch = get_scode(&in_cur, in_end);
@ -50,24 +47,25 @@ struct SoundexImpl
in_cur++; in_cur++;
while (in_cur < in_end && out_char_data < out_end && (ch = get_scode(&in_cur, in_end)) != 0) while (in_cur < in_end && out_char_data < out_end && (ch = get_scode(&in_cur, in_end)) != 0)
{ {
if (in_cur == in_end) break; if (in_cur == in_end)
{
break;
}
in_cur++; in_cur++;
if ((ch != '0') && (ch != last_ch)) if ((ch != '0') && (ch != last_ch))
{ {
*out_char_data++ = ch; *out_char_data++ = ch;
} }
last_ch = ch; last_ch = ch;
} }
while (out_char_data < out_end) { while (out_char_data < out_end)
*out_char_data++ = '0'; {
*out_char_data++ = '0';
} }
return; return;
} }
}; };
}
REGISTER_FUNCTION(Soundex) REGISTER_FUNCTION(Soundex)
{ {
factory.registerFunction<FunctionStringHashFixedString<SoundexImpl>>(); factory.registerFunction<FunctionStringHashFixedString<SoundexImpl>>();