Ejemplo n.º 1
0
result_t path_base::extname(exlib::string path, exlib::string &retVal)
{
    char ch;
    const char *p1 = NULL;
    const char* c_str = path.c_str();

    if (*c_str == '.')
        c_str++;

    while (*c_str)
    {
        ch = *c_str++;
        if (isPathSlash(ch))
        {
            if (*c_str == '.')
                c_str++;
            p1 = NULL;
        }
        else if (ch == '.')
            p1 = c_str - 1;
    }

    if (p1)
        retVal.assign(p1, (int32_t) (c_str - p1));

    return 0;
}
Ejemplo n.º 2
0
inline result_t msgMethod(Message_base *msg, exlib::string &method)
{
    exlib::string str;
    const char *p, *p1;

    msg->get_value(str);

    p = p1 = str.c_str();
    while (true)
    {
        while (*p && *p != '.' && *p != '/' && *p != '\\')
            p++;
        if (p != p1)
            break;
        if (!*p)
            return CHECK_ERROR(Runtime::setError("JSHandler: method \"" + method + "\" not found."));
        p++;
        p1 = p;
    }

    msg->set_value(*p ? p + 1 : "");
    method.assign(p1, (int32_t) (p - p1));

    return 0;
}
Ejemplo n.º 3
0
result_t Url::get_search(exlib::string& retVal)
{
    if (m_query.length() > 0) {
        retVal.assign(1, '?');
        retVal.append(m_query);
    }

    return 0;
}
Ejemplo n.º 4
0
void Url::parseHost(const char*& url, exlib::string& hostname, exlib::string& port)
{
    const char* p1 = url;
    const char* p2 = NULL;
    char ch;

    if (*p1 == '[') {
        p1++;
        while ((ch = *p1) && (qisxdigit(ch) || ch == ':' || ch == '.'))
            p1++;
        if (ch == ']')
            ch = *++p1;
        else
            url++;
    } else {
        while ((ch = *p1)
            && (qisascii(ch) || qisdigit(ch) || ch == '.' || ch == '_' || ch == '-' || ch < 0))
            p1++;
    }

    if (ch == ':') {
        p2 = p1 + 1;

        while ((ch = *p2) && qisdigit(ch))
            p2++;
    }

    if (*url == '[')
        hostname.assign(url + 1, p1 - url - 2);
    else
        hostname.assign(url, p1 - url);

    if (hostname.length() > 0) {
        qstrlwr(&hostname[0]);
        punycode_base::toASCII(hostname, hostname);
    }
    if (p2)
        port.assign(p1 + 1, p2 - p1 - 1);
    else
        port.clear();

    url = p2 ? p2 : p1;
}
Ejemplo n.º 5
0
result_t path_base::dirname(exlib::string path, exlib::string &retVal)
{
    char ch;
    const char* c_str = path.c_str();
    const char *p1 = c_str;
    const char *p2 = NULL;

#ifdef _WIN32
    if (c_str[0] != 0 && c_str[1] == ':')
    {
        c_str += 2;
        if (isPathSlash(*c_str))
            c_str++;
        p2 = c_str;
    }
    else if (isPathSlash(c_str[0]) && isPathSlash(c_str[1]))
    {
        c_str += 2;
        while (*c_str && !isPathSlash(*c_str))
            c_str++;

        if (*c_str)
        {
            c_str++;

            while (*c_str && !isPathSlash(*c_str))
                c_str++;

            if (*c_str)
                c_str++;
        }

        p2 = c_str;
    }
#endif

    while (*c_str)
    {
        ch = *c_str++;
        if (isPathSlash(ch) && *c_str)
            p2 = c_str - 1;
    }

    if (p2 == NULL)
        p2 = p1;

    if (isPathSlash(*p2) && p2 == p1)
        p2++;

    retVal.assign(p1, (int32_t) (p2 - p1));

    return 0;
}
Ejemplo n.º 6
0
result_t path_base::basename(exlib::string path, exlib::string ext,
                             exlib::string &retVal)
{
    char ch;
    const char* c_str = path.c_str();
    const char *p1 = c_str;
    int32_t extlen = (int32_t)ext.length();

    while (*c_str)
    {
        ch = *c_str++;
        if (isPathSlash(ch))
            p1 = c_str;
    }

    if (extlen && ((int32_t) (c_str - p1) >= extlen)
            && !pathcmp(ext.c_str(), c_str - extlen, extlen))
        c_str -= extlen;

    retVal.assign(p1, (int32_t) (c_str - p1));

    return 0;
}