Back to index

php5  5.3.10
Functions | Variables
mbfilter_htmlent.h File Reference
#include "mbfilter.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mbfl_filt_conv_html_dec_ctor (mbfl_convert_filter *filter)
void mbfl_filt_conv_html_dec_dtor (mbfl_convert_filter *filter)
int mbfl_filt_conv_html_enc (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_html_enc_flush (mbfl_convert_filter *filter)
int mbfl_filt_conv_html_dec (int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_html_dec_flush (mbfl_convert_filter *filter)

Variables

const mbfl_encoding mbfl_encoding_html_ent

Function Documentation

int mbfl_filt_conv_html_dec ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 179 of file mbfilter_htmlent.c.

{
       int  pos, ent = 0;
       mbfl_html_entity_entry *entity;
       char *buffer = (char*)filter->opaque;

       if (!filter->status) {
              if (c == '&' ) {
                     filter->status = 1;
                     buffer[0] = '&';
              } else {
                     CK((*filter->output_function)(c, filter->data));
              }
       } else {
              if (c == ';') {
                     if (buffer[1]=='#') {
                            if (filter->status > 2 && (buffer[2] == 'x' || buffer[2] == 'X')) {
                                   if (filter->status > 3) {
                                          /* numeric entity */
                                          for (pos=3; pos<filter->status; pos++) {
                                                 int v =  buffer[pos];
                                                 if (v >= '0' && v <= '9') {
                                                        v = v - '0';
                                                 } else if (v >= 'A' && v <= 'F') {
                                                        v = v - 'A' + 10;
                                                 } else if (v >= 'a' && v <= 'f') {
                                                        v = v - 'a' + 10;
                                                 } else {
                                                        ent = -1;
                                                        break;
                                                 }
                                                 ent = ent * 16 + v;
                                          }
                                   } else {
                                          ent = -1;
                                   }
                            } else {
                                   /* numeric entity */
                                   if (filter->status > 2) {
                                          for (pos=2; pos<filter->status; pos++) {
                                                 int v = buffer[pos];
                                                 if (v >= '0' && v <= '9') {
                                                        v = v - '0';
                                                 } else {
                                                        ent = -1;
                                                        break;
                                                 }
                                                 ent = ent*10 + v;
                                          }
                                   } else {
                                          ent = -1;
                                   }
                            }
                            if (ent >= 0 && ent < 0x110000) {
                                   CK((*filter->output_function)(ent, filter->data));
                            } else {
                                   for (pos = 0; pos < filter->status; pos++) {
                                          CK((*filter->output_function)(buffer[pos], filter->data));
                                   }
                                   CK((*filter->output_function)(c, filter->data));
                            }
                            filter->status = 0;
                            /*php_error_docref("ref.mbstring" TSRMLS_CC, E_NOTICE, "mbstring decoded '%s'=%d", buffer, ent);*/
                     } else {
                            /* named entity */
                            buffer[filter->status] = 0;
                            entity = (mbfl_html_entity_entry *)mbfl_html_entity_list;
                            while (entity->name) {
                                   if (!strcmp(buffer+1, entity->name))      {
                                          ent = entity->code;
                                          break;
                                   }
                                   entity++;
                            }
                            if (ent) {
                                   /* decoded */
                                   CK((*filter->output_function)(ent, filter->data));
                                   filter->status = 0;
                                   /*php_error_docref("ref.mbstring" TSRMLS_CC, E_NOTICE,"mbstring decoded '%s'=%d", buffer, ent);*/
                            } else { 
                                   /* failure */
                                   buffer[filter->status++] = ';';
                                   buffer[filter->status] = 0;
                                   /* php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring cannot decode '%s'", buffer); */
                                   mbfl_filt_conv_html_dec_flush(filter);
                            }
                     }
              } else {
                     /* add character */
                     buffer[filter->status++] = c;
                     /* add character and check */
                     if (!strchr(html_entity_chars, c) || filter->status+1==html_enc_buffer_size || (c=='#' && filter->status>2))
                     {
                            /* illegal character or end of buffer */
                            if (c=='&')
                                   filter->status--;
                            buffer[filter->status] = 0;
                            /* php_error_docref("ref.mbstring" TSRMLS_CC, E_WARNING, "mbstring cannot decode '%s'", buffer)l */
                            mbfl_filt_conv_html_dec_flush(filter);
                            if (c=='&')
                            {
                                   buffer[filter->status++] = '&';
                            }
                     }
              }
       }
       return c;
}

Here is the call graph for this function:

void mbfl_filt_conv_html_dec_ctor ( mbfl_convert_filter *  filter)

Definition at line 163 of file mbfilter_htmlent.c.

{
       filter->status = 0;
       filter->opaque = mbfl_malloc(html_enc_buffer_size+1);
}
void mbfl_filt_conv_html_dec_dtor ( mbfl_convert_filter *  filter)

Definition at line 169 of file mbfilter_htmlent.c.

{
       filter->status = 0;
       if (filter->opaque)
       {
              mbfl_free((void*)filter->opaque);
       }
       filter->opaque = NULL;
}
int mbfl_filt_conv_html_dec_flush ( mbfl_convert_filter *  filter)

Definition at line 288 of file mbfilter_htmlent.c.

{
       int status, pos = 0;
       unsigned char *buffer;
       int err = 0;

       buffer = (unsigned char*)filter->opaque;
       status = filter->status;
       filter->status = 0;

       /* flush fragments */
       while (status--) {
              int e = (*filter->output_function)(buffer[pos++], filter->data);
              if (e != 0)
                     err = e;
       }

       if (filter->flush_function != NULL) {
              (*filter->flush_function)(filter->data);
       }

       return err;
}

Here is the caller graph for this function:

int mbfl_filt_conv_html_enc ( int  c,
mbfl_convert_filter *  filter 
)

Definition at line 99 of file mbfilter_htmlent.c.

{
       int tmp[64];
       int i;
       unsigned int uc;
       const mbfl_html_entity_entry *e;

       if (c < sizeof(htmlentitifieds) / sizeof(htmlentitifieds[0]) &&
                            htmlentitifieds[c] != 1) {
              CK((*filter->output_function)(c, filter->data));
       } else {
              CK((*filter->output_function)('&', filter->data));
              for (i = 0; (e = &mbfl_html_entity_list[i])->name != NULL; i++) {
                     if (c == e->code) {
                            char *p;
                            
                            for (p = e->name; *p != '\0'; p++) {
                                   CK((*filter->output_function)((int)*p, filter->data));
                            }
                            goto last;
                     }
              }

              {
                     int *p = tmp + sizeof(tmp) / sizeof(tmp[0]);

                     CK((*filter->output_function)('#', filter->data));

                     uc = (unsigned int)c;

                     *(--p) = '\0';
                     do {
                            *(--p) = "0123456789"[uc % 10];
                            uc /= 10;
                     } while (uc);

                     for (; *p != '\0'; p++) {
                            CK((*filter->output_function)(*p, filter->data));
                     }
              }
       last:
              CK((*filter->output_function)(';', filter->data));
       }
       return c;
}
int mbfl_filt_conv_html_enc_flush ( mbfl_convert_filter *  filter)

Definition at line 145 of file mbfilter_htmlent.c.

{
       filter->status = 0;
       filter->opaque = NULL;

       if (filter->flush_function != NULL) {
              (*filter->flush_function)(filter->data);
       }

       return 0;
}

Variable Documentation

Definition at line 67 of file mbfilter_htmlent.c.