Exemplo n.º 1
0
result_t Regex::test(const char *str, bool &retVal)
{
    int32_t rc = 0;
    int32_t ovector[RE_SIZE];
    int32_t len = (int32_t) qstrlen(str);
    const char *end = str + len;

    if (m_bGlobal)
    {
        int32_t n = m_nlastIndex;
        while (n > 0 && utf8_getchar(str, end))
            n--;
    }

    if (*str)
    {
        len = (int32_t) qstrlen(str);

        rc = pcre_exec(m_re, NULL, str, len, 0, 0, ovector, RE_SIZE);
        if (rc < 0)
        {
            rc = 0;
            m_nlastIndex = 0;
        }
    }

    if (rc)
    {
        retVal = true;
        if (m_bGlobal)
            m_nlastIndex += utf8_strlen(str, ovector[2 * rc - 1]);
    }

    return 0;
}
Exemplo n.º 2
0
int utf8_mbstowcs(const char *src, int srclen, wchar *dst, int dstlen)
{
    int count = 0;
    const char *src_end = src + srclen;
    const wchar *dst_end = dst + dstlen;
    int ch;

    while (src < src_end)
    {
        ch = utf8_getchar(src, src_end);
        count += utf16_putchar(ch, dst, dst_end);
    }

    return count;
}
Exemplo n.º 3
0
result_t Regex::exec(const char *str, v8::Local<v8::Array> &retVal)
{
    int32_t rc = 0;
    int32_t ovector[RE_SIZE];
    int32_t len = (int32_t) qstrlen(str);
    const char *end = str + len;
    int32_t i;

    if (m_bGlobal)
    {
        int32_t n = m_nlastIndex;
        while (n > 0 && utf8_getchar(str, end))
            n--;
    }

    if (*str)
    {
        len = (int32_t) qstrlen(str);

        rc = pcre_exec(m_re, NULL, str, len, 0, 0, ovector, RE_SIZE);
        if (rc < 0)
        {
            rc = 0;
            m_nlastIndex = 0;
        }
    }

    if (rc)
    {
        Isolate* isolate = Isolate::now();
        retVal = v8::Array::New(isolate->m_isolate, rc);

        for (i = 0; i < rc; i++)
            retVal->Set(i,
                        v8::String::NewFromUtf8(isolate->m_isolate, str + ovector[2 * i],
                                                v8::String::kNormalString,
                                                ovector[2 * i + 1] - ovector[2 * i]));

        if (m_bGlobal)
            m_nlastIndex += utf8_strlen(str, ovector[2 * rc - 1]);
    }

    return rc ? 0 : CALL_RETURN_NULL;
}