[Groonga-commit] groonga/groonga at 8608c1e [master] grn_ts: move definitions of grn_ts_str into lib/ts/ts_str

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Mon Nov 9 12:53:02 JST 2015


susumu.yata	2015-11-09 12:53:02 +0900 (Mon, 09 Nov 2015)

  New Revision: 8608c1e67e23343588f09b9477bc86b3f6418a4b
  https://github.com/groonga/groonga/commit/8608c1e67e23343588f09b9477bc86b3f6418a4b

  Message:
    grn_ts: move definitions of grn_ts_str into lib/ts/ts_str

  Added files:
    lib/ts/Makefile.am
    lib/ts/sources.am
    lib/ts/ts_str.c
    lib/ts/ts_str.h
  Modified files:
    configure.ac
    lib/CMakeLists.txt
    lib/Makefile.am
    lib/ts.c

  Modified: configure.ac (+1 -0)
===================================================================
--- configure.ac    2015-11-07 22:15:08 +0900 (9d04bd3)
+++ configure.ac    2015-11-09 12:53:02 +0900 (05a9af5)
@@ -242,6 +242,7 @@ AC_CONFIG_FILES([
   lib/mrb/scripts/initialize/Makefile
   lib/mrb/scripts/logger/Makefile
   lib/mrb/scripts/query_logger/Makefile
+  lib/ts/Makefile
   include/Makefile
   include/groonga/Makefile
   plugins/Makefile

  Modified: lib/CMakeLists.txt (+7 -2)
===================================================================
--- lib/CMakeLists.txt    2015-11-07 22:15:08 +0900 (1a7da11)
+++ lib/CMakeLists.txt    2015-11-09 12:53:02 +0900 (00d895c)
@@ -32,8 +32,12 @@ string(REGEX REPLACE "([^;]+)" "dat/\\1"
 read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/mrb/sources.am LIBGRNMRB_SOURCES)
 string(REGEX REPLACE "([^;]+)" "mrb/\\1"
   LIBGRNMRB_SOURCES "${LIBGRNMRB_SOURCES}")
+read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/ts/sources.am LIBGRNTS_SOURCES)
+string(REGEX REPLACE "([^;]+)" "ts/\\1"
+  LIBGRNTS_SOURCES "${LIBGRNTS_SOURCES}")
 
-set_source_files_properties(${LIBGROONGA_SOURCES} ${LIBGRNMRB_SOURCES}
+set_source_files_properties(
+  ${LIBGROONGA_SOURCES} ${LIBGRNMRB_SOURCES} ${LIBGRNTS_SOURCES}
   PROPERTIES
   COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
 set_source_files_properties(dat.cpp ${LIBGRNDAT_SOURCES}
@@ -43,7 +47,8 @@ set_source_files_properties(dat.cpp ${LIBGRNDAT_SOURCES}
 set(GRN_ALL_SOURCES
   ${LIBGROONGA_SOURCES}
   ${LIBGRNDAT_SOURCES}
-  ${LIBGRNMRB_SOURCES})
+  ${LIBGRNMRB_SOURCES}
+  ${LIBGRNTS_SOURCES})
 if(GRN_EMBED)
   add_library(libgroonga STATIC ${GRN_ALL_SOURCES})
   set_target_properties(

  Modified: lib/Makefile.am (+3 -1)
===================================================================
--- lib/Makefile.am    2015-11-07 22:15:08 +0900 (8f4e76e)
+++ lib/Makefile.am    2015-11-09 12:53:02 +0900 (4cf5e39)
@@ -1,6 +1,7 @@
 SUBDIRS =					\
 	dat					\
-	mrb
+	mrb					\
+	ts
 
 lib_LTLIBRARIES = libgroonga.la
 
@@ -33,6 +34,7 @@ libgroonga_la_LDFLAGS =				\
 libgroonga_la_LIBADD =				\
 	dat/libgrndat.la			\
 	mrb/libgrnmrb.la			\
+	ts/libgrnts.la				\
 	$(MESSAGE_PACK_LIBS)
 
 if WITH_MRUBY

  Modified: lib/ts.c (+2 -153)
===================================================================
--- lib/ts.c    2015-11-07 22:15:08 +0900 (4e601c5)
+++ lib/ts.c    2015-11-09 12:53:02 +0900 (0dd902e)
@@ -35,6 +35,8 @@
 #include "grn_store.h"
 #include "grn_str.h"
 
+#include "ts/ts_str.h"
+
 /*-------------------------------------------------------------
  * Miscellaneous.
  */
@@ -56,159 +58,6 @@ enum { GRN_TS_BATCH_SIZE = 1024 };
 } while (GRN_FALSE)
 
 /*-------------------------------------------------------------
- * grn_ts_str.
- */
-
-typedef struct {
-  const char *ptr; /* The starting address. */
-  size_t size;     /* The size in bytes. */
-} grn_ts_str;
-
-/* grn_ts_byte_is_decimal() returns whether or not a byte is decimal. */
-inline static grn_ts_bool
-grn_ts_byte_is_decimal(unsigned char byte) {
-  return (byte >= '0') && (byte <= '9');
-}
-
-/*
- * grn_ts_byte_is_name_char() returns whether or not a byte is allowed as a
- * part of a name.
- */
-inline static grn_ts_bool
-grn_ts_byte_is_name_char(unsigned char byte) {
-  /*
-   * Note: A table name allows '#', '@' and '-'.
-   * http://groonga.org/docs/reference/commands/table_create.html#name
-   */
-  if (((byte >= '0') && (byte <= '9')) || ((byte >= 'A') && (byte <= 'Z')) ||
-      ((byte >= 'a') && (byte <= 'z')) || (byte == '_')) {
-    return GRN_TRUE;
-  }
-  return GRN_FALSE;
-}
-
-/* grn_ts_str_trim_left() returns a string without the leading white-spaces. */
-static grn_ts_str
-grn_ts_str_trim_left(grn_ts_str str) {
-  size_t i;
-  for (i = 0; i < str.size; i++) {
-    if (!isspace((unsigned char)str.ptr[i])) {
-      break;
-    }
-  }
-  str.ptr += i;
-  str.size -= i;
-  return str;
-}
-
-/* grn_ts_str_is_true() returns str == "true". */
-static grn_ts_bool
-grn_ts_str_is_true(grn_ts_str str) {
-  return (str.size == 4) && !memcmp(str.ptr, "true", 4);
-}
-
-/* grn_ts_str_is_false() returns str == "false". */
-static grn_ts_bool
-grn_ts_str_is_false(grn_ts_str str) {
-  return (str.size == 5) && !memcmp(str.ptr, "false", 5);
-}
-
-/* grn_ts_str_is_bool() returns (str == "true") || (str == "false"). */
-static grn_ts_bool
-grn_ts_str_is_bool(grn_ts_str str) {
-  return grn_ts_str_is_true(str) || grn_ts_str_is_false(str);
-}
-
-/*
- * grn_ts_str_is_name_prefix() returns whether or not a string is valid as a
- * name prefix. Note that an empty string is a name prefix.
- */
-static grn_ts_bool
-grn_ts_str_is_name_prefix(grn_ts_str str) {
-  size_t i;
-  for (i = 0; i < str.size; i++) {
-    if (!grn_ts_byte_is_name_char(str.ptr[i])) {
-      return GRN_FALSE;
-    }
-  }
-  return GRN_TRUE;
-}
-
-/*
- * grn_ts_str_is_name() returns whether or not a string is valid as a name.
- * Note that an empty string is invalid as a name.
- */
-static grn_ts_bool
-grn_ts_str_is_name(grn_ts_str str) {
-  if (!str.size) {
-    return GRN_FALSE;
-  }
-  return grn_ts_str_is_name_prefix(str);
-}
-
-/* grn_ts_str_is_id_name() returns str == "_id". */
-static grn_ts_bool
-grn_ts_str_is_id_name(grn_ts_str str) {
-  return (str.size == GRN_COLUMN_NAME_ID_LEN) &&
-         !memcmp(str.ptr, GRN_COLUMN_NAME_ID, GRN_COLUMN_NAME_ID_LEN);
-}
-
-/* grn_ts_str_is_score_name() returns str == "_score". */
-static grn_ts_bool
-grn_ts_str_is_score_name(grn_ts_str str) {
-  return (str.size == GRN_COLUMN_NAME_SCORE_LEN) &&
-         !memcmp(str.ptr, GRN_COLUMN_NAME_SCORE, GRN_COLUMN_NAME_SCORE_LEN);
-}
-
-/* grn_ts_str_is_key_name() returns str == "_key". */
-static grn_ts_bool
-grn_ts_str_is_key_name(grn_ts_str str) {
-  return (str.size == GRN_COLUMN_NAME_KEY_LEN) &&
-         !memcmp(str.ptr, GRN_COLUMN_NAME_KEY, GRN_COLUMN_NAME_KEY_LEN);
-}
-
-/* grn_ts_str_is_value_name() returns str == "_value". */
-static grn_ts_bool
-grn_ts_str_is_value_name(grn_ts_str str) {
-  return (str.size == GRN_COLUMN_NAME_VALUE_LEN) &&
-         !memcmp(str.ptr, GRN_COLUMN_NAME_VALUE, GRN_COLUMN_NAME_VALUE_LEN);
-}
-
-/*
- * grn_ts_str_has_number_prefix() returns whether or not a string starts with a
- * number or not.
- */
-static grn_ts_bool
-grn_ts_str_has_number_prefix(grn_ts_str str) {
-  if (!str.size) {
-    return GRN_FALSE;
-  }
-  if (grn_ts_byte_is_decimal(str.ptr[0])) {
-    return GRN_TRUE;
-  }
-  if (str.size == 1) {
-    return GRN_FALSE;
-  }
-  switch (str.ptr[0]) {
-    case '+': case '-': {
-      if (grn_ts_byte_is_decimal(str.ptr[1])) {
-        return GRN_TRUE;
-      }
-      if (str.size == 2) {
-        return GRN_FALSE;
-      }
-      return (str.ptr[1] == '.') && grn_ts_byte_is_decimal(str.ptr[2]);
-    }
-    case '.': {
-      return grn_ts_byte_is_decimal(str.ptr[1]);
-    }
-    default: {
-      return GRN_FALSE;
-    }
-  }
-}
-
-/*-------------------------------------------------------------
  * grn_ts_buf.
  */
 

  Added: lib/ts/Makefile.am (+14 -0) 100644
===================================================================
--- /dev/null
+++ lib/ts/Makefile.am    2015-11-09 12:53:02 +0900 (e8a1c77)
@@ -0,0 +1,14 @@
+DEFAULT_INCLUDES =				\
+	-I$(top_builddir)			\
+	-I$(top_srcdir)/include
+
+AM_CFLAGS =					\
+	$(NO_STRICT_ALIASING_CFLAGS)		\
+	$(COVERAGE_CFLAGS)			\
+	$(GRN_CFLAGS)
+
+noinst_LTLIBRARIES = libgrnts.la
+
+include sources.am
+
+CLEANFILES = *.gcno *.gcda

  Added: lib/ts/sources.am (+3 -0) 100644
===================================================================
--- /dev/null
+++ lib/ts/sources.am    2015-11-09 12:53:02 +0900 (704d4ac)
@@ -0,0 +1,3 @@
+libgrnts_la_SOURCES =				\
+	ts_str.c				\
+	ts_str.h

  Added: lib/ts/ts_str.c (+154 -0) 100644
===================================================================
--- /dev/null
+++ lib/ts/ts_str.c    2015-11-09 12:53:02 +0900 (fdc5600)
@@ -0,0 +1,154 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2015 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "ts_str.h"
+
+#include <ctype.h>
+#include <string.h>
+
+grn_ts_bool
+grn_ts_byte_is_decimal(uint8_t byte)
+{
+  return (byte >= '0') && (byte <= '9');
+}
+
+grn_ts_bool
+grn_ts_byte_is_name_char(uint8_t byte)
+{
+  /*
+   * Note: A table name allows '#', '@' and '-'.
+   * http://groonga.org/docs/reference/commands/table_create.html#name
+   */
+  if (((byte >= '0') && (byte <= '9')) || ((byte >= 'A') && (byte <= 'Z')) ||
+      ((byte >= 'a') && (byte <= 'z')) || (byte == '_')) {
+    return GRN_TRUE;
+  }
+  return GRN_FALSE;
+}
+
+grn_ts_str
+grn_ts_str_trim_left(grn_ts_str str)
+{
+  size_t i;
+  for (i = 0; i < str.size; i++) {
+    if (!isspace((uint8_t)str.ptr[i])) {
+      break;
+    }
+  }
+  str.ptr += i;
+  str.size -= i;
+  return str;
+}
+
+grn_ts_bool
+grn_ts_str_is_true(grn_ts_str str)
+{
+  return (str.size == 4) && !memcmp(str.ptr, "true", 4);
+}
+
+grn_ts_bool
+grn_ts_str_is_false(grn_ts_str str)
+{
+  return (str.size == 5) && !memcmp(str.ptr, "false", 5);
+}
+
+grn_ts_bool
+grn_ts_str_is_bool(grn_ts_str str)
+{
+  return grn_ts_str_is_true(str) || grn_ts_str_is_false(str);
+}
+
+grn_ts_bool
+grn_ts_str_is_name_prefix(grn_ts_str str)
+{
+  size_t i;
+  for (i = 0; i < str.size; i++) {
+    if (!grn_ts_byte_is_name_char(str.ptr[i])) {
+      return GRN_FALSE;
+    }
+  }
+  return GRN_TRUE;
+}
+
+grn_ts_bool
+grn_ts_str_is_name(grn_ts_str str)
+{
+  if (!str.size) {
+    return GRN_FALSE;
+  }
+  return grn_ts_str_is_name_prefix(str);
+}
+
+grn_ts_bool
+grn_ts_str_is_id_name(grn_ts_str str)
+{
+  return (str.size == GRN_COLUMN_NAME_ID_LEN) &&
+         !memcmp(str.ptr, GRN_COLUMN_NAME_ID, GRN_COLUMN_NAME_ID_LEN);
+}
+
+grn_ts_bool
+grn_ts_str_is_score_name(grn_ts_str str)
+{
+  return (str.size == GRN_COLUMN_NAME_SCORE_LEN) &&
+         !memcmp(str.ptr, GRN_COLUMN_NAME_SCORE, GRN_COLUMN_NAME_SCORE_LEN);
+}
+
+grn_ts_bool
+grn_ts_str_is_key_name(grn_ts_str str)
+{
+  return (str.size == GRN_COLUMN_NAME_KEY_LEN) &&
+         !memcmp(str.ptr, GRN_COLUMN_NAME_KEY, GRN_COLUMN_NAME_KEY_LEN);
+}
+
+grn_ts_bool
+grn_ts_str_is_value_name(grn_ts_str str)
+{
+  return (str.size == GRN_COLUMN_NAME_VALUE_LEN) &&
+         !memcmp(str.ptr, GRN_COLUMN_NAME_VALUE, GRN_COLUMN_NAME_VALUE_LEN);
+}
+
+grn_ts_bool
+grn_ts_str_has_number_prefix(grn_ts_str str)
+{
+  if (!str.size) {
+    return GRN_FALSE;
+  }
+  if (grn_ts_byte_is_decimal(str.ptr[0])) {
+    return GRN_TRUE;
+  }
+  if (str.size == 1) {
+    return GRN_FALSE;
+  }
+  switch (str.ptr[0]) {
+    case '+': case '-': {
+      if (grn_ts_byte_is_decimal(str.ptr[1])) {
+        return GRN_TRUE;
+      }
+      if (str.size == 2) {
+        return GRN_FALSE;
+      }
+      return (str.ptr[1] == '.') && grn_ts_byte_is_decimal(str.ptr[2]);
+    }
+    case '.': {
+      return grn_ts_byte_is_decimal(str.ptr[1]);
+    }
+    default: {
+      return GRN_FALSE;
+    }
+  }
+}

  Added: lib/ts/ts_str.h (+88 -0) 100644
===================================================================
--- /dev/null
+++ lib/ts/ts_str.h    2015-11-09 12:53:02 +0900 (fe83b7b)
@@ -0,0 +1,88 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2015 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef GRN_TS_STR_H
+#define GRN_TS_STR_H
+
+#include "../grn_ts.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+  const char *ptr; /* The starting address. */
+  size_t size;     /* The size in bytes. */
+} grn_ts_str;
+
+/* grn_ts_byte_is_decimal() returns whether or not a byte is decimal. */
+grn_ts_bool grn_ts_byte_is_decimal(uint8_t byte);
+
+/*
+ * grn_ts_byte_is_name_char() returns whether or not a byte is allowed as a
+ * part of a name.
+ */
+grn_ts_bool grn_ts_byte_is_name_char(uint8_t byte);
+
+/* grn_ts_str_trim_left() returns a string without the leading white-spaces. */
+grn_ts_str grn_ts_str_trim_left(grn_ts_str str);
+
+/* grn_ts_str_is_true() returns str == "true". */
+grn_ts_bool grn_ts_str_is_true(grn_ts_str str);
+
+/* grn_ts_str_is_false() returns str == "false". */
+grn_ts_bool grn_ts_str_is_false(grn_ts_str str);
+
+/* grn_ts_str_is_bool() returns (str == "true") || (str == "false"). */
+grn_ts_bool grn_ts_str_is_bool(grn_ts_str str);
+
+/*
+ * grn_ts_str_is_name_prefix() returns whether or not a string is valid as a
+ * name prefix. Note that an empty string is a name prefix.
+ */
+grn_ts_bool grn_ts_str_is_name_prefix(grn_ts_str str);
+
+/*
+ * grn_ts_str_is_name() returns whether or not a string is valid as a name.
+ * Note that an empty string is invalid as a name.
+ */
+grn_ts_bool grn_ts_str_is_name(grn_ts_str str);
+
+/* grn_ts_str_is_id_name() returns str == "_id". */
+grn_ts_bool grn_ts_str_is_id_name(grn_ts_str str);
+
+/* grn_ts_str_is_score_name() returns str == "_score". */
+grn_ts_bool grn_ts_str_is_score_name(grn_ts_str str);
+
+/* grn_ts_str_is_key_name() returns str == "_key". */
+grn_ts_bool grn_ts_str_is_key_name(grn_ts_str str);
+
+/* grn_ts_str_is_value_name() returns str == "_value". */
+grn_ts_bool grn_ts_str_is_value_name(grn_ts_str str);
+
+/*
+ * grn_ts_str_has_number_prefix() returns whether or not a string starts with a
+ * number or not.
+ */
+grn_ts_bool grn_ts_str_has_number_prefix(grn_ts_str str);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_TS_STR_H */
-------------- next part --------------
HTML����������������������������...
ダウンロード 



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