Kouhei Sutou 2018-10-30 16:08:16 +0900 (Tue, 30 Oct 2018) Revision: e584a8bd10c06cd597422446f83e896993f9c1fb https://github.com/groonga/groonga/commit/e584a8bd10c06cd597422446f83e896993f9c1fb Message: Unify common feature Modified files: lib/grn_proc.h lib/proc/proc_dump.c lib/proc/proc_schema.c Modified: lib/grn_proc.h (+4 -0) =================================================================== --- lib/grn_proc.h 2018-10-30 16:01:47 +0900 (fdb010069) +++ lib/grn_proc.h 2018-10-30 16:08:16 +0900 (3477d39b7) @@ -158,6 +158,10 @@ grn_obj *grn_proc_lexicon_open(grn_ctx *ctx, grn_raw_string *token_filters_raw, const char *context_tag); +grn_bool grn_proc_text_include_special_character(grn_ctx *ctx, + const char *text, + size_t size); + #ifdef __cplusplus } #endif Modified: lib/proc/proc_dump.c (+1 -19) =================================================================== --- lib/proc/proc_dump.c 2018-10-30 16:01:47 +0900 (3799b905d) +++ lib/proc/proc_dump.c 2018-10-30 16:08:16 +0900 (6886eae48) @@ -711,26 +711,8 @@ dump_optionable_obj_string(grn_ctx *ctx, { const char *value = GRN_TEXT_VALUE(string); size_t length = GRN_TEXT_LEN(string); - grn_bool need_quote = GRN_FALSE; - size_t i; - - for (i = 0; i < length; i++) { - switch (value[i]) { - case '(' : - case ')' : - case ',' : - case ' ' : - need_quote = GRN_TRUE; - break; - default : - break; - } - if (need_quote) { - break; - } - } - if (need_quote) { + if (grn_proc_text_include_special_character(ctx, value, length)) { grn_text_otoj(ctx, dumper->output, string, NULL); } else { GRN_TEXT_PUT(ctx, dumper->output, value, length); Modified: lib/proc/proc_schema.c (+8 -10) =================================================================== --- lib/proc/proc_schema.c 2018-10-30 16:01:47 +0900 (526d8959c) +++ lib/proc/proc_schema.c 2018-10-30 16:08:16 +0900 (4b29696bd) @@ -98,15 +98,15 @@ command_schema_output_value_type(grn_ctx *ctx, grn_obj *value_type) command_schema_output_type(ctx, "value_type", value_type); } -static grn_bool -command_schema_output_command_include_special_character(grn_ctx *ctx, - const char *value, - unsigned int size) +grn_bool +grn_proc_text_include_special_character(grn_ctx *ctx, + const char *text, + size_t size) { - const char *end = value + size; + const char *end = text + size; - for (; value < end; value++) { - switch (value[0]) { + for (; text < end; text++) { + switch (text[0]) { case '(' : case ')' : case ' ' : @@ -175,9 +175,7 @@ command_schema_output_command(grn_ctx *ctx, name_size, name); value_size = grn_vector_get_element(ctx, arguments, i + 1, &value, NULL, NULL); - if (command_schema_output_command_include_special_character(ctx, - value, - value_size)) { + if (grn_proc_text_include_special_character(ctx, value, value_size)) { grn_obj value_text; GRN_TEXT_INIT(&value_text, GRN_OBJ_DO_SHALLOW_COPY); GRN_TEXT_SET(ctx, &value_text, value, value_size); -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181030/e69bbe33/attachment-0001.html>