httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r160977 - in httpd/apreq/branches/multi-env-unstable/library: t/util.c util.c
Date Mon, 11 Apr 2005 22:59:17 GMT
Author: joes
Date: Mon Apr 11 15:59:16 2005
New Revision: 160977

URL: http://svn.apache.org/viewcvs?view=rev&rev=160977
Log:
Convert switch to hex, and add basic charset decoding tests.

Modified:
    httpd/apreq/branches/multi-env-unstable/library/t/util.c
    httpd/apreq/branches/multi-env-unstable/library/util.c

Modified: httpd/apreq/branches/multi-env-unstable/library/t/util.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/library/t/util.c?view=diff&r1=160976&r2=160977
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/library/t/util.c (original)
+++ httpd/apreq/branches/multi-env-unstable/library/t/util.c Mon Apr 11 15:59:16 2005
@@ -19,6 +19,7 @@
 #include "apreq_util.h"
 #include "at.h"
 
+
 static void test_atoi64f(dAT)
 {
     AT_int_eq(apreq_atoi64f("0"), 0);
@@ -66,13 +67,23 @@
               hlen - 3);
 }
 
+#define A_GRAVE  0xE5
+#define KATAKANA_A 0xFF71
+
 static void test_decode(dAT)
 {
-
-
-
-
-
+    apr_size_t elen;
+    char src1[] = "%C3%80%E3%82%a2"; /* A_GRAVE KATAKANA_A as utf8 */
+    unsigned char expect[6];
+
+    AT_int_eq(apreq_decode((char *)expect, &elen, src1, sizeof(src1) -1), 
+              APR_SUCCESS + APREQ_CHARSET_UTF8);
+    AT_int_eq(elen, 5);
+    AT_int_eq(expect[0], 0xC3);
+    AT_int_eq(expect[1], 0x80);
+    AT_int_eq(expect[2], 0xE3);
+    AT_int_eq(expect[3], 0x82);
+    AT_int_eq(expect[4], 0xA2);
 }
 
 static void test_decodev(dAT)
@@ -114,6 +125,38 @@
 
 static void test_cp1252_to_utf8(dAT)
 {
+    char src1[] = "%C3%80%E3%82%a2"; /* A_GRAVE KATAKANA_A as utf8 */
+    char src2[5];
+    unsigned char expect[16];
+    apr_size_t slen;
+
+    AT_int_eq(apreq_decode((char *)src2, &slen, src1, sizeof(src1) -1), 
+              APR_SUCCESS + APREQ_CHARSET_UTF8);
+    AT_int_eq(apreq_cp1252_to_utf8((char *)expect, src2, 5),
+              12);
+
+    /* 0xC3 */
+    AT_int_eq(expect[0], 0xC0 | (0xC3 >> 6));
+    AT_int_eq(expect[1], 0xC3 - 0x40);
+
+    /* 0x20AC */
+    AT_int_eq(expect[2], 0xE0 | (0x20AC >> 12));
+    AT_int_eq(expect[3], 0x80 | ((0x20AC >> 6) & 0x3F));
+    AT_int_eq(expect[4], 0x80 | (0x20AC & 0x3F));
+    
+    /* 0xE3 */
+    AT_int_eq(expect[5], 0xC3);
+    AT_int_eq(expect[6], 0xE3 - 0x40);
+
+    /* 0x201A */
+    AT_int_eq(expect[7], 0xE0 | (0x201A >> 12));
+    AT_int_eq(expect[8], 0x80 | ((0x201A >> 6) & 0x3F));
+    AT_int_eq(expect[9], 0x80 | (0x201A & 0x3F));
+    
+
+    /* 0xA2 */
+    AT_int_eq(expect[10], 0xC0 | (0xA2 >> 6));
+    AT_int_eq(expect[11], 0xA2);
 
 }
 
@@ -168,10 +211,10 @@
         { dT(test_atoi64f, 9) },
         { dT(test_atoi64t, 9) },
         { dT(test_index, 6) },
-        { dT(test_decode, 0) },
+        { dT(test_decode, 7) },
         { dT(test_decodev, 6) },
         { dT(test_encode, 0) },
-        { dT(test_cp1252_to_utf8, 0) },
+        { dT(test_cp1252_to_utf8, 14) },
         { dT(test_quote, 0) },
         { dT(test_quote_once, 0), },
         { dT(test_join, 0) },

Modified: httpd/apreq/branches/multi-env-unstable/library/util.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/library/util.c?view=diff&r1=160976&r2=160977
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/library/util.c (original)
+++ httpd/apreq/branches/multi-env-unstable/library/util.c Mon Apr 11 15:59:16 2005
@@ -152,33 +152,33 @@
         return c;
 
     switch (c) {
-    case 128: return 0x20AC;
-    case 130: return 0x201A;
-    case 131: return 0x192;
-    case 132: return 0x201E;
-    case 133: return 0x2026;
-    case 134: return 0x2020;
-    case 135: return 0x2021;
-    case 136: return 0x2C6;
-    case 137: return 0x2030;
-    case 138: return 0x160;
-    case 139: return 0x2039;
-    case 140: return 0x152;
-    case 142: return 0x17D;
-    case 145: return 0x2018;
-    case 146: return 0x2019;
-    case 147: return 0x201C;
-    case 148: return 0x201D;
-    case 149: return 0x2022;
-    case 150: return 0x2013;
-    case 151: return 0x2014;
-    case 152: return 0x2DC;
-    case 153: return 0x2122;
-    case 154: return 0x161;
-    case 155: return 0x203A;
-    case 156: return 0x153;
-    case 158: return 0x17E;
-    case 159: return 0x178;
+    case 0x80: return 0x20AC;
+    case 0x82: return 0x201A;
+    case 0x83: return 0x192;
+    case 0x84: return 0x201E;
+    case 0x85: return 0x2026;
+    case 0x86: return 0x2020;
+    case 0x87: return 0x2021;
+    case 0x88: return 0x2C6;
+    case 0x89: return 0x2030;
+    case 0x8A: return 0x160;
+    case 0x8B: return 0x2039;
+    case 0x8C: return 0x152;
+    case 0x8E: return 0x17D;
+    case 0x91: return 0x2018;
+    case 0x92: return 0x2019;
+    case 0x93: return 0x201C;
+    case 0x94: return 0x201D;
+    case 0x95: return 0x2022;
+    case 0x96: return 0x2013;
+    case 0x97: return 0x2014;
+    case 0x98: return 0x2DC;
+    case 0x99: return 0x2122;
+    case 0x9A: return 0x161;
+    case 0x9B: return 0x203A;
+    case 0x9C: return 0x153;
+    case 0x9E: return 0x17E;
+    case 0x9F: return 0x178;
     }
     return c;
 }



Mime
View raw message