hi,

firstly apologies if i have gone about this all wrong; this is my first contribution.

it was mentioned in the status mail this morning (28th July) that testucs needs to be ported to unix. i have attempted to do this.

the testucs app tests the two functions  apr_conv_utf8_to_ucs2 and apr_conv_ucs2_to_utf8. These functions are only declared for win32. Looking at this code there doesn't seem to be much that is win32 specific in it (in fact it does compile unchanged on linux). So to get this test to work on unix i just have to link this to functions into the unix shared lib.

two ways i see to do this:
    1) a clean way:
    i move the win32 arch dependant utf8 files (include/arch/win32/apr_arch_utf8.h and misc/win32/utf8.c) to a common place (include/apr_utf8.h and strings/apr_utf8.c (aplogies for the use of the strings dir, but it seemed like to most appropriate. of course i can change that)). Then update all win32 files that #include the old locations, change the .dsp files (this i did manually so i could be wrong) and update the test/internal/Makefile.in (to build the test) and the testucs.c file (to reflect the include path changes)

    clean.patch that is attached does this.

    2) a dirty way
    i copied the win32 arch files to the unix arch directory. I updated the test/internal/Makefile.in file to include the arch dependant files. The arch directory that is included is set by the configure script.

    dirty.patch that is attached does this.

both patches are based on version 1.1.1.

you must ./buildconf and ./configure once applied (for both patches), since i moved some files around.

using both patches i have now run the testucs program on my linux box. the testall program also reports success. the real (almost laughable) downside is that i do not have a windows compile environment to test that i have not broken it there. there is a distinct possibility that i have.

i prefer the clean patch, but i don't now enough about the consequences to comment on whether it is suitable. the dirty way would work better with symbolic links not straight copies.


i hope that is what was required and that i have contributed in the correct way

neale


--- /dev/null	2005-06-10 15:18:08.000000000 +0200
+++ include/apr_utf8.h	2005-07-28 14:33:25.318699576 +0200
@@ -0,0 +1,55 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * 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.
+ */
+
+#ifndef UTF8_H
+#define UTF8_H
+
+#include "apr.h"
+#include "apr_lib.h"
+#include "apr_errno.h"
+
+/* If we ever support anything more exciting than char... this could move.
+ */
+typedef apr_uint16_t apr_wchar_t;
+
+/**
+ * An APR internal function for fast utf-8 octet-encoded Unicode conversion
+ * to the ucs-2 wide Unicode format.  This function is used for filename and 
+ * other resource conversions for platforms providing native Unicode support.
+ *
+ * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
+ * when the character code is invalid (in or out of context) and the later
+ * when more characters were expected, but insufficient characters remain.
+ */
+APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
+                                                apr_size_t *inbytes,
+                                                apr_wchar_t *out, 
+                                                apr_size_t *outwords);
+
+/**
+ * An APR internal function for fast ucs-2 wide Unicode format conversion to 
+ * the utf-8 octet-encoded Unicode.  This function is used for filename and 
+ * other resource conversions for platforms providing native Unicode support.
+ *
+ * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
+ * when the character code is invalid (in or out of context) and the later
+ * when more words were expected, but insufficient words remain.
+ */
+APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
+                                                apr_size_t *inwords,
+                                                char *out, 
+                                                apr_size_t *outbytes);
+
+#endif /* def UTF8_H */
--- /dev/null	2005-06-10 15:18:08.000000000 +0200
+++ strings/apr_utf8.c	2005-07-28 14:34:39.656398528 +0200
@@ -0,0 +1,253 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * 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 "apr.h"
+#include "apr_private.h"
+#include "apr_errno.h"
+#include "apr_utf8.h"
+
+/* Implement the design principal specified by RFC 2718 2.2.5 
+ * Guidelines for new URL Schemes - within the APR.
+ *
+ * Since many architectures support unicode, and UCS2 is the most
+ * efficient storage used by those archictures, these functions
+ * exist to validate a UCS string.  It is up to the operating system
+ * to determine the validitity of the string in the context of it's
+ * native language support.  File systems that support filename 
+ * characters of 0x80-0xff but have no support of Unicode will find 
+ * this function useful only for validating the character sequences 
+ * and rejecting poorly encoded strings, if RFC 2718 2.2.5 naming is
+ * desired.
+ *
+ * from RFC 2279 UTF-8, a transformation format of ISO 10646
+ *
+ *     UCS-4 range (hex.)    UTF-8 octet sequence (binary)
+ * 1:2 0000 0000-0000 007F   0xxxxxxx
+ * 2:2 0000 0080-0000 07FF   110XXXXx 10xxxxxx
+ * 3:2 0000 0800-0000 FFFF   1110XXXX 10Xxxxxx 10xxxxxx
+ * 4:4 0001 0000-001F FFFF   11110zXX 10XXxxxx 10xxxxxx 10xxxxxx
+ * inv 0020 0000-03FF FFFF   111110XX 10XXXxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * inv 0400 0000-7FFF FFFF   1111110X 10XXXXxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ *
+ * One of the X values must be one for the encoding length to be legit.
+ * Neither the z bit, nor the final two forms, are used for ucs-2
+ *
+ *   "Pairs of UCS-2 values between D800 and DFFF (surrogate pairs in 
+ *   Unicode parlance), being actually UCS-4 characters transformed 
+ *   through UTF-16, need special treatment: the UTF-16 transformation 
+ *   must be undone, yielding a UCS-4 character that is then transformed 
+ *   as above."
+ *
+ * from RFC2781 UTF-16: the compressed ISO 10646 encoding bitmask
+ *
+ *  U' = U - 0x10000
+ *  U' = 000000000000yyyyyyyyyyxxxxxxxxxx
+ *                  W1 = 110110yyyyyyyyyy
+ *                  W2 = 110111xxxxxxxxxx
+ *
+ * apr_conv_utf8_to_ucs2 out bytes:sizeof(in) * 1 <= Req <= sizeof(in) * 2
+ *
+ * apr_conv_ucs2_to_utf8 out words:sizeof(in) / 2 <= Req <= sizeof(in) * 3 / 2
+ */
+
+APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
+                                                apr_size_t *inbytes,
+                                                apr_wchar_t *out, 
+                                                apr_size_t *outwords)
+{
+    apr_int64_t newch, mask;
+    apr_size_t expect, eating;
+    int ch;
+    
+    while (*inbytes && *outwords) 
+    {
+        ch = (unsigned char)(*in++);
+        if (!(ch & 0200)) {
+            /* US-ASCII-7 plain text
+             */
+            --*inbytes;
+            --*outwords;
+            *(out++) = ch;
+        }
+        else
+        {
+            if ((ch & 0300) != 0300) { 
+                /* Multibyte Continuation is out of place
+                 */
+                return APR_EINVAL;
+            }
+            else
+            {
+                /* Multibyte Sequence Lead Character
+                 *
+                 * Compute the expected bytes while adjusting
+                 * or lead byte and leading zeros mask.
+                 */
+                mask = 0340;
+                expect = 1;
+                while ((ch & mask) == mask) {
+                    mask |= mask >> 1;
+                    if (++expect > 3) /* (truly 5 for ucs-4) */
+                        return APR_EINVAL;
+                }
+                newch = ch & ~mask;
+                eating = expect + 1;
+                if (*inbytes <= expect)
+                    return APR_INCOMPLETE;
+                /* Reject values of excessive leading 0 bits
+                 * utf-8 _demands_ the shortest possible byte length
+                 */
+                if (expect == 1) {
+                    if (!(newch & 0036))
+                        return APR_EINVAL;
+                }
+                else {
+                    /* Reject values of excessive leading 0 bits
+                     */
+                    if (!newch && !((unsigned char)*in & 0077 & (mask << 1)))
+                        return APR_EINVAL;
+                    if (expect == 2) {
+                        /* Reject values D800-DFFF when not utf16 encoded
+                         * (may not be an appropriate restriction for ucs-4)
+                         */
+                        if (newch == 0015 && ((unsigned char)*in & 0040))
+                            return APR_EINVAL;
+                    }
+                    else if (expect == 3) {
+                        /* Short circuit values > 110000
+                         */
+                        if (newch > 4)
+                            return APR_EINVAL;
+                        if (newch == 4 && ((unsigned char)*in & 0060))
+                            return APR_EINVAL;
+                    }
+                }
+                /* Where the boolean (expect > 2) is true, we will need
+                 * an extra word for the output.
+                 */
+                if (*outwords < (apr_size_t)(expect > 2) + 1) 
+                    break; /* buffer full */
+                while (expect--)
+                {
+                    /* Multibyte Continuation must be legal */
+                    if (((ch = (unsigned char)*(in++)) & 0300) != 0200)
+                        return APR_EINVAL;
+                    newch <<= 6;
+                    newch |= (ch & 0077);
+                }
+                *inbytes -= eating;
+                /* newch is now a true ucs-4 character
+                 *
+                 * now we need to fold to ucs-2
+                 */
+                if (newch < 0x10000) 
+                {
+                    --*outwords;
+                    *(out++) = (apr_wchar_t) newch;
+                }
+                else 
+                {
+                    *outwords -= 2;
+                    newch -= 0x10000;
+                    *(out++) = (apr_wchar_t) (0xD800 | (newch >> 10));
+                    *(out++) = (apr_wchar_t) (0xDC00 | (newch & 0x03FF));                    
+                }
+            }
+        }
+    }
+    /* Buffer full 'errors' aren't errors, the client must inspect both
+     * the inbytes and outwords values
+     */
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
+                                                apr_size_t *inwords,
+                                                char *out, 
+                                                apr_size_t *outbytes)
+{
+    apr_int64_t newch, require;
+    apr_size_t need;
+    char *invout;
+    int ch;
+    
+    while (*inwords && *outbytes) 
+    {
+        ch = (unsigned short)(*in++);
+        if (ch < 0x80)
+        {
+            --*inwords;
+            --*outbytes;
+            *(out++) = (unsigned char) ch;
+        }
+        else 
+        {
+            if ((ch & 0xFC00) == 0xDC00) {
+                /* Invalid Leading ucs-2 Multiword Continuation Character
+                 */
+                return APR_EINVAL;
+            }
+            if ((ch & 0xFC00) == 0xD800) {
+                /* Leading ucs-2 Multiword Character
+                 */
+                if (*inwords < 2) {
+                    /* Missing ucs-2 Multiword Continuation Character
+                     */
+                    return APR_INCOMPLETE;
+                }
+                if (((unsigned short)(*in) & 0xFC00) != 0xDC00) {
+                    /* Invalid ucs-2 Multiword Continuation Character
+                     */
+                    return APR_EINVAL;
+                }
+                newch = (ch & 0x03FF) << 10 | ((unsigned short)(*in++) & 0x03FF);
+                newch += 0x10000;
+            }
+            else {
+                /* ucs-2 Single Word Character
+                 */
+                newch = ch;
+            }
+            /* Determine the absolute minimum utf-8 bytes required
+             */
+            require = newch >> 11;
+            need = 1;
+            while (require)
+                require >>= 5, ++need;
+            if (need >= *outbytes)
+                break; /* Insufficient buffer */
+            *inwords -= (need > 2) + 1;
+            *outbytes -= need + 1;
+            /* Compute the utf-8 characters in last to first order,
+             * calculating the lead character length bits along the way.
+             */
+            ch = 0200;
+            out += need + 1;
+            invout = out;
+            while (need--) {
+                ch |= ch >> 1;
+                *(--invout) = (unsigned char)(0200 | (newch & 0077));
+                newch >>= 6;
+            }
+            /* Compute the lead utf-8 character and move the dest offset
+             */
+            *(--invout) = (unsigned char)(ch | newch);
+        }
+    }
+    /* Buffer full 'errors' aren't errors, the client must inspect both
+     * the inwords and outbytes values
+     */
+    return APR_SUCCESS;    
+}
--- include/arch/win32/apr_arch_utf8.h	2004-11-24 23:51:51.000000000 +0100
+++ /dev/null	2005-06-10 15:18:08.000000000 +0200
@@ -1,55 +0,0 @@
-/* Copyright 2000-2004 The Apache Software Foundation
- *
- * 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.
- */
-
-#ifndef UTF8_H
-#define UTF8_H
-
-#include "apr.h"
-#include "apr_lib.h"
-#include "apr_errno.h"
-
-/* If we ever support anything more exciting than char... this could move.
- */
-typedef apr_uint16_t apr_wchar_t;
-
-/**
- * An APR internal function for fast utf-8 octet-encoded Unicode conversion
- * to the ucs-2 wide Unicode format.  This function is used for filename and 
- * other resource conversions for platforms providing native Unicode support.
- *
- * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
- * when the character code is invalid (in or out of context) and the later
- * when more characters were expected, but insufficient characters remain.
- */
-APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
-                                                apr_size_t *inbytes,
-                                                apr_wchar_t *out, 
-                                                apr_size_t *outwords);
-
-/**
- * An APR internal function for fast ucs-2 wide Unicode format conversion to 
- * the utf-8 octet-encoded Unicode.  This function is used for filename and 
- * other resource conversions for platforms providing native Unicode support.
- *
- * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
- * when the character code is invalid (in or out of context) and the later
- * when more words were expected, but insufficient words remain.
- */
-APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
-                                                apr_size_t *inwords,
-                                                char *out, 
-                                                apr_size_t *outbytes);
-
-#endif /* def UTF8_H */
--- misc/win32/utf8.c	2004-11-24 23:51:51.000000000 +0100
+++ /dev/null	2005-06-10 15:18:08.000000000 +0200
@@ -1,253 +0,0 @@
-/* Copyright 2000-2004 The Apache Software Foundation
- *
- * 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 "apr.h"
-#include "apr_private.h"
-#include "apr_errno.h"
-#include "apr_arch_utf8.h"
-
-/* Implement the design principal specified by RFC 2718 2.2.5 
- * Guidelines for new URL Schemes - within the APR.
- *
- * Since many architectures support unicode, and UCS2 is the most
- * efficient storage used by those archictures, these functions
- * exist to validate a UCS string.  It is up to the operating system
- * to determine the validitity of the string in the context of it's
- * native language support.  File systems that support filename 
- * characters of 0x80-0xff but have no support of Unicode will find 
- * this function useful only for validating the character sequences 
- * and rejecting poorly encoded strings, if RFC 2718 2.2.5 naming is
- * desired.
- *
- * from RFC 2279 UTF-8, a transformation format of ISO 10646
- *
- *     UCS-4 range (hex.)    UTF-8 octet sequence (binary)
- * 1:2 0000 0000-0000 007F   0xxxxxxx
- * 2:2 0000 0080-0000 07FF   110XXXXx 10xxxxxx
- * 3:2 0000 0800-0000 FFFF   1110XXXX 10Xxxxxx 10xxxxxx
- * 4:4 0001 0000-001F FFFF   11110zXX 10XXxxxx 10xxxxxx 10xxxxxx
- * inv 0020 0000-03FF FFFF   111110XX 10XXXxxx 10xxxxxx 10xxxxxx 10xxxxxx
- * inv 0400 0000-7FFF FFFF   1111110X 10XXXXxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
- *
- * One of the X values must be one for the encoding length to be legit.
- * Neither the z bit, nor the final two forms, are used for ucs-2
- *
- *   "Pairs of UCS-2 values between D800 and DFFF (surrogate pairs in 
- *   Unicode parlance), being actually UCS-4 characters transformed 
- *   through UTF-16, need special treatment: the UTF-16 transformation 
- *   must be undone, yielding a UCS-4 character that is then transformed 
- *   as above."
- *
- * from RFC2781 UTF-16: the compressed ISO 10646 encoding bitmask
- *
- *  U' = U - 0x10000
- *  U' = 000000000000yyyyyyyyyyxxxxxxxxxx
- *                  W1 = 110110yyyyyyyyyy
- *                  W2 = 110111xxxxxxxxxx
- *
- * apr_conv_utf8_to_ucs2 out bytes:sizeof(in) * 1 <= Req <= sizeof(in) * 2
- *
- * apr_conv_ucs2_to_utf8 out words:sizeof(in) / 2 <= Req <= sizeof(in) * 3 / 2
- */
-
-APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
-                                                apr_size_t *inbytes,
-                                                apr_wchar_t *out, 
-                                                apr_size_t *outwords)
-{
-    apr_int64_t newch, mask;
-    apr_size_t expect, eating;
-    int ch;
-    
-    while (*inbytes && *outwords) 
-    {
-        ch = (unsigned char)(*in++);
-        if (!(ch & 0200)) {
-            /* US-ASCII-7 plain text
-             */
-            --*inbytes;
-            --*outwords;
-            *(out++) = ch;
-        }
-        else
-        {
-            if ((ch & 0300) != 0300) { 
-                /* Multibyte Continuation is out of place
-                 */
-                return APR_EINVAL;
-            }
-            else
-            {
-                /* Multibyte Sequence Lead Character
-                 *
-                 * Compute the expected bytes while adjusting
-                 * or lead byte and leading zeros mask.
-                 */
-                mask = 0340;
-                expect = 1;
-                while ((ch & mask) == mask) {
-                    mask |= mask >> 1;
-                    if (++expect > 3) /* (truly 5 for ucs-4) */
-                        return APR_EINVAL;
-                }
-                newch = ch & ~mask;
-                eating = expect + 1;
-                if (*inbytes <= expect)
-                    return APR_INCOMPLETE;
-                /* Reject values of excessive leading 0 bits
-                 * utf-8 _demands_ the shortest possible byte length
-                 */
-                if (expect == 1) {
-                    if (!(newch & 0036))
-                        return APR_EINVAL;
-                }
-                else {
-                    /* Reject values of excessive leading 0 bits
-                     */
-                    if (!newch && !((unsigned char)*in & 0077 & (mask << 1)))
-                        return APR_EINVAL;
-                    if (expect == 2) {
-                        /* Reject values D800-DFFF when not utf16 encoded
-                         * (may not be an appropriate restriction for ucs-4)
-                         */
-                        if (newch == 0015 && ((unsigned char)*in & 0040))
-                            return APR_EINVAL;
-                    }
-                    else if (expect == 3) {
-                        /* Short circuit values > 110000
-                         */
-                        if (newch > 4)
-                            return APR_EINVAL;
-                        if (newch == 4 && ((unsigned char)*in & 0060))
-                            return APR_EINVAL;
-                    }
-                }
-                /* Where the boolean (expect > 2) is true, we will need
-                 * an extra word for the output.
-                 */
-                if (*outwords < (apr_size_t)(expect > 2) + 1) 
-                    break; /* buffer full */
-                while (expect--)
-                {
-                    /* Multibyte Continuation must be legal */
-                    if (((ch = (unsigned char)*(in++)) & 0300) != 0200)
-                        return APR_EINVAL;
-                    newch <<= 6;
-                    newch |= (ch & 0077);
-                }
-                *inbytes -= eating;
-                /* newch is now a true ucs-4 character
-                 *
-                 * now we need to fold to ucs-2
-                 */
-                if (newch < 0x10000) 
-                {
-                    --*outwords;
-                    *(out++) = (apr_wchar_t) newch;
-                }
-                else 
-                {
-                    *outwords -= 2;
-                    newch -= 0x10000;
-                    *(out++) = (apr_wchar_t) (0xD800 | (newch >> 10));
-                    *(out++) = (apr_wchar_t) (0xDC00 | (newch & 0x03FF));                    
-                }
-            }
-        }
-    }
-    /* Buffer full 'errors' aren't errors, the client must inspect both
-     * the inbytes and outwords values
-     */
-    return APR_SUCCESS;
-}
-
-APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
-                                                apr_size_t *inwords,
-                                                char *out, 
-                                                apr_size_t *outbytes)
-{
-    apr_int64_t newch, require;
-    apr_size_t need;
-    char *invout;
-    int ch;
-    
-    while (*inwords && *outbytes) 
-    {
-        ch = (unsigned short)(*in++);
-        if (ch < 0x80)
-        {
-            --*inwords;
-            --*outbytes;
-            *(out++) = (unsigned char) ch;
-        }
-        else 
-        {
-            if ((ch & 0xFC00) == 0xDC00) {
-                /* Invalid Leading ucs-2 Multiword Continuation Character
-                 */
-                return APR_EINVAL;
-            }
-            if ((ch & 0xFC00) == 0xD800) {
-                /* Leading ucs-2 Multiword Character
-                 */
-                if (*inwords < 2) {
-                    /* Missing ucs-2 Multiword Continuation Character
-                     */
-                    return APR_INCOMPLETE;
-                }
-                if (((unsigned short)(*in) & 0xFC00) != 0xDC00) {
-                    /* Invalid ucs-2 Multiword Continuation Character
-                     */
-                    return APR_EINVAL;
-                }
-                newch = (ch & 0x03FF) << 10 | ((unsigned short)(*in++) & 0x03FF);
-                newch += 0x10000;
-            }
-            else {
-                /* ucs-2 Single Word Character
-                 */
-                newch = ch;
-            }
-            /* Determine the absolute minimum utf-8 bytes required
-             */
-            require = newch >> 11;
-            need = 1;
-            while (require)
-                require >>= 5, ++need;
-            if (need >= *outbytes)
-                break; /* Insufficient buffer */
-            *inwords -= (need > 2) + 1;
-            *outbytes -= need + 1;
-            /* Compute the utf-8 characters in last to first order,
-             * calculating the lead character length bits along the way.
-             */
-            ch = 0200;
-            out += need + 1;
-            invout = out;
-            while (need--) {
-                ch |= ch >> 1;
-                *(--invout) = (unsigned char)(0200 | (newch & 0077));
-                newch >>= 6;
-            }
-            /* Compute the lead utf-8 character and move the dest offset
-             */
-            *(--invout) = (unsigned char)(ch | newch);
-        }
-    }
-    /* Buffer full 'errors' aren't errors, the client must inspect both
-     * the inwords and outbytes values
-     */
-    return APR_SUCCESS;    
-}
--- ../../tmp/apr-1.1.1/test/internal/Makefile.in	2005-07-28 15:00:16.513760696 +0200
+++ test/internal/Makefile.in	2005-07-28 15:08:39.291326888 +0200
@@ -14,7 +14,7 @@
 
 LOCAL_LIBS=../../[EMAIL PROTECTED]@.la
 
-CLEAN_TARGETS = [EMAIL PROTECTED]@
+CLEAN_TARGETS = $(NONPORTABLE)
 
 INCDIR=../../include
 INCLUDES=-I$(INCDIR)
--- /dev/null	2005-06-10 15:18:08.000000000 +0200
+++ include/arch/unix/apr_arch_utf8.h	2005-07-28 15:01:55.570701752 +0200
@@ -0,0 +1,55 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * 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.
+ */
+
+#ifndef UTF8_H
+#define UTF8_H
+
+#include "apr.h"
+#include "apr_lib.h"
+#include "apr_errno.h"
+
+/* If we ever support anything more exciting than char... this could move.
+ */
+typedef apr_uint16_t apr_wchar_t;
+
+/**
+ * An APR internal function for fast utf-8 octet-encoded Unicode conversion
+ * to the ucs-2 wide Unicode format.  This function is used for filename and 
+ * other resource conversions for platforms providing native Unicode support.
+ *
+ * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
+ * when the character code is invalid (in or out of context) and the later
+ * when more characters were expected, but insufficient characters remain.
+ */
+APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
+                                                apr_size_t *inbytes,
+                                                apr_wchar_t *out, 
+                                                apr_size_t *outwords);
+
+/**
+ * An APR internal function for fast ucs-2 wide Unicode format conversion to 
+ * the utf-8 octet-encoded Unicode.  This function is used for filename and 
+ * other resource conversions for platforms providing native Unicode support.
+ *
+ * @tip Only the errors APR_EINVAL and APR_INCOMPLETE may occur, the former
+ * when the character code is invalid (in or out of context) and the later
+ * when more words were expected, but insufficient words remain.
+ */
+APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
+                                                apr_size_t *inwords,
+                                                char *out, 
+                                                apr_size_t *outbytes);
+
+#endif /* def UTF8_H */
--- /dev/null	2005-06-10 15:18:08.000000000 +0200
+++ misc/unix/utf8.c	2005-07-28 15:01:31.276395048 +0200
@@ -0,0 +1,253 @@
+/* Copyright 2000-2004 The Apache Software Foundation
+ *
+ * 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 "apr.h"
+#include "apr_private.h"
+#include "apr_errno.h"
+#include "apr_arch_utf8.h"
+
+/* Implement the design principal specified by RFC 2718 2.2.5 
+ * Guidelines for new URL Schemes - within the APR.
+ *
+ * Since many architectures support unicode, and UCS2 is the most
+ * efficient storage used by those archictures, these functions
+ * exist to validate a UCS string.  It is up to the operating system
+ * to determine the validitity of the string in the context of it's
+ * native language support.  File systems that support filename 
+ * characters of 0x80-0xff but have no support of Unicode will find 
+ * this function useful only for validating the character sequences 
+ * and rejecting poorly encoded strings, if RFC 2718 2.2.5 naming is
+ * desired.
+ *
+ * from RFC 2279 UTF-8, a transformation format of ISO 10646
+ *
+ *     UCS-4 range (hex.)    UTF-8 octet sequence (binary)
+ * 1:2 0000 0000-0000 007F   0xxxxxxx
+ * 2:2 0000 0080-0000 07FF   110XXXXx 10xxxxxx
+ * 3:2 0000 0800-0000 FFFF   1110XXXX 10Xxxxxx 10xxxxxx
+ * 4:4 0001 0000-001F FFFF   11110zXX 10XXxxxx 10xxxxxx 10xxxxxx
+ * inv 0020 0000-03FF FFFF   111110XX 10XXXxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * inv 0400 0000-7FFF FFFF   1111110X 10XXXXxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ *
+ * One of the X values must be one for the encoding length to be legit.
+ * Neither the z bit, nor the final two forms, are used for ucs-2
+ *
+ *   "Pairs of UCS-2 values between D800 and DFFF (surrogate pairs in 
+ *   Unicode parlance), being actually UCS-4 characters transformed 
+ *   through UTF-16, need special treatment: the UTF-16 transformation 
+ *   must be undone, yielding a UCS-4 character that is then transformed 
+ *   as above."
+ *
+ * from RFC2781 UTF-16: the compressed ISO 10646 encoding bitmask
+ *
+ *  U' = U - 0x10000
+ *  U' = 000000000000yyyyyyyyyyxxxxxxxxxx
+ *                  W1 = 110110yyyyyyyyyy
+ *                  W2 = 110111xxxxxxxxxx
+ *
+ * apr_conv_utf8_to_ucs2 out bytes:sizeof(in) * 1 <= Req <= sizeof(in) * 2
+ *
+ * apr_conv_ucs2_to_utf8 out words:sizeof(in) / 2 <= Req <= sizeof(in) * 3 / 2
+ */
+
+APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, 
+                                                apr_size_t *inbytes,
+                                                apr_wchar_t *out, 
+                                                apr_size_t *outwords)
+{
+    apr_int64_t newch, mask;
+    apr_size_t expect, eating;
+    int ch;
+    
+    while (*inbytes && *outwords) 
+    {
+        ch = (unsigned char)(*in++);
+        if (!(ch & 0200)) {
+            /* US-ASCII-7 plain text
+             */
+            --*inbytes;
+            --*outwords;
+            *(out++) = ch;
+        }
+        else
+        {
+            if ((ch & 0300) != 0300) { 
+                /* Multibyte Continuation is out of place
+                 */
+                return APR_EINVAL;
+            }
+            else
+            {
+                /* Multibyte Sequence Lead Character
+                 *
+                 * Compute the expected bytes while adjusting
+                 * or lead byte and leading zeros mask.
+                 */
+                mask = 0340;
+                expect = 1;
+                while ((ch & mask) == mask) {
+                    mask |= mask >> 1;
+                    if (++expect > 3) /* (truly 5 for ucs-4) */
+                        return APR_EINVAL;
+                }
+                newch = ch & ~mask;
+                eating = expect + 1;
+                if (*inbytes <= expect)
+                    return APR_INCOMPLETE;
+                /* Reject values of excessive leading 0 bits
+                 * utf-8 _demands_ the shortest possible byte length
+                 */
+                if (expect == 1) {
+                    if (!(newch & 0036))
+                        return APR_EINVAL;
+                }
+                else {
+                    /* Reject values of excessive leading 0 bits
+                     */
+                    if (!newch && !((unsigned char)*in & 0077 & (mask << 1)))
+                        return APR_EINVAL;
+                    if (expect == 2) {
+                        /* Reject values D800-DFFF when not utf16 encoded
+                         * (may not be an appropriate restriction for ucs-4)
+                         */
+                        if (newch == 0015 && ((unsigned char)*in & 0040))
+                            return APR_EINVAL;
+                    }
+                    else if (expect == 3) {
+                        /* Short circuit values > 110000
+                         */
+                        if (newch > 4)
+                            return APR_EINVAL;
+                        if (newch == 4 && ((unsigned char)*in & 0060))
+                            return APR_EINVAL;
+                    }
+                }
+                /* Where the boolean (expect > 2) is true, we will need
+                 * an extra word for the output.
+                 */
+                if (*outwords < (apr_size_t)(expect > 2) + 1) 
+                    break; /* buffer full */
+                while (expect--)
+                {
+                    /* Multibyte Continuation must be legal */
+                    if (((ch = (unsigned char)*(in++)) & 0300) != 0200)
+                        return APR_EINVAL;
+                    newch <<= 6;
+                    newch |= (ch & 0077);
+                }
+                *inbytes -= eating;
+                /* newch is now a true ucs-4 character
+                 *
+                 * now we need to fold to ucs-2
+                 */
+                if (newch < 0x10000) 
+                {
+                    --*outwords;
+                    *(out++) = (apr_wchar_t) newch;
+                }
+                else 
+                {
+                    *outwords -= 2;
+                    newch -= 0x10000;
+                    *(out++) = (apr_wchar_t) (0xD800 | (newch >> 10));
+                    *(out++) = (apr_wchar_t) (0xDC00 | (newch & 0x03FF));                    
+                }
+            }
+        }
+    }
+    /* Buffer full 'errors' aren't errors, the client must inspect both
+     * the inbytes and outwords values
+     */
+    return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, 
+                                                apr_size_t *inwords,
+                                                char *out, 
+                                                apr_size_t *outbytes)
+{
+    apr_int64_t newch, require;
+    apr_size_t need;
+    char *invout;
+    int ch;
+    
+    while (*inwords && *outbytes) 
+    {
+        ch = (unsigned short)(*in++);
+        if (ch < 0x80)
+        {
+            --*inwords;
+            --*outbytes;
+            *(out++) = (unsigned char) ch;
+        }
+        else 
+        {
+            if ((ch & 0xFC00) == 0xDC00) {
+                /* Invalid Leading ucs-2 Multiword Continuation Character
+                 */
+                return APR_EINVAL;
+            }
+            if ((ch & 0xFC00) == 0xD800) {
+                /* Leading ucs-2 Multiword Character
+                 */
+                if (*inwords < 2) {
+                    /* Missing ucs-2 Multiword Continuation Character
+                     */
+                    return APR_INCOMPLETE;
+                }
+                if (((unsigned short)(*in) & 0xFC00) != 0xDC00) {
+                    /* Invalid ucs-2 Multiword Continuation Character
+                     */
+                    return APR_EINVAL;
+                }
+                newch = (ch & 0x03FF) << 10 | ((unsigned short)(*in++) & 0x03FF);
+                newch += 0x10000;
+            }
+            else {
+                /* ucs-2 Single Word Character
+                 */
+                newch = ch;
+            }
+            /* Determine the absolute minimum utf-8 bytes required
+             */
+            require = newch >> 11;
+            need = 1;
+            while (require)
+                require >>= 5, ++need;
+            if (need >= *outbytes)
+                break; /* Insufficient buffer */
+            *inwords -= (need > 2) + 1;
+            *outbytes -= need + 1;
+            /* Compute the utf-8 characters in last to first order,
+             * calculating the lead character length bits along the way.
+             */
+            ch = 0200;
+            out += need + 1;
+            invout = out;
+            while (need--) {
+                ch |= ch >> 1;
+                *(--invout) = (unsigned char)(0200 | (newch & 0077));
+                newch >>= 6;
+            }
+            /* Compute the lead utf-8 character and move the dest offset
+             */
+            *(--invout) = (unsigned char)(ch | newch);
+        }
+    }
+    /* Buffer full 'errors' aren't errors, the client must inspect both
+     * the inwords and outbytes values
+     */
+    return APR_SUCCESS;    
+}
--- ../../tmp/apr-1.1.1/test/internal/Makefile.in	2004-11-24 23:51:51.000000000 +0100
+++ test/internal/Makefile.in	2005-07-28 15:26:26.860031776 +0200
@@ -1,8 +1,10 @@
 srcdir = @srcdir@
 VPATH = @srcdir@
+top_srcdir = @top_srcdir@
 
 NONPORTABLE = \
-	[EMAIL PROTECTED]@
+	[EMAIL PROTECTED]@ \
+	[EMAIL PROTECTED]@
 
 PROGRAMS = \
 
@@ -13,10 +15,13 @@
 
 LOCAL_LIBS=../../[EMAIL PROTECTED]@.la
 
-CLEAN_TARGETS = [EMAIL PROTECTED]@
+CLEAN_TARGETS = $(NONPORTABLE)
 
 INCDIR=../../include
-INCLUDES=-I$(INCDIR)
+
+OSDIR=$(top_srcdir)/include/arch/@OSDIR@
+DEFOSDIR=$(INCDIR)/arch/@DEFAULT_OSDIR@
+INCLUDES=-I$(INCDIR) -I$(OSDIR)
 
 CFLAGS=$(MY_CFLAGS)
 
@@ -34,4 +39,7 @@
 [EMAIL PROTECTED]@: testregex.lo $(LOCAL_LIBS)
 	$(LINK) testregex.lo $(LOCAL_LIBS) $(ALL_LIBS)
 
[EMAIL PROTECTED]@: testucs.lo $(LOCAL_LIBS)
+	$(LINK) testucs.lo $(LOCAL_LIBS) $(ALL_LIBS)
+
 # DO NOT REMOVE

Reply via email to