[Groonga-commit] groonga/groonga at 8618ee6 [master] snippet_full: move option position to end of arguments

Back to archive index

naoa null+****@clear*****
Thu Feb 18 23:59:22 JST 2016


naoa	2016-02-18 23:59:22 +0900 (Thu, 18 Feb 2016)

  New Revision: 8618ee6be73c9f79eec4b129593ed07f7332635a
  https://github.com/groonga/groonga/commit/8618ee6be73c9f79eec4b129593ed07f7332635a

  Merged af81362: Merge pull request #483 from naoa/remove-needless

  Message:
    snippet_full: move option position to end of arguments

  Modified files:
    lib/proc/proc_snippet.c
    test/command/suite/select/function/snippet_full/default_tag.expected
    test/command/suite/select/function/snippet_full/default_tag.test
    test/command/suite/select/function/snippet_full/empty_option.expected
    test/command/suite/select/function/snippet_full/empty_option.test
    test/command/suite/select/function/snippet_full/html_escape.expected
    test/command/suite/select/function/snippet_full/html_escape.test
    test/command/suite/select/function/snippet_full/leading_space.expected
    test/command/suite/select/function/snippet_full/leading_space.test
    test/command/suite/select/function/snippet_full/max_results.expected
    test/command/suite/select/function/snippet_full/max_results.test
    test/command/suite/select/function/snippet_full/normalizer.expected
    test/command/suite/select/function/snippet_full/normalizer.test
    test/command/suite/select/function/snippet_full/prefix.expected
    test/command/suite/select/function/snippet_full/prefix.test
    test/command/suite/select/function/snippet_full/suffix.expected
    test/command/suite/select/function/snippet_full/suffix.test
    test/command/suite/select/function/snippet_full/twice_keyword.expected
    test/command/suite/select/function/snippet_full/twice_keyword.test

  Modified: lib/proc/proc_snippet.c (+14 -13)
===================================================================
--- lib/proc/proc_snippet.c    2016-02-18 20:13:43 +0900 (a3cfbf7)
+++ lib/proc/proc_snippet.c    2016-02-18 23:59:22 +0900 (5774e0d)
@@ -149,12 +149,12 @@ static grn_obj *
 func_snippet_full(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
   grn_obj *snippets = NULL;
-  int n_required_args = 2;
 
+#define N_REQUIRED_ARGS 1
 #define KEYWORD_SET_SIZE 3
-  if (nargs >= n_required_args) {
+  if (nargs > N_REQUIRED_ARGS) {
     grn_obj *text = args[0];
-    grn_obj *hash_args_ptr = args[1];
+    grn_obj *end_arg = args[nargs - 1];
     grn_obj *expression = NULL;
     grn_obj *snip = NULL;
     grn_obj *snip_ptr;
@@ -172,22 +172,22 @@ func_snippet_full(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
     int default_open_tag_length = 0;
     const char *default_close_tag = NULL;
     int default_close_tag_length = 0;
+    int n_args_without_option = nargs;
 
-    if (hash_args_ptr->header.type != GRN_PTR) {
-      n_required_args--;
-    } else {
+    if (end_arg->header.type == GRN_PTR) {
       grn_obj *hash;
-      hash = GRN_PTR_VALUE(hash_args_ptr);
+      hash = GRN_PTR_VALUE(end_arg);
       if (hash) {
         grn_hash_cursor *cursor;
         void *key, *value;
         int key_size;
         if (hash->header.type != GRN_TABLE_HASH_KEY) {
           GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
-                           "snippet_full(): 2nd argument must be object literal: <%.*s>",
-                           (int)GRN_TEXT_LEN(args[1]), GRN_TEXT_VALUE(args[1]));
+                           "snippet_full(): end argument must be object literal: <%.*s>",
+                           (int)GRN_TEXT_LEN(args[nargs - 1]), GRN_TEXT_VALUE(args[nargs - 1]));
           goto exit;
         }
+        n_args_without_option--;
 
         if (!(cursor = grn_hash_cursor_open(ctx, (grn_hash *)hash, NULL, 0, NULL, 0, 0, -1, 0))) {
           GRN_PLUGIN_ERROR(ctx, GRN_NO_MEMORY_AVAILABLE,
@@ -275,8 +275,8 @@ func_snippet_full(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
           grn_obj_unlink(ctx, normalizer);
         }
         if (!default_open_tag_length && !default_close_tag_length) {
-          unsigned int n_keyword_sets = (nargs - n_required_args) / KEYWORD_SET_SIZE;
-          grn_obj **keyword_set_args = args + n_required_args;
+          unsigned int n_keyword_sets = (n_args_without_option - N_REQUIRED_ARGS) / KEYWORD_SET_SIZE;
+          grn_obj **keyword_set_args = args + N_REQUIRED_ARGS;
           for (i = 0; i < n_keyword_sets; i++) {
             rc = grn_snip_add_cond(ctx, snip,
                                    GRN_TEXT_VALUE(keyword_set_args[i * KEYWORD_SET_SIZE]),
@@ -287,8 +287,8 @@ func_snippet_full(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
                                    GRN_TEXT_LEN(keyword_set_args[i * KEYWORD_SET_SIZE + 2]));
           }
         } else {
-          unsigned int n_keywords = nargs - n_required_args;
-          grn_obj **keyword_args = args + n_required_args;
+          unsigned int n_keywords = n_args_without_option - N_REQUIRED_ARGS;
+          grn_obj **keyword_args = args + N_REQUIRED_ARGS;
           for (i = 0; i < n_keywords; i++) {
             rc = grn_snip_add_cond(ctx, snip,
                                    GRN_TEXT_VALUE(keyword_args[i]),
@@ -307,6 +307,7 @@ func_snippet_full(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d
     }
   }
 #undef KEYWORD_SET_SIZE
+#undef N_REQUIRED_ARGS
 
 exit :
   if (!snippets) {

  Modified: test/command/suite/select/function/snippet_full/default_tag.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/default_tag.expected    2016-02-18 20:13:43 +0900 (1f1d883)
+++ test/command/suite/select/function/snippet_full/default_tag.expected    2016-02-18 23:59:22 +0900 (3d695ce)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "<p>groonga and MySQL</p>"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"default_open_tag": "<span>", "default_close_tag": "</span>"},   "Groonga", "MySQL"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "Groonga", "MySQL",   {"default_open_tag": "<span>", "default_close_tag": "</span>"}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/default_tag.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/default_tag.test    2016-02-18 20:13:43 +0900 (de75b85)
+++ test/command/suite/select/function/snippet_full/default_tag.test    2016-02-18 23:59:22 +0900 (8d04e55)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"default_open_tag": "<span>", "default_close_tag": "</span>"}, \
-  "Groonga", "MySQL" \
+  snippet_full(content, \
+  "Groonga", "MySQL", \
+  {"default_open_tag": "<span>", "default_close_tag": "</span>"} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/empty_option.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/empty_option.expected    2016-02-18 20:13:43 +0900 (e6cafad)
+++ test/command/suite/select/function/snippet_full/empty_option.expected    2016-02-18 23:59:22 +0900 (72d7e9a)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "<p>groonga and MySQL</p>"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {},   "Groonga", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "Groonga", "<span class=\\"keyword\\">", "</span>",   {}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/empty_option.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/empty_option.test    2016-02-18 20:13:43 +0900 (023e41b)
+++ test/command/suite/select/function/snippet_full/empty_option.test    2016-02-18 23:59:22 +0900 (7f2c383)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {}, \
-  "Groonga", "<span class=\\"keyword\\">", "</span>" \
+  snippet_full(content, \
+  "Groonga", "<span class=\\"keyword\\">", "</span>", \
+  {} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/html_escape.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/html_escape.expected    2016-02-18 20:13:43 +0900 (d85b461)
+++ test/command/suite/select/function/snippet_full/html_escape.expected    2016-02-18 23:59:22 +0900 (ce6fe9f)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "<p>groonga and MySQL</p>"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"html_escape": true},   "groonga", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "groonga", "<span class=\\"keyword\\">", "</span>",   {"html_escape": true})'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/html_escape.test (+3 -3)
===================================================================
--- test/command/suite/select/function/snippet_full/html_escape.test    2016-02-18 20:13:43 +0900 (710f75b)
+++ test/command/suite/select/function/snippet_full/html_escape.test    2016-02-18 23:59:22 +0900 (3e48d46)
@@ -8,7 +8,7 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"html_escape": true}, \
-  "groonga", "<span class=\\"keyword\\">", "</span>" \
-  )' \
+  snippet_full(content, \
+  "groonga", "<span class=\\"keyword\\">", "</span>", \
+  {"html_escape": true})' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/leading_space.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/leading_space.expected    2016-02-18 20:13:43 +0900 (772d836)
+++ test/command/suite/select/function/snippet_full/leading_space.expected    2016-02-18 23:59:22 +0900 (7ee2279)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"skip_leading_spaces": false},   "MySQL", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "MySQL", "<span class=\\"keyword\\">", "</span>",   {"skip_leading_spaces": false}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/leading_space.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/leading_space.test    2016-02-18 20:13:43 +0900 (40ef33a)
+++ test/command/suite/select/function/snippet_full/leading_space.test    2016-02-18 23:59:22 +0900 (a957d8b)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"skip_leading_spaces": false}, \
-  "MySQL", "<span class=\\"keyword\\">", "</span>" \
+  snippet_full(content, \
+  "MySQL", "<span class=\\"keyword\\">", "</span>", \
+  {"skip_leading_spaces": false} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/max_results.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/max_results.expected    2016-02-18 20:13:43 +0900 (006689c)
+++ test/command/suite/select/function/snippet_full/max_results.expected    2016-02-18 23:59:22 +0900 (58c32a2)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL and PosrgreSQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"width": 10, "max_n_results": 2},   "SQL", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "SQL", "<span class=\\"keyword\\">", "</span>",   {"width": 10, "max_n_results": 2}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/max_results.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/max_results.test    2016-02-18 20:13:43 +0900 (9f52068)
+++ test/command/suite/select/function/snippet_full/max_results.test    2016-02-18 23:59:22 +0900 (c43d12e)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"width": 10, "max_n_results": 2}, \
-  "SQL", "<span class=\\"keyword\\">", "</span>" \
+  snippet_full(content, \
+  "SQL", "<span class=\\"keyword\\">", "</span>", \
+  {"width": 10, "max_n_results": 2} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/normalizer.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/normalizer.expected    2016-02-18 20:13:43 +0900 (41602f7)
+++ test/command/suite/select/function/snippet_full/normalizer.expected    2016-02-18 23:59:22 +0900 (8e3b069)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL and PosrgreSQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"normalizer": "NormalizerAuto"},   "sql", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "sql", "<span class=\\"keyword\\">", "</span>",   {"normalizer": "NormalizerAuto"}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/normalizer.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/normalizer.test    2016-02-18 20:13:43 +0900 (c8c8f93)
+++ test/command/suite/select/function/snippet_full/normalizer.test    2016-02-18 23:59:22 +0900 (6c71c41)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"normalizer": "NormalizerAuto"}, \
-  "sql", "<span class=\\"keyword\\">", "</span>" \
+  snippet_full(content, \
+  "sql", "<span class=\\"keyword\\">", "</span>", \
+  {"normalizer": "NormalizerAuto"} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/prefix.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/prefix.expected    2016-02-18 20:13:43 +0900 (94bb678)
+++ test/command/suite/select/function/snippet_full/prefix.expected    2016-02-18 23:59:22 +0900 (c7ffe62)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL and PosrgreSQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"prefix": "..."},   "SQL", "<span class=\\"w1\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "SQL", "<span class=\\"w1\\">", "</span>",   {"prefix": "..."}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/prefix.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/prefix.test    2016-02-18 20:13:43 +0900 (5792b33)
+++ test/command/suite/select/function/snippet_full/prefix.test    2016-02-18 23:59:22 +0900 (0867ef5)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"prefix": "..."}, \
-  "SQL", "<span class=\\"w1\\">", "</span>" \
+  snippet_full(content, \
+  "SQL", "<span class=\\"w1\\">", "</span>", \
+  {"prefix": "..."} \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/suffix.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/suffix.expected    2016-02-18 20:13:43 +0900 (b3fbf7b)
+++ test/command/suite/select/function/snippet_full/suffix.expected    2016-02-18 23:59:22 +0900 (4e60a10)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL and PosrgreSQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"suffix": "..."},   "SQL", "<span class=\\"keyword\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "SQL", "<span class=\\"keyword\\">", "</span>",   {"suffix": "..."}    )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/suffix.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/suffix.test    2016-02-18 20:13:43 +0900 (fecc16c)
+++ test/command/suite/select/function/snippet_full/suffix.test    2016-02-18 23:59:22 +0900 (9ae101a)
@@ -8,7 +8,8 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"suffix": "..."}, \
-  "SQL", "<span class=\\"keyword\\">", "</span>" \
+  snippet_full(content, \
+  "SQL", "<span class=\\"keyword\\">", "</span>", \
+  {"suffix": "..."}  \
   )' \
   --command_version 2

  Modified: test/command/suite/select/function/snippet_full/twice_keyword.expected (+1 -1)
===================================================================
--- test/command/suite/select/function/snippet_full/twice_keyword.expected    2016-02-18 20:13:43 +0900 (cce84de)
+++ test/command/suite/select/function/snippet_full/twice_keyword.expected    2016-02-18 23:59:22 +0900 (92e4b0b)
@@ -7,7 +7,7 @@ load --table Entries
 {"content": "groonga and MySQL and PosrgreSQL"}
 ]
 [[0,0.0,0.0],1]
-select Entries   --output_columns '   snippet_full(content, {"prefix": "..."},   "SQL", "<span class=\\"keyword1\\">", "</span>",   "groonga", "<span class=\\"keyword2\\">", "</span>"   )'   --command_version 2
+select Entries   --output_columns '   snippet_full(content,   "SQL", "<span class=\\"keyword1\\">", "</span>",   "groonga", "<span class=\\"keyword2\\">", "</span>",   {"prefix": "..."}   )'   --command_version 2
 [
   [
     0,

  Modified: test/command/suite/select/function/snippet_full/twice_keyword.test (+3 -2)
===================================================================
--- test/command/suite/select/function/snippet_full/twice_keyword.test    2016-02-18 20:13:43 +0900 (4ccb4e0)
+++ test/command/suite/select/function/snippet_full/twice_keyword.test    2016-02-18 23:59:22 +0900 (73c0260)
@@ -8,8 +8,9 @@ load --table Entries
 
 select Entries \
   --output_columns ' \
-  snippet_full(content, {"prefix": "..."}, \
+  snippet_full(content, \
   "SQL", "<span class=\\"keyword1\\">", "</span>", \
-  "groonga", "<span class=\\"keyword2\\">", "</span>" \
+  "groonga", "<span class=\\"keyword2\\">", "</span>", \
+  {"prefix": "..."} \
   )' \
   --command_version 2
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index