OSDN Git Service

* Added Zenkaku Alphabet -> Hankaku Alphabet function.
authorAtsushi Konno <konn@users.sourceforge.jp>
Fri, 5 Dec 2008 15:58:27 +0000 (00:58 +0900)
committerAtsushi Konno <konn@users.sourceforge.jp>
Fri, 5 Dec 2008 15:58:27 +0000 (00:58 +0900)
include/chxj_conv_z2h.h [moved from include/chxj_conv_z2h_kana.h with 86% similarity]
src/chxj_conv_z2h_alpha.c [new file with mode: 0644]
src/chxj_conv_z2h_kana.c
src/mod_chxj.c

similarity index 86%
rename from include/chxj_conv_z2h_kana.h
rename to include/chxj_conv_z2h.h
index 53adbb5..770ab13 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef __CHXJ_CONV_KANA_H__
-#define __CHXJ_CONV_kANA_H__
+#ifndef __CHXJ_CONV_Z2H_H__
+#define __CHXJ_CONV_Z2H_H__
 
 #include "mod_chxj.h"
 
+typedef struct {
+  apr_size_t byte;
+  char *hankaku;
+} z2h_table_t;
+
 extern char *chxj_conv_z2h_kana(request_rec *r, const char *src, apr_size_t *len, chxjconvrule_entry *entryp);
 
 #endif
diff --git a/src/chxj_conv_z2h_alpha.c b/src/chxj_conv_z2h_alpha.c
new file mode 100644 (file)
index 0000000..c2d56ea
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "mod_chxj.h"
+#include "chxj_conv_z2h.h"
+#include "chxj_url_encode.h"
+#include "qs_parse_string.h"
+#include <errno.h>
+
+static z2h_table_t alpha_table_uc[] = {
+  { 1, "A",},
+  { 1, "B",},
+  { 1, "C",},
+  { 1, "D",},
+  { 1, "E",},
+  { 1, "F",},
+  { 1, "G",},
+  { 1, "H",},
+  { 1, "I",},
+  { 1, "J",},
+  { 1, "K",},
+  { 1, "L",},
+  { 1, "M",},
+  { 1, "N",},
+  { 1, "O",},
+  { 1, "P",},
+  { 1, "Q",},
+  { 1, "R",},
+  { 1, "S",},
+  { 1, "T",},
+  { 1, "U",},
+  { 1, "V",},
+  { 1, "W",},
+  { 1, "X",},
+  { 1, "Y",},
+  { 1, "Z",},
+};
+static z2h_table_t alpha_table_lc[] = {
+  { 1, "a",},
+  { 1, "b",},
+  { 1, "c",},
+  { 1, "d",},
+  { 1, "e",},
+  { 1, "f",},
+  { 1, "g",},
+  { 1, "h",},
+  { 1, "i",},
+  { 1, "j",},
+  { 1, "k",},
+  { 1, "l",},
+  { 1, "m",},
+  { 1, "n",},
+  { 1, "o",},
+  { 1, "p",},
+  { 1, "q",},
+  { 1, "r",},
+  { 1, "s",},
+  { 1, "t",},
+  { 1, "u",},
+  { 1, "v",},
+  { 1, "w",},
+  { 1, "x",},
+  { 1, "y",},
+  { 1, "z",},
+};
+
+/**
+ * 0x8260 -> 0x8279
+ * 0x8281 -> 0x829a
+ */
+char *
+chxj_conv_z2h_alpha(request_rec *r, const char *src, apr_size_t *len, chxjconvrule_entry *entryp)
+{
+  apr_size_t          ii;
+  apr_size_t          ilen;
+  apr_pool_t          *pool;
+  char                *obuf;
+  apr_size_t          olen;
+
+  DBG(r,"REQ[%X] start chxj_conv_z2h_alpha()", (unsigned int)(apr_size_t)r);
+
+  if (entryp->action & CONVRULE_Z2H_ALPHA_OFF_BIT) {
+    DBG(r,"REQ[%X] Detect Z2hAlphaOff", (unsigned int)(apr_size_t)r);
+    DBG(r,"REQ[%X] end chxj_conv_z2h_alpha()", (unsigned int)(apr_size_t)r);
+    return (char *)src;
+  }
+  if (! (entryp->action & CONVRULE_Z2H_ALPHA_ON_BIT)) {
+    DBG(r,"REQ[%X] Detect Z2hAlphaOff", (unsigned int)(apr_size_t)r);
+    DBG(r,"REQ[%X] end chxj_conv_z2h_alpha()", (unsigned int)(apr_size_t)r);
+    return (char *)src;
+  }
+
+  apr_pool_create(&pool, r->pool);
+
+  olen = 0;
+  ilen = *len;
+
+  obuf = apr_palloc(pool, ilen + 1);
+  if (! obuf) {
+    ERR(r,"%s:%d REQ[%X] memory allocation error", __FILE__,__LINE__,(unsigned int)(apr_size_t)r);
+    return (char*)src;
+  }
+
+  memset(obuf, 0, ilen + 1);
+  for (ii=0; ii<ilen; ii++) {
+    /* sjis only */
+    if (is_sjis_alpha(src[ii])) {
+      obuf[olen++] = src[ii];
+    }
+    else if (is_sjis_kanji(src[ii])) {
+      unsigned char firstbyte  = src[ii + 0];
+      unsigned char secondbyte = src[ii + 1];
+      /* Upper case */
+      if (   firstbyte == 0x82
+          && (secondbyte >= 0x60 && secondbyte <= 0x79)) {
+        unsigned char p = secondbyte - 0x60;
+        if (alpha_table_uc[p].byte != 0) {
+          /* Detect Zenkaku Alphabet */
+          strcpy(&obuf[olen], alpha_table_uc[p].hankaku);
+          olen += alpha_table_uc[p].byte;
+        }
+        else {
+          obuf[olen++] = src[ii + 0];
+          obuf[olen++] = src[ii + 1];
+        }
+      }
+      else /* Lower case */
+      if (   firstbyte == 0x82
+          && (secondbyte >= 0x81 && secondbyte <= 0x9a)) {
+        unsigned char p = secondbyte - 0x81;
+        if (alpha_table_lc[p].byte != 0) {
+          /* Detect Zenkaku Alphabet */
+          strcpy(&obuf[olen], alpha_table_lc[p].hankaku);
+          olen += alpha_table_lc[p].byte;
+        }
+        else {
+          obuf[olen++] = src[ii + 0];
+          obuf[olen++] = src[ii + 1];
+        }
+      }
+      else {
+        obuf[olen++] = src[ii + 0];
+        obuf[olen++] = src[ii + 1];
+      }
+      ii++;
+    }
+    else {
+      obuf[olen++] = src[ii];
+    }
+  }
+  *len = olen;
+
+  DBG(r,"REQ[%X] end chxj_conv_z2h_alpha()", (unsigned int)(apr_size_t)r);
+  return obuf;
+}
+/*
+ * vim: ts=2 et
+ */
index 770192b..be80293 100644 (file)
  * limitations under the License.
  */
 #include "mod_chxj.h"
-#include "chxj_conv_z2h_kana.h"
+#include "chxj_conv_z2h.h"
 #include "chxj_url_encode.h"
 #include "qs_parse_string.h"
 #include <errno.h>
 
-typedef struct {
-  apr_size_t byte;
-  char *hankaku;
-} kana_table_t;
-
-static kana_table_t kana_table1[] = {
+static z2h_table_t kana_table1[] = {
   { /* 00 */ 1, "\xa7\x00",},
   { /* 01 */ 1, "\xb1\x00",},
   { /* 02 */ 1, "\xa8\x00",},
@@ -114,7 +109,7 @@ static kana_table_t kana_table1[] = {
   { /* 85 */ 2, "\x83\x95",},
   { /* 86 */ 2, "\x83\x96",},
 };
-static kana_table_t kana_table2[] = {
+static z2h_table_t kana_table2[] = {
   { /* 0x8141 、*/ 1, "\xa4",},
   { /* 0x8142 。*/ 1, "\xa1",},
   { /* 0x8143 ,*/ 1, ",",},
@@ -127,11 +122,11 @@ static kana_table_t kana_table2[] = {
   { /* 0x814a ゛*/ 1, "\xde",},
   { /* 0x814b ゜*/ 1, "\xdf",},
 };
-static kana_table_t kana_table3[] = {
+static z2h_table_t kana_table3[] = {
   { /* 0x8175 「*/ 1, "\xa2",},
   { /* 0x8176 」*/ 1, "\xa3",},
 };
-static kana_table_t kana_table4[] = {
+static z2h_table_t kana_table4[] = {
   { /* 0x815b ゛*/ 1, "\xb0",},
 };
 
index 1acd7a1..403174c 100644 (file)
@@ -68,7 +68,7 @@
 #endif
 #include "chxj_serf.h"
 #include "chxj_add_device_env.h"
-#include "chxj_conv_kana.h"
+#include "chxj_conv_z2h.h"
 
 
 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"