Back to index

php5  5.3.10
Defines | Functions | Variables
utf16_be.c File Reference
#include "regenc.h"

Go to the source code of this file.

Defines

#define UTF16_IS_SURROGATE_FIRST(c)   (c >= 0xd8 && c <= 0xdb)
#define UTF16_IS_SURROGATE_SECOND(c)   (c >= 0xdc && c <= 0xdf)

Functions

static int utf16be_mbc_enc_len (const UChar *p)
static int utf16be_is_mbc_newline (const UChar *p, const UChar *end)
static OnigCodePoint utf16be_mbc_to_code (const UChar *p, const UChar *end)
static int utf16be_code_to_mbclen (OnigCodePoint code)
static int utf16be_code_to_mbc (OnigCodePoint code, UChar *buf)
static int utf16be_mbc_to_normalize (OnigAmbigType flag, const UChar **pp, const UChar *end, UChar *lower)
static int utf16be_is_mbc_ambiguous (OnigAmbigType flag, const UChar **pp, const UChar *end)
static UCharutf16be_left_adjust_char_head (const UChar *start, const UChar *s)

Variables

static const int EncLen_UTF16 []
OnigEncodingType OnigEncodingUTF16_BE

Define Documentation

#define UTF16_IS_SURROGATE_FIRST (   c)    (c >= 0xd8 && c <= 0xdb)

Definition at line 32 of file utf16_be.c.

#define UTF16_IS_SURROGATE_SECOND (   c)    (c >= 0xdc && c <= 0xdf)

Definition at line 33 of file utf16_be.c.


Function Documentation

static int utf16be_code_to_mbc ( OnigCodePoint  code,
UChar buf 
) [static]

Definition at line 99 of file utf16_be.c.

{
  UChar* p = buf;

  if (code > 0xffff) {
    unsigned int plane, high;

    plane = code >> 16;
    *p++ = (plane >> 2) + 0xd8;
    high = (code & 0xff00) >> 8;
    *p++ = ((plane & 0x03) << 6) + (high >> 2);
    *p++ = (high & 0x02) + 0xdc;
    *p   = (UChar )(code & 0xff);
    return 4;
  }
  else {
    *p++ = (UChar )((code & 0xff00) >> 8);
    *p++ = (UChar )(code & 0xff);
    return 2;
  }
}
static int utf16be_code_to_mbclen ( OnigCodePoint  code) [static]

Definition at line 93 of file utf16_be.c.

{
  return (code > 0xffff ? 4 : 2);
}
static int utf16be_is_mbc_ambiguous ( OnigAmbigType  flag,
const UChar **  pp,
const UChar end 
) [static]

Definition at line 158 of file utf16_be.c.

{
  const UChar* p = *pp;

  (*pp) += EncLen_UTF16[*p];

  if (*p == 0) {
    int c, v;

    p++;
    if (((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
        ONIGENC_IS_MBC_ASCII(p)) ||
       ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0 &&
        !ONIGENC_IS_MBC_ASCII(p))) {
      c = *p;
      v = ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(c,
             (ONIGENC_CTYPE_UPPER | ONIGENC_CTYPE_LOWER));

      if ((v | ONIGENC_CTYPE_LOWER) != 0) {
        /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */
        if (c >= 0xaa && c <= 0xba)
          return FALSE;
        else
          return TRUE;
      }
      return (v != 0 ? TRUE : FALSE);
    }
  }

  return FALSE;
}
static int utf16be_is_mbc_newline ( const UChar p,
const UChar end 
) [static]

Definition at line 61 of file utf16_be.c.

{
  if (p + 1 < end) {
    if (*(p+1) == 0x0a && *p == 0x00)
      return 1;
#ifdef USE_UNICODE_ALL_LINE_TERMINATORS
    if ((*(p+1) == 0x0d || *(p+1) == 0x85) && *p == 0x00)
      return 1;
    if (*p == 0x20 && (*(p+1) == 0x29 || *(p+1) == 0x28))
      return 1;
#endif
  }
  return 0;
}
static UChar* utf16be_left_adjust_char_head ( const UChar start,
const UChar s 
) [static]

Definition at line 191 of file utf16_be.c.

{
  if (s <= start) return (UChar* )s;

  if ((s - start) % 2 == 1) {
    s--;
  }

  if (UTF16_IS_SURROGATE_SECOND(*s) && s > start + 1)
    s -= 2;

  return (UChar* )s;
}
static int utf16be_mbc_enc_len ( const UChar p) [static]

Definition at line 55 of file utf16_be.c.

{
  return EncLen_UTF16[*p];
}
static OnigCodePoint utf16be_mbc_to_code ( const UChar p,
const UChar end 
) [static]

Definition at line 77 of file utf16_be.c.

{
  OnigCodePoint code;

  if (UTF16_IS_SURROGATE_FIRST(*p)) {
    code = ((((p[0] - 0xd8) << 2) + ((p[1] & 0xc0) >> 6) + 1) << 16)
         + ((((p[1] & 0x3f) << 2) + (p[2] - 0xdc)) << 8)
         + p[3];
  }
  else {
    code = p[0] * 256 + p[1];
  }
  return code;
}
static int utf16be_mbc_to_normalize ( OnigAmbigType  flag,
const UChar **  pp,
const UChar end,
UChar lower 
) [static]

Definition at line 122 of file utf16_be.c.

{
  const UChar* p = *pp;

  if (*p == 0) {
    p++;
    *lower++ = '\0';
    if (((flag & ONIGENC_AMBIGUOUS_MATCH_ASCII_CASE) != 0 &&
        ONIGENC_IS_MBC_ASCII(p)) ||
       ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0 &&
        !ONIGENC_IS_MBC_ASCII(p))) {
      *lower = ONIGENC_ISO_8859_1_TO_LOWER_CASE(*p);
    }
    else {
      *lower = *p;
    }

    (*pp) += 2;
    return 2;  /* return byte length of converted char to lower */
  }
  else {
    int len;
    len = EncLen_UTF16[*p];
    if (lower != p) {
      int i;
      for (i = 0; i < len; i++) {
       *lower++ = *p++;
      }
    }
    (*pp) += len;
    return len; /* return byte length of converted char to lower */
  }
}

Variable Documentation

const int EncLen_UTF16[] [static]
Initial value:
 {
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
}

Definition at line 35 of file utf16_be.c.