commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r821051 - /commons/sandbox/runtime/trunk/src/main/native/shared/string.c
Date Fri, 02 Oct 2009 15:17:59 GMT
Author: mturk
Date: Fri Oct  2 15:17:58 2009
New Revision: 821051

URL: http://svn.apache.org/viewvc?rev=821051&view=rev
Log:
Break conversion of input NUL char

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=821051&r1=821050&r2=821051&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Fri Oct  2 15:17:58 2009
@@ -383,7 +383,8 @@
     return need;
 }
 
-/* Modified version of UTF.
+/* Modified UTF-8 according to the java.io.DataInput
+ * specification
  */
 static int java_ucs2_to_utf8(const jchar *in, jsize inwords,
                              char *out, jsize *outbytes)
@@ -410,8 +411,8 @@
                 if (*outbytes < 2)
                     return ACR_INCOMPLETE;
                 *outbytes -= 2;
-                *(out++) = (unsigned char)(0xDF & (ch >> 6));
-                *(out++) = (unsigned char)(0xBF & (ch));
+                *(out++) = (unsigned char)(0xC0 | ((ch >> 6) & 0x1F));
+                *(out++) = (unsigned char)(0x80 | ((ch)      & 0x3F));
             }
             else {
                 /* Three byte sequence
@@ -419,9 +420,9 @@
                 if (*outbytes < 3)
                     return ACR_INCOMPLETE;
                 *outbytes -= 3;
-                *(out++) = (unsigned char)(0xEF & (ch >> 12));
-                *(out++) = (unsigned char)(0xBF & (ch >>  6));
-                *(out++) = (unsigned char)(0xBF & (ch));
+                *(out++) = (unsigned char)(0xE0 | ((ch >> 12) & 0x0F));
+                *(out++) = (unsigned char)(0x80 | ((ch >>  6) & 0x3F));
+                *(out++) = (unsigned char)(0x80 | ((ch)       & 0x3F));
             }
         }
        --inwords;
@@ -432,7 +433,9 @@
     }
     return ACR_SUCCESS;
 }
-
+/* Modified UTF-8 according to the java.io.DataOutput
+ * specification
+ */
 static int java_utf8_to_ucs2(const char *in, jsize inbytes,
                              jchar *out, jsize *outwords)
 {
@@ -440,7 +443,12 @@
 
     while (inbytes && *outwords) {
         ch = (unsigned char)(*in++);
-        if (!(ch & 0x80)) {
+        if (ch == 0) {
+            --*outwords;
+            *(out) = (jchar)0;
+            return ACR_SUCCESS;
+        }
+        else if (!(ch & 0x80)) {
             /* US-ASCII-7 plain text
              */
             --inbytes;



Mime
View raw message