[Groonga-commit] groonga/groonga at 10a3836 [master] Export grn_inspect_limited()

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 3 11:03:13 JST 2017


Kouhei Sutou	2017-02-03 11:03:13 +0900 (Fri, 03 Feb 2017)

  New Revision: 10a38363665d4918877a24a88a6c007cde9b119c
  https://github.com/groonga/groonga/commit/10a38363665d4918877a24a88a6c007cde9b119c

  Message:
    Export grn_inspect_limited()

  Modified files:
    include/groonga/util.h
    lib/db.c
    lib/util.c

  Modified: include/groonga/util.h (+4 -1)
===================================================================
--- include/groonga/util.h    2017-02-03 10:56:48 +0900 (52997ea)
+++ include/groonga/util.h    2017-02-03 11:03:13 +0900 (9195df1)
@@ -1,5 +1,5 @@
 /*
-  Copyright(C) 2010-2016 Brazil
+  Copyright(C) 2010-2017 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,9 @@ extern "C" {
 GRN_API grn_obj *grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj);
 GRN_API grn_obj *grn_inspect_indented(grn_ctx *ctx, grn_obj *buffer,
                                       grn_obj *obj, const char *indent);
+GRN_API grn_obj *grn_inspect_limited(grn_ctx *ctx,
+                                     grn_obj *buffer,
+                                     grn_obj *obj);
 GRN_API grn_obj *grn_inspect_name(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj);
 GRN_API grn_obj *grn_inspect_encoding(grn_ctx *ctx, grn_obj *buffer, grn_encoding encoding);
 GRN_API grn_obj *grn_inspect_type(grn_ctx *ctx, grn_obj *buffer, unsigned char type);

  Modified: lib/db.c (+2 -2)
===================================================================
--- lib/db.c    2017-02-03 10:56:48 +0900 (a0a15bc)
+++ lib/db.c    2017-02-03 11:03:13 +0900 (2a88714)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2009-2016 Brazil
+  Copyright(C) 2009-2017 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -11049,7 +11049,7 @@ grn_obj_reinit_for(grn_ctx *ctx, grn_obj *obj, grn_obj *domain_obj)
   if (!GRN_DB_OBJP(domain_obj) && domain_obj->header.type != GRN_ACCESSOR) {
     grn_obj inspected;
     GRN_TEXT_INIT(&inspected, 0);
-    limited_size_inspect(ctx, &inspected, domain_obj);
+    grn_inspect_limited(ctx, &inspected, domain_obj);
     ERR(GRN_INVALID_ARGUMENT,
         "[reinit] invalid domain object: <%.*s>",
         (int)GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));

  Modified: lib/util.c (+24 -0)
===================================================================
--- lib/util.c    2017-02-03 10:56:48 +0900 (3cc367b)
+++ lib/util.c    2017-02-03 11:03:13 +0900 (7b4b5ea)
@@ -1449,6 +1449,30 @@ grn_inspect_indented(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj,
   return buffer;
 }
 
+grn_obj *
+grn_inspect_limited(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
+{
+  grn_obj sub_buffer;
+  unsigned int max_size = GRN_CTX_MSGSIZE / 2;
+
+  GRN_TEXT_INIT(&sub_buffer, 0);
+  grn_inspect(ctx, &sub_buffer, obj);
+  if (GRN_TEXT_LEN(&sub_buffer) > max_size) {
+    GRN_TEXT_PUT(ctx, buffer, GRN_TEXT_VALUE(&sub_buffer), max_size);
+    GRN_TEXT_PUTS(ctx, buffer, "...(");
+    grn_text_lltoa(ctx, buffer, GRN_TEXT_LEN(&sub_buffer));
+    GRN_TEXT_PUTS(ctx, buffer, ")");
+  } else {
+    GRN_TEXT_PUT(ctx,
+                 buffer,
+                 GRN_TEXT_VALUE(&sub_buffer),
+                 GRN_TEXT_LEN(&sub_buffer));
+  }
+  GRN_OBJ_FIN(ctx, &sub_buffer);
+
+  return buffer;
+}
+
 void
 grn_p(grn_ctx *ctx, grn_obj *obj)
 {
-------------- next part --------------
HTML����������������������������...
Descargar 



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