Back to index

php5  5.3.10
Typedefs | Functions | Variables
cyr_convert.c File Reference
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "php.h"
#include "cyr_convert.h"
#include <stdio.h>

Go to the source code of this file.

Typedefs

typedef unsigned char _cyr_charset_table [512]

Functions

static char * php_convert_cyr_string (unsigned char *str, int length, char from, char to TSRMLS_DC)
 PHP_FUNCTION (convert_cyr_string)

Variables

static const _cyr_charset_table _cyr_win1251
static const _cyr_charset_table _cyr_cp866
static const _cyr_charset_table _cyr_iso88595
static const _cyr_charset_table _cyr_mac

Typedef Documentation

typedef unsigned char _cyr_charset_table[512]

Definition at line 48 of file cyr_convert.c.


Function Documentation

static char* php_convert_cyr_string ( unsigned char *  str,
int  length,
char  from,
char to  TSRMLS_DC 
) [static]

Definition at line 204 of file cyr_convert.c.

{
       const unsigned char *from_table, *to_table;
       unsigned char tmp;
       int i;

       from_table = NULL;
       to_table   = NULL;
       
       switch (toupper((int)(unsigned char)from))
       {
              case 'W':
                     from_table = _cyr_win1251;
                     break;
              case 'A':
              case 'D':
                     from_table = _cyr_cp866;
                     break;
              case 'I':
                     from_table = _cyr_iso88595;
                     break;
              case 'M':
                     from_table = _cyr_mac;
                     break;
              case 'K':
                     break;
              default:
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown source charset: %c", from);
                     break;
       }

       switch (toupper((int)(unsigned char)to))
       {
              case 'W':
                     to_table = _cyr_win1251;
                     break;
              case 'A':
              case 'D':
                     to_table = _cyr_cp866;
                     break;
              case 'I':
                     to_table = _cyr_iso88595;
                     break;
              case 'M':
                     to_table = _cyr_mac;
                     break;
              case 'K':
                     break;
              default:
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown destination charset: %c", to);
                     break;
       }


       if (!str)
              return (char *)str;
       
       for( i = 0; i<length; i++)
       {
              tmp = (from_table == NULL)? str[i] : from_table[ str[i] ];
              str[i] = (to_table == NULL) ? tmp : to_table[tmp + 256];
       }
       return (char *)str;
}

Here is the caller graph for this function:

PHP_FUNCTION ( convert_cyr_string  )

Definition at line 272 of file cyr_convert.c.

{
       char *input, *fr_cs, *to_cs;
       int input_len, fr_cs_len, to_cs_len;
       unsigned char *str;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &input, &input_len, &fr_cs, &fr_cs_len, &to_cs, &to_cs_len) == FAILURE) {
              return;
       }

       str = (unsigned char*) estrndup(input, input_len);

       php_convert_cyr_string(str, input_len, fr_cs[0], to_cs[0] TSRMLS_CC);
       RETVAL_STRING((char *)str, 0)
}

Here is the call graph for this function:


Variable Documentation

Definition at line 86 of file cyr_convert.c.

Definition at line 120 of file cyr_convert.c.

const _cyr_charset_table _cyr_mac [static]

Definition at line 154 of file cyr_convert.c.

Definition at line 52 of file cyr_convert.c.