[C] Refactoring

This commit is contained in:
seleznevae 2019-08-26 13:07:21 +03:00
parent 5e62cd959b
commit d2bed0fdf1
2 changed files with 44 additions and 16 deletions

View File

@ -5575,12 +5575,31 @@ clear:
} }
#endif #endif
FT_INTERNAL
fort_row_t *create_row_from_buffer(const string_buffer_t *buffer)
{
switch (buffer->type) {
case CHAR_BUF:
return create_row_from_string(buffer->str.cstr);
#ifdef FT_HAVE_WCHAR
case W_CHAR_BUF:
return create_row_from_wstring(buffer->str.wstr);
#endif /* FT_HAVE_WCHAR */
#ifdef FT_HAVE_UTF8
case UTF8_BUF:
return create_row_from_string(buffer->str.u8str);
#endif /* FT_HAVE_UTF8 */
default:
assert(0);
return NULL;
}
}
FT_INTERNAL FT_INTERNAL
fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args) fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
{ {
#define VSNPRINTF vsnprintf #define VSNPRINTF vsnprintf
#define STR_FILED cstr #define STR_FILED cstr
#define CREATE_ROW_FROM_STRING create_row_from_string
#define STR_BUF_TYPE CHAR_BUF #define STR_BUF_TYPE CHAR_BUF
string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE); string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE);
@ -5615,7 +5634,7 @@ fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
cols = number_of_columns_in_format_buffer(buffer); cols = number_of_columns_in_format_buffer(buffer);
if (cols == cols_origin) { if (cols == cols_origin) {
fort_row_t *row = CREATE_ROW_FROM_STRING(buffer->str.STR_FILED); fort_row_t *row = create_row_from_buffer(buffer);
if (row == NULL) { if (row == NULL) {
goto clear; goto clear;
} }
@ -5656,7 +5675,6 @@ clear:
return NULL; return NULL;
#undef VSNPRINTF #undef VSNPRINTF
#undef STR_FILED #undef STR_FILED
#undef CREATE_ROW_FROM_STRING
#undef STR_BUF_TYPE #undef STR_BUF_TYPE
} }
@ -5666,8 +5684,6 @@ fort_row_t *create_row_from_fmt_wstring(const wchar_t *fmt, va_list *va_args)
{ {
#define VSNPRINTF vswprintf #define VSNPRINTF vswprintf
#define STR_FILED wstr #define STR_FILED wstr
#define CREATE_ROW_FROM_STRING create_row_from_wstring
#define NUMBER_OF_COLUMNS_IN_FORMAT_STRING number_of_columns_in_format_wstring
#define STR_BUF_TYPE W_CHAR_BUF #define STR_BUF_TYPE W_CHAR_BUF
string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE); string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE);
@ -5703,7 +5719,7 @@ fort_row_t *create_row_from_fmt_wstring(const wchar_t *fmt, va_list *va_args)
cols = number_of_columns_in_format_buffer(buffer); cols = number_of_columns_in_format_buffer(buffer);
if (cols == cols_origin) { if (cols == cols_origin) {
fort_row_t *row = CREATE_ROW_FROM_STRING(buffer->str.STR_FILED); fort_row_t *row = create_row_from_buffer(buffer);
if (row == NULL) { if (row == NULL) {
goto clear; goto clear;
} }
@ -5744,8 +5760,6 @@ clear:
return NULL; return NULL;
#undef VSNPRINTF #undef VSNPRINTF
#undef STR_FILED #undef STR_FILED
#undef CREATE_ROW_FROM_STRING
#undef NUMBER_OF_COLUMNS_IN_FORMAT_STRING
#undef STR_BUF_TYPE #undef STR_BUF_TYPE
} }
#endif #endif

View File

@ -595,12 +595,31 @@ clear:
} }
#endif #endif
FT_INTERNAL
fort_row_t *create_row_from_buffer(const string_buffer_t *buffer)
{
switch (buffer->type) {
case CHAR_BUF:
return create_row_from_string(buffer->str.cstr);
#ifdef FT_HAVE_WCHAR
case W_CHAR_BUF:
return create_row_from_wstring(buffer->str.wstr);
#endif /* FT_HAVE_WCHAR */
#ifdef FT_HAVE_UTF8
case UTF8_BUF:
return create_row_from_string(buffer->str.u8str);
#endif /* FT_HAVE_UTF8 */
default:
assert(0);
return NULL;
}
}
FT_INTERNAL FT_INTERNAL
fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args) fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
{ {
#define VSNPRINTF vsnprintf #define VSNPRINTF vsnprintf
#define STR_FILED cstr #define STR_FILED cstr
#define CREATE_ROW_FROM_STRING create_row_from_string
#define STR_BUF_TYPE CHAR_BUF #define STR_BUF_TYPE CHAR_BUF
string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE); string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE);
@ -635,7 +654,7 @@ fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
cols = number_of_columns_in_format_buffer(buffer); cols = number_of_columns_in_format_buffer(buffer);
if (cols == cols_origin) { if (cols == cols_origin) {
fort_row_t *row = CREATE_ROW_FROM_STRING(buffer->str.STR_FILED); fort_row_t *row = create_row_from_buffer(buffer);
if (row == NULL) { if (row == NULL) {
goto clear; goto clear;
} }
@ -676,7 +695,6 @@ clear:
return NULL; return NULL;
#undef VSNPRINTF #undef VSNPRINTF
#undef STR_FILED #undef STR_FILED
#undef CREATE_ROW_FROM_STRING
#undef STR_BUF_TYPE #undef STR_BUF_TYPE
} }
@ -686,8 +704,6 @@ fort_row_t *create_row_from_fmt_wstring(const wchar_t *fmt, va_list *va_args)
{ {
#define VSNPRINTF vswprintf #define VSNPRINTF vswprintf
#define STR_FILED wstr #define STR_FILED wstr
#define CREATE_ROW_FROM_STRING create_row_from_wstring
#define NUMBER_OF_COLUMNS_IN_FORMAT_STRING number_of_columns_in_format_wstring
#define STR_BUF_TYPE W_CHAR_BUF #define STR_BUF_TYPE W_CHAR_BUF
string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE); string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, STR_BUF_TYPE);
@ -723,7 +739,7 @@ fort_row_t *create_row_from_fmt_wstring(const wchar_t *fmt, va_list *va_args)
cols = number_of_columns_in_format_buffer(buffer); cols = number_of_columns_in_format_buffer(buffer);
if (cols == cols_origin) { if (cols == cols_origin) {
fort_row_t *row = CREATE_ROW_FROM_STRING(buffer->str.STR_FILED); fort_row_t *row = create_row_from_buffer(buffer);
if (row == NULL) { if (row == NULL) {
goto clear; goto clear;
} }
@ -764,8 +780,6 @@ clear:
return NULL; return NULL;
#undef VSNPRINTF #undef VSNPRINTF
#undef STR_FILED #undef STR_FILED
#undef CREATE_ROW_FROM_STRING
#undef NUMBER_OF_COLUMNS_IN_FORMAT_STRING
#undef STR_BUF_TYPE #undef STR_BUF_TYPE
} }
#endif #endif