Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
utf8_decode.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  json_utf8_decode

Defines

#define UTF8_END   -1
#define UTF8_ERROR   -2

Typedefs

typedef struct json_utf8_decode json_utf8_decode

Functions

int utf8_decode_at_byte (json_utf8_decode *utf8)
int utf8_decode_at_character (json_utf8_decode *utf8)
void utf8_decode_init (json_utf8_decode *utf8, char p[], int length)
int utf8_decode_next (json_utf8_decode *utf8)

Class Documentation

struct json_utf8_decode

Definition at line 6 of file utf8_decode.h.

Class Members
int the_byte
int the_char
int the_index
char * the_input
int the_length

Define Documentation

#define UTF8_END   -1

Definition at line 3 of file utf8_decode.h.

#define UTF8_ERROR   -2

Definition at line 4 of file utf8_decode.h.


Typedef Documentation


Function Documentation

Definition at line 101 of file utf8_decode.c.

{
    return utf8->the_byte;
}

Definition at line 112 of file utf8_decode.c.

{
    return utf8->the_char > 0 ? utf8->the_char - 1 : 0;
}
void utf8_decode_init ( json_utf8_decode utf8,
char  p[],
int  length 
)

Definition at line 87 of file utf8_decode.c.

{
    utf8->the_index = 0;
    utf8->the_input = p;
    utf8->the_length = length;
    utf8->the_char = 0;
    utf8->the_byte = 0;
}

Here is the caller graph for this function:

Definition at line 125 of file utf8_decode.c.

{
    int c;  /* the first byte of the character */
    int r;  /* the result */

    if (utf8->the_index >= utf8->the_length) {
        return utf8->the_index == utf8->the_length ? UTF8_END : UTF8_ERROR;
    }
    utf8->the_byte = utf8->the_index;
    utf8->the_char += 1;
    c = get(utf8);
/*
    Zero continuation (0 to 127)
*/
    if ((c & 0x80) == 0) {
        return c;
    }
/*
    One contination (128 to 2047)
*/
    if ((c & 0xE0) == 0xC0) {
        int c1 = cont(utf8);
        if (c1 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x1F) << 6) | c1;
        return r >= 128 ? r : UTF8_ERROR;
    }
/*
    Two continuation (2048 to 55295 and 57344 to 65535) 
*/
    if ((c & 0xF0) == 0xE0) {
        int c1 = cont(utf8);
        int c2 = cont(utf8);
        if (c1 < 0 || c2 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x0F) << 12) | (c1 << 6) | c2;
        return r >= 2048 && (r < 55296 || r > 57343) ? r : UTF8_ERROR;
    }
/*
    Three continuation (65536 to 1114111)
*/
    if ((c & 0xF8) == 0xF0) {
        int c1 = cont(utf8);
        int c2 = cont(utf8);
        int c3 = cont(utf8);
        if (c1 < 0 || c2 < 0 || c3 < 0) {
            return UTF8_ERROR;
        }
        r = ((c & 0x0F) << 18) | (c1 << 12) | (c2 << 6) | c3;
        return r >= 65536 && r <= 1114111 ? r : UTF8_ERROR;
    }
    return UTF8_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function: