[Groonga-commit] groonga/groonga at 65b989f [master] Export grn_token_cursor

アーカイブの一覧に戻る
Kouhei Sutou null+****@clear*****
Thu Nov 8 17:45:58 JST 2018


Kouhei Sutou	2018-11-08 17:45:58 +0900 (Thu, 08 Nov 2018)

  Revision: 65b989fe015a6800abbaef35745c1eed502ca513
  https://github.com/groonga/groonga/commit/65b989fe015a6800abbaef35745c1eed502ca513

  Message:
    Export grn_token_cursor

  Copied files:
    include/groonga/token_cursor.h
      (from lib/grn_token_cursor.h)
  Modified files:
    include/groonga.h
    include/groonga/Makefile.am
    lib/grn_token_cursor.h
    lib/token_cursor.c

  Modified: include/groonga.h (+1 -0)
===================================================================
--- include/groonga.h    2018-11-08 12:35:26 +0900 (b465d6910)
+++ include/groonga.h    2018-11-08 17:45:58 +0900 (d44ca02dd)
@@ -52,6 +52,7 @@
 #include "groonga/thread.h"
 #include "groonga/time.h"
 #include "groonga/token.h"
+#include "groonga/token_cursor.h"
 #include "groonga/token_metadata.h"
 #include "groonga/type.h"
 #include "groonga/util.h"

  Modified: include/groonga/Makefile.am (+1 -0)
===================================================================
--- include/groonga/Makefile.am    2018-11-08 12:35:26 +0900 (adbecf008)
+++ include/groonga/Makefile.am    2018-11-08 17:45:58 +0900 (75e5cadf8)
@@ -37,6 +37,7 @@ groonga_include_HEADERS =			\
 	thread.h				\
 	time.h					\
 	token.h					\
+	token_cursor.h				\
 	token_filter.h				\
 	token_metadata.h			\
 	tokenizer.h				\

  Copied: include/groonga/token_cursor.h (+18 -38) 50%
===================================================================
--- lib/grn_token_cursor.h    2018-11-08 12:35:26 +0900 (ee0fe700e)
+++ include/groonga/token_cursor.h    2018-11-08 17:45:58 +0900 (44db4f345)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2016 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -18,11 +19,6 @@
 
 #pragma once
 
-#include "grn_ctx.h"
-#include "grn_token.h"
-#include "grn_tokenizer.h"
-#include "grn_db.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -34,42 +30,26 @@ typedef enum {
   GRN_TOKEN_CURSOR_NOT_FOUND
 } grn_token_cursor_status;
 
-typedef struct {
-  grn_obj *table;
-  const unsigned char *orig;
-  const unsigned char *curr;
-  uint32_t orig_blen;
-  uint32_t curr_size;
-  int32_t pos;
-  grn_tokenize_mode mode;
-  grn_token_cursor_status status;
-  grn_bool force_prefix;
-  grn_obj_flags table_flags;
-  grn_encoding encoding;
-  struct {
-    grn_obj *object;
-    grn_proc_ctx pctx;
-    grn_tokenizer_query query;
-    void *user_data;
-    grn_token current_token;
-    grn_token next_token;
-  } tokenizer;
-  struct {
-    grn_obj *objects;
-    void **data;
-  } token_filter;
-  uint32_t variant;
-} grn_token_cursor;
-
 #define GRN_TOKEN_CURSOR_ENABLE_TOKENIZED_DELIMITER (0x01L<<0)
 
-GRN_API grn_token_cursor *grn_token_cursor_open(grn_ctx *ctx, grn_obj *table,
-                                                const char *str, size_t str_len,
-                                                grn_tokenize_mode mode,
-                                                unsigned int flags);
+typedef struct _grn_token_cursor grn_token_cursor;
+
+GRN_API grn_token_cursor *
+grn_token_cursor_open(grn_ctx *ctx,
+                      grn_obj *table,
+                      const char *str,
+                      size_t str_len,
+                      grn_tokenize_mode mode,
+                      unsigned int flags);
+
+GRN_API grn_id
+grn_token_cursor_next(grn_ctx *ctx, grn_token_cursor *token_cursor);
+
+GRN_API grn_token_cursor_status
+grn_token_cursor_get_status(grn_ctx *ctx, grn_token_cursor *token_cursor);
 
-GRN_API grn_id grn_token_cursor_next(grn_ctx *ctx, grn_token_cursor *token_cursor);
-GRN_API grn_rc grn_token_cursor_close(grn_ctx *ctx, grn_token_cursor *token_cursor);
+GRN_API grn_rc
+grn_token_cursor_close(grn_ctx *ctx, grn_token_cursor *token_cursor);
 
 GRN_API grn_token *
 grn_token_cursor_get_token(grn_ctx *ctx, grn_token_cursor *token_cursor);

  Modified: lib/grn_token_cursor.h (+2 -22)
===================================================================
--- lib/grn_token_cursor.h    2018-11-08 12:35:26 +0900 (ee0fe700e)
+++ lib/grn_token_cursor.h    2018-11-08 17:45:58 +0900 (c144939ae)
@@ -27,14 +27,7 @@
 extern "C" {
 #endif
 
-typedef enum {
-  GRN_TOKEN_CURSOR_DOING = 0,
-  GRN_TOKEN_CURSOR_DONE,
-  GRN_TOKEN_CURSOR_DONE_SKIP,
-  GRN_TOKEN_CURSOR_NOT_FOUND
-} grn_token_cursor_status;
-
-typedef struct {
+struct _grn_token_cursor {
   grn_obj *table;
   const unsigned char *orig;
   const unsigned char *curr;
@@ -59,20 +52,7 @@ typedef struct {
     void **data;
   } token_filter;
   uint32_t variant;
-} grn_token_cursor;
-
-#define GRN_TOKEN_CURSOR_ENABLE_TOKENIZED_DELIMITER (0x01L<<0)
-
-GRN_API grn_token_cursor *grn_token_cursor_open(grn_ctx *ctx, grn_obj *table,
-                                                const char *str, size_t str_len,
-                                                grn_tokenize_mode mode,
-                                                unsigned int flags);
-
-GRN_API grn_id grn_token_cursor_next(grn_ctx *ctx, grn_token_cursor *token_cursor);
-GRN_API grn_rc grn_token_cursor_close(grn_ctx *ctx, grn_token_cursor *token_cursor);
-
-GRN_API grn_token *
-grn_token_cursor_get_token(grn_ctx *ctx, grn_token_cursor *token_cursor);
+};
 
 #ifdef __cplusplus
 }

  Modified: lib/token_cursor.c (+44 -24)
===================================================================
--- lib/token_cursor.c    2018-11-08 12:35:26 +0900 (10d5f008a)
+++ lib/token_cursor.c    2018-11-08 17:45:58 +0900 (cd9de1bd2)
@@ -70,6 +70,8 @@ grn_token_cursor_open(grn_ctx *ctx, grn_obj *table,
                       const char *str, size_t str_len,
                       grn_tokenize_mode mode, unsigned int flags)
 {
+  GRN_API_ENTER;
+
   grn_token_cursor *token_cursor;
   grn_encoding encoding;
   grn_obj *tokenizer;
@@ -77,7 +79,9 @@ grn_token_cursor_open(grn_ctx *ctx, grn_obj *table,
   grn_table_flags table_flags;
   if (grn_table_get_info(ctx, table, &table_flags, &encoding, &tokenizer,
                          NULL, &token_filters)) {
-    return NULL;
+    ERR(GRN_INVALID_ARGUMENT,
+        "[token-cursor][open] failed to get table information");
+    GRN_API_RETURN(NULL);
   }
   if (!(token_cursor = GRN_MALLOC(sizeof(grn_token_cursor)))) { return NULL; }
   token_cursor->table = table;
@@ -161,7 +165,7 @@ exit :
     grn_token_cursor_close(ctx, token_cursor);
     token_cursor = NULL;
   }
-  return token_cursor;
+  GRN_API_RETURN(token_cursor);
 }
 
 static int
@@ -217,6 +221,8 @@ grn_token_cursor_next_apply_token_filters(grn_ctx *ctx,
 grn_id
 grn_token_cursor_next(grn_ctx *ctx, grn_token_cursor *token_cursor)
 {
+  GRN_API_ENTER;
+
   int status;
   grn_id tid = GRN_ID_NIL;
   grn_obj *table = token_cursor->table;
@@ -373,7 +379,19 @@ grn_token_cursor_next(grn_ctx *ctx, grn_token_cursor *token_cursor)
     token_cursor->pos++;
     break;
   }
-  return tid;
+  GRN_API_RETURN(tid);
+}
+
+grn_token_cursor_status
+grn_token_cursor_get_status(grn_ctx *ctx, grn_token_cursor *token_cursor)
+{
+  GRN_API_ENTER;
+  if (!token_cursor) {
+    ERR(GRN_INVALID_ARGUMENT,
+        "[token-cursor][status] token cursor must not NULL");
+    GRN_API_RETURN(GRN_TOKEN_CURSOR_DONE);
+  }
+  GRN_API_RETURN(token_cursor->status);
 }
 
 static void
@@ -412,32 +430,34 @@ grn_token_cursor_close_token_filters(grn_ctx *ctx,
 grn_rc
 grn_token_cursor_close(grn_ctx *ctx, grn_token_cursor *token_cursor)
 {
-  if (token_cursor) {
-    if (token_cursor->tokenizer.object) {
-      grn_proc *tokenizer_proc = (grn_proc *)(token_cursor->tokenizer.object);
-      if (tokenizer_proc->callbacks.tokenizer.fin) {
-        void *user_data = token_cursor->tokenizer.user_data;
-        tokenizer_proc->callbacks.tokenizer.fin(ctx, user_data);
-      } else if (tokenizer_proc->funcs[PROC_FIN]) {
-        tokenizer_proc->funcs[PROC_FIN](ctx,
-                                        1,
-                                        &token_cursor->table,
-                                        &token_cursor->tokenizer.pctx.user_data);
-      }
+  GRN_API_ENTER;
+  if (!token_cursor) {
+    GRN_API_RETURN(GRN_INVALID_ARGUMENT);
+  }
+
+  if (token_cursor->tokenizer.object) {
+    grn_proc *tokenizer_proc = (grn_proc *)(token_cursor->tokenizer.object);
+    if (tokenizer_proc->callbacks.tokenizer.fin) {
+      void *user_data = token_cursor->tokenizer.user_data;
+      tokenizer_proc->callbacks.tokenizer.fin(ctx, user_data);
+    } else if (tokenizer_proc->funcs[PROC_FIN]) {
+      tokenizer_proc->funcs[PROC_FIN](ctx,
+                                      1,
+                                      &token_cursor->table,
+                                      &token_cursor->tokenizer.pctx.user_data);
     }
-    grn_token_fin(ctx, &(token_cursor->tokenizer.current_token));
-    grn_token_fin(ctx, &(token_cursor->tokenizer.next_token));
-    grn_tokenizer_query_fin(ctx, &(token_cursor->tokenizer.query));
-    grn_token_cursor_close_token_filters(ctx, token_cursor);
-    GRN_FREE(token_cursor);
-    return GRN_SUCCESS;
-  } else {
-    return GRN_INVALID_ARGUMENT;
   }
+  grn_token_fin(ctx, &(token_cursor->tokenizer.current_token));
+  grn_token_fin(ctx, &(token_cursor->tokenizer.next_token));
+  grn_tokenizer_query_fin(ctx, &(token_cursor->tokenizer.query));
+  grn_token_cursor_close_token_filters(ctx, token_cursor);
+  GRN_FREE(token_cursor);
+  GRN_API_RETURN(GRN_SUCCESS);
 }
 
 grn_token *
 grn_token_cursor_get_token(grn_ctx *ctx, grn_token_cursor *token_cursor)
 {
-  return &(token_cursor->tokenizer.current_token);
+  GRN_API_ENTER;
+  GRN_API_RETURN(&(token_cursor->tokenizer.current_token));
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181108/8122d8f4/attachment-0001.html>


More information about the Groonga-commit mailing list
アーカイブの一覧に戻る