]> granicus.if.org Git - php/commitdiff
Skip BOM for UTF-16/32 converters when setting subst char.
authorAndrei Zmievski <andrei@php.net>
Mon, 27 Mar 2006 03:17:49 +0000 (03:17 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 27 Mar 2006 03:17:49 +0000 (03:17 +0000)
Zend/zend_unicode.c

index f72ea784dee6c51d2de7371003b58ac486102171..753681c051f33ad6302d4210dc7e7cb922bace5d 100644 (file)
@@ -108,7 +108,7 @@ void zend_set_converter_error_mode(UConverter *conv, zend_conv_direction directi
 /* {{{ zend_set_converter_subst_char */
 void zend_set_converter_subst_char(UConverter *conv, UChar *subst_char)
 {
-       char dest[8];
+       char dest[8], *dest_ptr;
        int8_t dest_len = 8;
        UErrorCode status = U_ZERO_ERROR;
        UErrorCode temp = U_ZERO_ERROR;
@@ -126,7 +126,25 @@ void zend_set_converter_subst_char(UConverter *conv, UChar *subst_char)
                zend_error(E_WARNING, "Could not set substitution character for the converter");
                return;
        }
-       ucnv_setSubstChars(conv, dest, dest_len, &status);
+
+       /* skip BOM for UTF-16/32 converters */
+       switch (ucnv_getType(conv)) {
+               case UCNV_UTF16:
+                       dest_ptr = dest + 2;
+                       dest_len -= 2;
+                       break;
+
+               case UCNV_UTF32:
+                       dest_ptr = dest + 4;
+                       dest_len -= 4;
+                       break;
+
+               default:
+                       dest_ptr = dest;
+                       break;
+       }
+
+       ucnv_setSubstChars(conv, dest_ptr, dest_len, &status);
        if (status == U_ILLEGAL_ARGUMENT_ERROR) {
                zend_error(E_WARNING, "Substitution character byte sequence is too short or long for this converter");
                return;