Example #1
0
/**
 * 12 2.4.8
 */
static int h5_state_tag_open(h5_state_t* hs)
{
    char ch;

    TRACE();
    ch = hs->s[hs->pos];
    if (ch == CHAR_BANG) {
        hs->pos += 1;
        return h5_state_markup_declaration_open(hs);
    } else if (ch == CHAR_SLASH) {
        hs->pos += 1;
        hs->is_close = 1;
        return h5_state_end_tag_open(hs);
    } else if (ch == CHAR_QUESTION) {
        hs->pos += 1;
        return h5_state_bogus_comment(hs);
    } else if (ch == CHAR_PERCENT) {
        /* this is not in spec.. alternative comment format used
           by IE <= 9 and Safari < 4.0.3 */
        hs->pos += 1;
        return h5_state_bogus_comment2(hs);
    } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
        return h5_state_tag_name(hs);
    } else {
        /* user input mistake in configuring state */
        if (hs->pos == 0) {
            return h5_state_data(hs);
        }
        hs->token_start = hs->s + hs->pos - 1;
        hs->token_len = 1;
        hs->token_type = DATA_TEXT;
        hs->state = h5_state_data;
        return 1;
    }
}
/**
 * 12.2.4.9
 */
static int h5_state_end_tag_open(h5_state_t* hs)
{
    char ch;

    TRACE();

    if (hs->pos >= hs->len) {
        return 0;
    }
    ch = hs->s[hs->pos];
    if (ch == CHAR_GT) {
        return h5_state_data(hs);
    } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
        return h5_state_tag_name(hs);
    }

    hs->is_close = 0;
    return h5_state_bogus_comment(hs);
}
/**
 * 8.2.4.45
 */
static int h5_state_markup_declaration_open(h5_state_t* hs)
{
    size_t remaining;

    TRACE();
    remaining = hs->len - hs->pos;
    if (remaining >= 7 &&
        /* case insensitive */
        (hs->s[hs->pos + 0] == 'D' || hs->s[hs->pos + 0] == 'd') &&
        (hs->s[hs->pos + 1] == 'O' || hs->s[hs->pos + 1] == 'o') &&
        (hs->s[hs->pos + 2] == 'C' || hs->s[hs->pos + 2] == 'c') &&
        (hs->s[hs->pos + 3] == 'T' || hs->s[hs->pos + 3] == 't') &&
        (hs->s[hs->pos + 4] == 'Y' || hs->s[hs->pos + 4] == 'y') &&
        (hs->s[hs->pos + 5] == 'P' || hs->s[hs->pos + 5] == 'p') &&
        (hs->s[hs->pos + 6] == 'E' || hs->s[hs->pos + 6] == 'e')
        ) {
        return h5_state_doctype(hs);
    } else if (remaining >= 7 &&
               /* upper case required */
               hs->s[hs->pos + 0] == '[' &&
               hs->s[hs->pos + 1] == 'C' &&
               hs->s[hs->pos + 2] == 'D' &&
               hs->s[hs->pos + 3] == 'A' &&
               hs->s[hs->pos + 4] == 'T' &&
               hs->s[hs->pos + 5] == 'A' &&
               hs->s[hs->pos + 6] == '['
        ) {
        hs->pos += 7;
        return h5_state_cdata(hs);
    } else if (remaining >= 2 &&
               hs->s[hs->pos + 0] == '-' &&
               hs->s[hs->pos + 1] == '-') {
        hs->pos += 2;
        return h5_state_comment(hs);
    }

    return h5_state_bogus_comment(hs);
}