[Groonga-mysql-commit] mroonga/mroonga [master] Extract mrn_encode() as mrn::PathEncoder

Back to archive index

null+****@clear***** null+****@clear*****
2012年 4月 9日 (月) 18:32:22 JST


Kouhei Sutou	2012-04-09 18:32:22 +0900 (Mon, 09 Apr 2012)

  New Revision: 6df04844aa29d1000067705ababd5e3be230c164

  Log:
    Extract mrn_encode() as mrn::PathEncoder

  Added files:
    lib/mrn_path_encoder.cpp
    lib/mrn_path_encoder.hpp
  Modified files:
    lib/Makefile.am

  Modified: lib/Makefile.am (+6 -1)
===================================================================
--- lib/Makefile.am    2012-04-09 18:24:53 +0900 (b5f5428)
+++ lib/Makefile.am    2012-04-09 18:32:22 +0900 (7472563)
@@ -5,8 +5,13 @@ AM_CPPFLAGS =					\
 	-I$(top_srcdir)
 
 noinst_LTLIBRARIES =				\
-	libmroonga.la
+	libmroonga.la				\
+	libmrn_need_mysql.la
 
 libmroonga_la_SOURCES =				\
 	mrn_path_mapper.cpp			\
 	mrn_path_mapper.hpp
+
+libmrn_need_mysql_la_SOURCES =			\
+	mrn_path_encoder.cpp			\
+	mrn_path_encoder.hpp

  Added: lib/mrn_path_encoder.cpp (+71 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrn_path_encoder.cpp    2012-04-09 18:32:22 +0900 (5c6baa9)
@@ -0,0 +1,71 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2011 Kentoku SHIBA
+  Copyright(C) 2011-2012 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
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <mrn_mysql.h>
+
+#include "mrn_path_encoder.hpp"
+
+namespace mrn {
+  PathEncoder::PathEncoder(const char *name)
+    : name_(name) {
+    path_[0] = '\0';
+  }
+
+  const char *PathEncoder::path() {
+    if (path_[0] != '\0') {
+      return path_;
+    }
+
+    encode(path_, path_ + MRN_MAX_PATH_SIZE,
+           name_, name_ + strlen(name_));
+    return path_;
+  }
+
+  uint PathEncoder::encode(char *buf_st, char *buf_ed, const char *st, const char *ed) {
+    int res1, res2;
+    char *buf = buf_st;
+    my_wc_t wc;
+    my_charset_conv_mb_wc mb_wc = system_charset_info->cset->mb_wc;
+    my_charset_conv_wc_mb wc_mb = my_charset_filename.cset->wc_mb;
+    DBUG_ENTER("mrn_encode");
+    DBUG_PRINT("info", ("mroonga: in=%s", st));
+    buf_ed--;
+    for (; st < ed && buf < buf_ed; st += res1, buf += res2)
+    {
+      if ((res1 = (*mb_wc)(NULL, &wc, (uchar *) st, (uchar *) ed)) > 0)
+      {
+        if ((res2 = (*wc_mb)(NULL, wc, (uchar *) buf, (uchar *) buf_ed)) <= 0)
+        {
+          break;
+        }
+      } else if (res1 == MY_CS_ILSEQ)
+      {
+        *buf = *st;
+        res1 = 1;
+        res2 = 1;
+      } else {
+        break;
+      }
+    }
+    *buf = '\0';
+    DBUG_PRINT("info", ("mroonga: out=%s", buf_st));
+    DBUG_RETURN(buf - buf_st);
+  }
+}

  Added: lib/mrn_path_encoder.hpp (+39 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrn_path_encoder.hpp    2012-04-09 18:32:22 +0900 (3f72e57)
@@ -0,0 +1,39 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2011 Kentoku SHIBA
+  Copyright(C) 2011-2012 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
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#ifndef MRN_PATH_ENCODER_HPP_
+#define MRN_PATH_ENCODER_HPP_
+
+#include "mrn_sys.hpp"
+
+namespace mrn {
+  class PathEncoder {
+  public:
+    PathEncoder(const char *name);
+    const char *path();
+  private:
+    const char *name_;
+    char path_[MRN_MAX_PATH_SIZE];
+
+    uint encode(char *buf_st, char *buf_ed, const char *st, const char *ed);
+  };
+}
+
+#endif /* MRN_PATH_ENCODER_HPP_ */




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