PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - mbstring/oniguruma/enc - utf16_be.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 73
Code covered: 0.0 % Executed lines: 0
Legend: not executed executed

       1                 : /**********************************************************************
       2                 :   utf16_be.c -  Oniguruma (regular expression library)
       3                 : **********************************************************************/
       4                 : /*-
       5                 :  * Copyright (c) 2002-2009  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
       6                 :  * All rights reserved.
       7                 :  *
       8                 :  * Redistribution and use in source and binary forms, with or without
       9                 :  * modification, are permitted provided that the following conditions
      10                 :  * are met:
      11                 :  * 1. Redistributions of source code must retain the above copyright
      12                 :  *    notice, this list of conditions and the following disclaimer.
      13                 :  * 2. Redistributions in binary form must reproduce the above copyright
      14                 :  *    notice, this list of conditions and the following disclaimer in the
      15                 :  *    documentation and/or other materials provided with the distribution.
      16                 :  *
      17                 :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
      18                 :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      19                 :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      20                 :  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
      21                 :  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      22                 :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      23                 :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      24                 :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      25                 :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      26                 :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      27                 :  * SUCH DAMAGE.
      28                 :  */
      29                 : 
      30                 : #include "regenc.h"
      31                 : 
      32                 : #define UTF16_IS_SURROGATE_FIRST(c)    (c >= 0xd8 && c <= 0xdb)
      33                 : #define UTF16_IS_SURROGATE_SECOND(c)   (c >= 0xdc && c <= 0xdf)
      34                 : 
      35                 : static const int EncLen_UTF16[] = {
      36                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      37                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      38                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      39                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      40                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      41                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      42                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      43                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      44                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      45                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      46                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      47                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      48                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      49                 :   2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2,
      50                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      51                 :   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
      52                 : };
      53                 : 
      54                 : static int
      55                 : utf16be_mbc_enc_len(const UChar* p)
      56               0 : {
      57               0 :   return EncLen_UTF16[*p];
      58                 : }
      59                 : 
      60                 : static int
      61                 : utf16be_is_mbc_newline(const UChar* p, const UChar* end)
      62               0 : {
      63               0 :   if (p + 1 < end) {
      64               0 :     if (*(p+1) == 0x0a && *p == 0x00)
      65               0 :       return 1;
      66                 : #ifdef USE_UNICODE_ALL_LINE_TERMINATORS
      67                 :     if ((*(p+1) == 0x0d || *(p+1) == 0x85) && *p == 0x00)
      68                 :       return 1;
      69                 :     if (*p == 0x20 && (*(p+1) == 0x29 || *(p+1) == 0x28))
      70                 :       return 1;
      71                 : #endif
      72                 :   }
      73               0 :   return 0;
      74                 : }
      75                 : 
      76                 : static OnigCodePoint
      77                 : utf16be_mbc_to_code(const UChar* p, const UChar* end)
      78               0 : {
      79                 :   OnigCodePoint code;
      80                 : 
      81               0 :   if (UTF16_IS_SURROGATE_FIRST(*p)) {
      82               0 :     code = ((((p[0] - 0xd8) << 2) + ((p[1] & 0xc0) >> 6) + 1) << 16)
      83                 :          + ((((p[1] & 0x3f) << 2) + (p[2] - 0xdc)) << 8)
      84                 :          + p[3];
      85                 :   }
      86                 :   else {
      87               0 :     code = p[0] * 256 + p[1];
      88                 :   }
      89               0 :   return code;
      90                 : }
      91                 : 
      92                 : static int
      93                 : utf16be_code_to_mbclen(OnigCodePoint code)
      94               0 : {
      95               0 :   return (code > 0xffff ? 4 : 2);
      96                 : }
      97                 : 
      98                 : static int
      99                 : utf16be_code_to_mbc(OnigCodePoint code, UChar *buf)
     100               0 : {
     101               0 :   UChar* p = buf;
     102                 : 
     103               0 :   if (code > 0xffff) {
     104                 :     unsigned int plane, high;
     105                 : 
     106               0 :     plane = code >> 16;
     107               0 :     *p++ = (plane >> 2) + 0xd8;
     108               0 :     high = (code & 0xff00) >> 8;
     109               0 :     *p++ = ((plane & 0x03) << 6) + (high >> 2);
     110               0 :     *p++ = (high & 0x02) + 0xdc;
     111               0 :     *p   = (UChar )(code & 0xff);
     112               0 :     return 4;
     113                 :   }
     114                 :   else {
     115               0 :     *p++ = (UChar )((code & 0xff00) >> 8);
     116               0 :     *p++ = (UChar )(code & 0xff);
     117               0 :     return 2;
     118                 :   }
     119                 : }
     120                 : 
     121                 : static int
     122                 : utf16be_mbc_to_normalize(OnigAmbigType flag, const UChar** pp, const UChar* end,
     123                 :                          UChar* lower)
     124               0 : {
     125               0 :   const UChar* p = *pp;
     126                 : 
     127               0 :   if (*p == 0) {
     128               0 :     p++;
     129               0 :     if (end > p + 2 &&
     130                 :         (flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0 &&
     131                 :         ((*p == 's' && *(p+2) == 's') ||
     132                 :         ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
     133                 :          (*p == 'S' && *(p+2) == 'S'))) &&
     134                 :         *(p+1) == 0) {
     135               0 :       *lower++ = '\0';
     136               0 :       *lower   = 0xdf;
     137               0 :       (*pp) += 4;
     138               0 :       return 2;
     139                 :     }
     140                 : 
     141               0 :     *lower++ = '\0';
     142               0 :     if (((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
     143                 :          ONIGENC_IS_MBC_ASCII(p)) ||
     144                 :         ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0 &&
     145                 :          !ONIGENC_IS_MBC_ASCII(p))) {
     146               0 :       *lower = ONIGENC_ISO_8859_1_TO_LOWER_CASE(*p);
     147                 :     }
     148                 :     else {
     149               0 :       *lower = *p;
     150                 :     }
     151                 : 
     152               0 :     (*pp) += 2;
     153               0 :     return 2;  /* return byte length of converted char to lower */
     154                 :   }
     155                 :   else {
     156                 :     int len;
     157               0 :     len = EncLen_UTF16[*p];
     158               0 :     if (lower != p) {
     159                 :       int i;
     160               0 :       for (i = 0; i < len; i++) {
     161               0 :         *lower++ = *p++;
     162                 :       }
     163                 :     }
     164               0 :     (*pp) += len;
     165               0 :     return len; /* return byte length of converted char to lower */
     166                 :   }
     167                 : }
     168                 : 
     169                 : static int
     170                 : utf16be_is_mbc_ambiguous(OnigAmbigType flag, const UChar** pp, const UChar* end)
     171               0 : {
     172               0 :   const UChar* p = *pp;
     173                 : 
     174               0 :   (*pp) += EncLen_UTF16[*p];
     175                 : 
     176               0 :   if (*p == 0) {
     177                 :     int c, v;
     178                 : 
     179               0 :     p++;
     180               0 :     if ((flag & ONIGENC_AMBIGUOUS_MATCH_COMPOUND) != 0) {
     181               0 :       if (end > p + 2 &&
     182                 :           ((*p == 's' && *(p+2) == 's') ||
     183                 :            ((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
     184                 :             (*p == 'S' && *(p+2) == 'S'))) &&
     185                 :           *(p+1) == 0) {
     186               0 :         (*pp) += 2;
     187               0 :         return TRUE;
     188                 :       }
     189               0 :       else if (*p == 0xdf) {
     190               0 :         return TRUE;
     191                 :       }
     192                 :     }
     193                 : 
     194               0 :     if (((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
     195                 :          ONIGENC_IS_MBC_ASCII(p)) ||
     196                 :         ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0 &&
     197                 :          !ONIGENC_IS_MBC_ASCII(p))) {
     198               0 :       c = *p;
     199               0 :       v = ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(c,
     200                 :               (ONIGENC_CTYPE_UPPER | ONIGENC_CTYPE_LOWER));
     201                 : 
     202                 :       if ((v | ONIGENC_CTYPE_LOWER) != 0) {
     203                 :         /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */
     204               0 :         if (c >= 0xaa && c <= 0xba)
     205               0 :           return FALSE;
     206                 :         else
     207               0 :           return TRUE;
     208                 :       }
     209                 :       return (v != 0 ? TRUE : FALSE);
     210                 :     }
     211                 :   }
     212                 : 
     213               0 :   return FALSE;
     214                 : }
     215                 : 
     216                 : static UChar*
     217                 : utf16be_left_adjust_char_head(const UChar* start, const UChar* s)
     218               0 : {
     219               0 :   if (s <= start) return (UChar* )s;
     220                 : 
     221               0 :   if ((s - start) % 2 == 1) {
     222               0 :     s--;
     223                 :   }
     224                 : 
     225               0 :   if (UTF16_IS_SURROGATE_SECOND(*s) && s > start + 1)
     226               0 :     s -= 2;
     227                 : 
     228               0 :   return (UChar* )s;
     229                 : }
     230                 : 
     231                 : OnigEncodingType OnigEncodingUTF16_BE = {
     232                 :   utf16be_mbc_enc_len,
     233                 :   "UTF-16BE",   /* name */
     234                 :   4,            /* max byte length */
     235                 :   2,            /* min byte length */
     236                 :   (ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE |
     237                 :    ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE |
     238                 :    ONIGENC_AMBIGUOUS_MATCH_COMPOUND),
     239                 :   {
     240                 :       (OnigCodePoint )'\\'                       /* esc */
     241                 :     , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar '.'  */
     242                 :     , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anytime '*'  */
     243                 :     , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* zero or one time '?' */
     244                 :     , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* one or more time '+' */
     245                 :     , (OnigCodePoint )ONIG_INEFFECTIVE_META_CHAR /* anychar anytime */
     246                 :   },
     247                 :   utf16be_is_mbc_newline,
     248                 :   utf16be_mbc_to_code,
     249                 :   utf16be_code_to_mbclen,
     250                 :   utf16be_code_to_mbc,
     251                 :   utf16be_mbc_to_normalize,
     252                 :   utf16be_is_mbc_ambiguous,
     253                 :   onigenc_iso_8859_1_get_all_pair_ambig_codes,
     254                 :   onigenc_ess_tsett_get_all_comp_ambig_codes,
     255                 :   onigenc_unicode_is_code_ctype,
     256                 :   onigenc_unicode_get_ctype_code_range,
     257                 :   utf16be_left_adjust_char_head,
     258                 :   onigenc_always_false_is_allowed_reverse_match
     259                 : };

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:12 +0000 (5 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.