Skip to content

Commit

Permalink
Unify common feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 30, 2018
1 parent 48eb1f2 commit e584a8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
4 changes: 4 additions & 0 deletions lib/grn_proc.h
Expand Up @@ -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
20 changes: 1 addition & 19 deletions lib/proc/proc_dump.c
Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions lib/proc/proc_schema.c
Expand Up @@ -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 ' ' :
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e584a8b

Please sign in to comment.