update code style.

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

View File

@ -6,13 +6,6 @@
namespace DB namespace DB
{ {
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
namespace
{
struct SoundexImpl struct SoundexImpl
{ {
@ -23,25 +16,29 @@ struct SoundexImpl
/* :::::::::::::::::::::::::: */ /* :::::::::::::::::::::::::: */
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,7 +47,10 @@ 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))
{ {
@ -58,16 +58,14 @@ struct SoundexImpl
} }
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>>();