Esempio n. 1
0
void urlhack_go_find_me_some_hyperlinks(int screen_width)
{
    if (urlhack_disabled != 0) return;

    if (is_regexp_compiled == 0) {
        urlhack_set_regular_expression(urlhack_default_regex);
    }

    urlhack_clear_link_regions();


    char* text = const_cast<char*>(text_mass.c_str());
    char* text_pos = text;

    while (regexec(urlhack_rx, text_pos) == 1) {
        char* start_pos = *urlhack_rx->startp[0] == ' ' ? urlhack_rx->startp[0] + 1: urlhack_rx->startp[0];

        int x0 = (start_pos - text) % screen_width;
        int y0 = (start_pos - text) / screen_width;
        int x1 = (urlhack_rx->endp[0] - text) % screen_width;
        int y1 = (urlhack_rx->endp[0] - text) / screen_width;

        if (x0 >= screen_width) x0 = screen_width - 1;
        if (x1 >= screen_width) x1 = screen_width - 1;

        urlhack_add_link_region(x0, y0, x1, y1);

        text_pos = urlhack_rx->endp[0] + 1;
    }
}
Esempio n. 2
0
void urlhack_go_find_me_some_hyperlinks(int screen_width)
{
    if (urlhack_disabled != 0) return;

    if (is_regexp_compiled == 0) {
        urlhack_set_regular_expression(urlhack_default_regex);
    }

    urlhack_clear_link_regions();


    char* text = const_cast<char*>(text_mass.c_str());
    char* text_pos = text;

    while (regexec(urlhack_rx, text_pos) == 1) {
        char* start_pos = *urlhack_rx->startp[0] == ' ' ? urlhack_rx->startp[0] + 1: urlhack_rx->startp[0];
        char* end_pos = urlhack_rx->endp[0];
        int max_brackets = 0;
        for (char *c = start_pos; c < end_pos; ++c) {
            switch (*c) {
            case '(':
                ++max_brackets;
                break;
            case ')':
                --max_brackets;
                break;
            }
        }
        while (max_brackets --> 0 && *end_pos == ')')
            ++end_pos;

        int x0 = (start_pos - text) % screen_width;
        int y0 = (start_pos - text) / screen_width;
        int x1 = (end_pos - text) % screen_width;
        int y1 = (end_pos - text) / screen_width;

        if (x0 >= screen_width) x0 = screen_width - 1;
        if (x1 >= screen_width) x1 = screen_width - 1;

        urlhack_add_link_region(x0, y0, x1, y1);

        text_pos = end_pos + 1;
    }
}