Back to index

php5  5.3.10
Defines | Functions | Variables
mbfilter_utf16.c File Reference
#include "mbfilter.h"
#include "mbfilter_utf16.h"

Go to the source code of this file.

Defines

#define CK(statement)   do { if ((statement) < 0) return (-1); } while (0)

Functions

int mbfl_filt_conv_utf16_wchar (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_utf16be_wchar (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_wchar_utf16be (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_utf16le_wchar (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_wchar_utf16le (int c, mbfl_convert_filter *filter)

Variables

static const char * mbfl_encoding_utf16_aliases [] = {"utf16", NULL}
const mbfl_encoding mbfl_encoding_utf16
const mbfl_encoding mbfl_encoding_utf16be
const mbfl_encoding mbfl_encoding_utf16le

Define Documentation

#define CK (   statement)    do { if ((statement) < 0) return (-1); } while (0)

Definition at line 120 of file mbfilter_utf16.c.


Function Documentation

int mbfl_filt_conv_utf16_wchar ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 125 of file mbfilter_utf16.c.

{
       int n, endian;

       endian = filter->status & 0xff00;
       switch (filter->status & 0x0f) {
       case 0:
              if (endian) {
                     n = c & 0xff;
              } else {
                     n = (c & 0xff) << 8;
              }
              filter->cache |= n;
              filter->status++;
              break;
       default:
              if (endian) {
                     n = (c & 0xff) << 8;
              } else {
                     n = c & 0xff;
              }
              n |= filter->cache & 0xffff;
              filter->status &= ~0x0f;
              if (n >= 0xd800 && n < 0xdc00) {
                     filter->cache = ((n & 0x3ff) << 16) + 0x400000;
              } else if (n >= 0xdc00 && n < 0xe000) {
                     n &= 0x3ff;
                     n |= (filter->cache & 0xfff0000) >> 6;
                     filter->cache = 0;
                     if (n >= MBFL_WCSPLANE_SUPMIN && n < MBFL_WCSPLANE_SUPMAX) {
                            CK((*filter->output_function)(n, filter->data));
                     } else {             /* illegal character */
                            n &= MBFL_WCSGROUP_MASK;
                            n |= MBFL_WCSGROUP_THROUGH;
                            CK((*filter->output_function)(n, filter->data));
                     }
              } else {
                     int is_first = filter->status & 0x10;
                     filter->cache = 0;
                     filter->status |= 0x10;
                     if (!is_first) {
                            if (n == 0xfffe) {
                                   if (endian) {
                                          filter->status &= ~0x100;          /* big-endian */
                                   } else {
                                          filter->status |= 0x100;           /* little-endian */
                                   }
                                   break;
                            } else if (n == 0xfeff) {
                                   break;
                            }
                     }
                     CK((*filter->output_function)(n, filter->data));
              }
              break;
       }

       return c;
}
int mbfl_filt_conv_utf16be_wchar ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 188 of file mbfilter_utf16.c.

{
       int n;

       switch (filter->status) {
       case 0:
              filter->status = 1;
              n = (c & 0xff) << 8;
              filter->cache |= n;
              break;
       default:
              filter->status = 0;
              n = (filter->cache & 0xff00) | (c & 0xff);
              if (n >= 0xd800 && n < 0xdc00) {
                     filter->cache = ((n & 0x3ff) << 16) + 0x400000;
              } else if (n >= 0xdc00 && n < 0xe000) {
                     n &= 0x3ff;
                     n |= (filter->cache & 0xfff0000) >> 6;
                     filter->cache = 0;
                     if (n >= MBFL_WCSPLANE_SUPMIN && n < MBFL_WCSPLANE_SUPMAX) {
                            CK((*filter->output_function)(n, filter->data));
                     } else {             /* illegal character */
                            n &= MBFL_WCSGROUP_MASK;
                            n |= MBFL_WCSGROUP_THROUGH;
                            CK((*filter->output_function)(n, filter->data));
                     }
              } else {
                     filter->cache = 0;
                     CK((*filter->output_function)(n, filter->data));
              }
              break;
       }

       return c;
}
int mbfl_filt_conv_utf16le_wchar ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 253 of file mbfilter_utf16.c.

{
       int n;

       switch (filter->status) {
       case 0:
              filter->status = 1;
              n = c & 0xff;
              filter->cache |= n;
              break;
       default:
              filter->status = 0;
              n = (filter->cache & 0xff) | ((c & 0xff) << 8);
              if (n >= 0xd800 && n < 0xdc00) {
                     filter->cache = ((n & 0x3ff) << 16) + 0x400000;
              } else if (n >= 0xdc00 && n < 0xe000) {
                     n &= 0x3ff;
                     n |= (filter->cache & 0xfff0000) >> 6;
                     filter->cache = 0;
                     if (n >= MBFL_WCSPLANE_SUPMIN && n < MBFL_WCSPLANE_SUPMAX) {
                            CK((*filter->output_function)(n, filter->data));
                     } else {             /* illegal character */
                            n &= MBFL_WCSGROUP_MASK;
                            n |= MBFL_WCSGROUP_THROUGH;
                            CK((*filter->output_function)(n, filter->data));
                     }
              } else {
                     filter->cache = 0;
                     CK((*filter->output_function)(n, filter->data));
              }
              break;
       }

       return c;
}
int mbfl_filt_conv_wchar_utf16be ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 227 of file mbfilter_utf16.c.

{
       int n;

       if (c >= 0 && c < MBFL_WCSPLANE_UCS2MAX) {
              CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
              CK((*filter->output_function)(c & 0xff, filter->data));
       } else if (c >= MBFL_WCSPLANE_SUPMIN && c < MBFL_WCSPLANE_SUPMAX) {
              n = ((c >> 10) - 0x40) | 0xd800;
              CK((*filter->output_function)((n >> 8) & 0xff, filter->data));
              CK((*filter->output_function)(n & 0xff, filter->data));
              n = (c & 0x3ff) | 0xdc00;
              CK((*filter->output_function)((n >> 8) & 0xff, filter->data));
              CK((*filter->output_function)(n & 0xff, filter->data));
       } else {
              if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
                     CK(mbfl_filt_conv_illegal_output(c, filter));
              }
       }

       return c;
}

Here is the call graph for this function:

int mbfl_filt_conv_wchar_utf16le ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 292 of file mbfilter_utf16.c.

{
       int n;

       if (c >= 0 && c < MBFL_WCSPLANE_UCS2MAX) {
              CK((*filter->output_function)(c & 0xff, filter->data));
              CK((*filter->output_function)((c >> 8) & 0xff, filter->data));
       } else if (c >= MBFL_WCSPLANE_SUPMIN && c < MBFL_WCSPLANE_SUPMAX) {
              n = ((c >> 10) - 0x40) | 0xd800;
              CK((*filter->output_function)(n & 0xff, filter->data));
              CK((*filter->output_function)((n >> 8) & 0xff, filter->data));
              n = (c & 0x3ff) | 0xdc00;
              CK((*filter->output_function)(n & 0xff, filter->data));
              CK((*filter->output_function)((n >> 8) & 0xff, filter->data));
       } else {
              if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
                     CK(mbfl_filt_conv_illegal_output(c, filter));
              }
       }

       return c;
}

Here is the call graph for this function:


Variable Documentation

Initial value:
 {
       mbfl_no_encoding_utf16,
       "UTF-16",
       "UTF-16",
       (const char *(*)[])&mbfl_encoding_utf16_aliases,
       NULL,
       MBFL_ENCTYPE_MWC2BE
}

Definition at line 39 of file mbfilter_utf16.c.

const char* mbfl_encoding_utf16_aliases[] = {"utf16", NULL} [static]

Definition at line 37 of file mbfilter_utf16.c.

Initial value:
 {
       mbfl_no_encoding_utf16be,
       "UTF-16BE",
       "UTF-16BE",
       NULL,
       NULL,
       MBFL_ENCTYPE_MWC2BE
}

Definition at line 48 of file mbfilter_utf16.c.

Initial value:
 {
       mbfl_no_encoding_utf16le,
       "UTF-16LE",
       "UTF-16LE",
       NULL,
       NULL,
       MBFL_ENCTYPE_MWC2LE
}

Definition at line 57 of file mbfilter_utf16.c.