[Groonga-commit] groonga/groonga [master] Added grn_output_void().

Back to archive index

null+****@clear***** null+****@clear*****
2010年 6月 24日 (木) 12:03:36 JST


Daijiro MORI	2010-06-24 03:03:36 +0000 (Thu, 24 Jun 2010)

  New Revision: efa0a0dc4a00ac5005542c307fd68e4bd6f0c24e

  Log:
    Added grn_output_void().

  Modified files:
    lib/db.c
    lib/output.c
    test/unit/util/test-string.c

  Modified: lib/db.c (+1 -1)
===================================================================
--- lib/db.c    2010-06-24 02:11:13 +0000 (f1358e5)
+++ lib/db.c    2010-06-24 03:03:36 +0000 (63d34be)
@@ -7323,7 +7323,7 @@ json_read(grn_ctx *ctx, grn_loader *loader, const char *str, unsigned str_len)
         case 'n' :
           if (GRN_TEXT_LEN(loader->last) == 4 && !memcmp(v, "null", 4)) {
             loader->last->header.domain = GRN_DB_VOID;
-            GRN_BULK_REWIND(loader->last);
+            GRN_UINT32_SET(ctx, loader->last, GRN_ID_NIL);
           }
           break;
         case 't' :

  Modified: lib/output.c (+29 -0)
===================================================================
--- lib/output.c    2010-06-24 02:11:13 +0000 (21e0da5)
+++ lib/output.c    2010-06-24 03:03:36 +0000 (b2175e2)
@@ -338,6 +338,33 @@ grn_output_bool(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, cha
 }
 
 void
+grn_output_void(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
+                const char *value, size_t value_len)
+{
+  if (value_len == sizeof(grn_id) && *(grn_id *)value == GRN_ID_NIL) {
+    put_delimiter(ctx, outbuf, output_type);
+    switch (output_type) {
+    case GRN_CONTENT_JSON:
+      GRN_TEXT_PUTS(ctx, outbuf, "null");
+      break;
+    case GRN_CONTENT_TSV:
+      break;
+    case GRN_CONTENT_XML:
+      GRN_TEXT_PUTS(ctx, outbuf, "<NULL/>");
+      break;
+    case GRN_CONTENT_MSGPACK :
+      // todo
+      break;
+    case GRN_CONTENT_NONE:
+      break;
+    }
+    INCR_LENGTH;
+  } else {
+    grn_output_str(ctx, outbuf, output_type, value, value_len);
+  }
+}
+
+void
 grn_output_time(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, int64_t value)
 {
   double dv = value;
@@ -568,6 +595,8 @@ grn_output_obj(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
   case GRN_BULK :
     switch (obj->header.domain) {
     case GRN_DB_VOID :
+      grn_output_void(ctx, outbuf, output_type, GRN_BULK_HEAD(obj), GRN_BULK_VSIZE(obj));
+      break;
     case GRN_DB_SHORT_TEXT :
     case GRN_DB_TEXT :
     case GRN_DB_LONG_TEXT :

  Modified: test/unit/util/test-string.c (+1 -1)
===================================================================
--- test/unit/util/test-string.c    2010-06-24 02:11:13 +0000 (83c77d8)
+++ test/unit/util/test-string.c    2010-06-24 03:03:36 +0000 (4106735)
@@ -483,7 +483,7 @@ data_text_otoj(void)
                  "type", G_TYPE_INT, type,                      \
                  __VA_ARGS__);
 
-  ADD_DATUM("Void", "null", GRN_DB_VOID, NULL);
+  ADD_DATUM("Void", "", GRN_DB_VOID, NULL);
   ADD_DATUM("Bool", "true", GRN_DB_BOOL,
             "value", G_TYPE_BOOLEAN, TRUE,
             NULL);




Groonga-commit メーリングリストの案内
Back to archive index