Kouhei Sutou
null+****@clear*****
Tue Jul 5 20:20:11 JST 2016
Kouhei Sutou 2016-07-05 20:20:11 +0900 (Tue, 05 Jul 2016) New Revision: 7bd6c3f2705b9e0680f87b98373bf9ee7a264a6b https://github.com/groonga/groonga/commit/7bd6c3f2705b9e0680f87b98373bf9ee7a264a6b Message: string_substring: support too large from Added files: test/command/suite/select/function/string/string_substring/from_large.expected test/command/suite/select/function/string/string_substring/from_large.test Modified files: plugins/functions/string.c Modified: plugins/functions/string.c (+10 -6) =================================================================== --- plugins/functions/string.c 2016-07-05 20:18:08 +0900 (9d2b90b) +++ plugins/functions/string.c 2016-07-05 20:20:11 +0900 (b1d11ca) @@ -90,8 +90,8 @@ func_string_substring(grn_ctx *ctx, int n_args, grn_obj **args, size_t string_length = 0; int64_t from = 0; int64_t length = -1; - const char *start; - const char *end; + const char *start = NULL; + const char *end = NULL; grn_obj *substring; if (n_args < 2) { @@ -231,9 +231,11 @@ func_string_substring(grn_ctx *ctx, int n_args, grn_obj **args, { const char *p; unsigned int cl = 0; - start = GRN_TEXT_VALUE(target); - end = start + GRN_TEXT_LEN(target); - for (p = start; p < end && (cl = grn_charlen(ctx, p, end)); p += cl) { + start = NULL; + end = GRN_TEXT_VALUE(target) + GRN_TEXT_LEN(target); + for (p = GRN_TEXT_VALUE(target); + p < end && (cl = grn_charlen(ctx, p, end)); + p += cl) { if (string_length == from) { start = p; } @@ -245,7 +247,9 @@ func_string_substring(grn_ctx *ctx, int n_args, grn_obj **args, } } - GRN_TEXT_SET(ctx, substring, start, end - start); + if (start) { + GRN_TEXT_SET(ctx, substring, start, end - start); + } return substring; } Added: test/command/suite/select/function/string/string_substring/from_large.expected (+38 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/string/string_substring/from_large.expected 2016-07-05 20:20:11 +0900 (1c93306) @@ -0,0 +1,38 @@ +plugin_register functions/string +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga"} +] +[[0,0.0,0.0],1] +select Memos --output_columns '_key, string_substring(_key, 10)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "string_substring", + null + ] + ], + [ + "Groonga", + "" + ] + ] + ] +] Added: test/command/suite/select/function/string/string_substring/from_large.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/string/string_substring/from_large.test 2016-07-05 20:20:11 +0900 (bbc215d) @@ -0,0 +1,11 @@ +plugin_register functions/string + +table_create Memos TABLE_HASH_KEY ShortText + +load --table Memos +[ +{"_key": "Groonga"} +] + +select Memos \ + --output_columns '_key, string_substring(_key, 10)' -------------- next part -------------- HTML����������������������������... 下载