Ejemplo n.º 1
0
DOMString URI::getNativePath() const
{
    DOMString pathStr = toStr(path);
    DOMString npath;
#ifdef __WIN32__
    unsigned int firstChar = 0;
    if (pathStr.size() >= 3)
        {
        if (pathStr[0] == '/' &&
            uni_is_letter(pathStr[1]) &&
            pathStr[2] == ':')
            firstChar++;
         }
    for (unsigned int i=firstChar ; i<pathStr.size() ; i++)
        {
        XMLCh ch = (XMLCh) pathStr[i];
        if (ch == '/')
            npath.push_back((XMLCh)'\\');
        else
            npath.push_back(ch);
        }
#else
    npath = pathStr;
#endif
    return npath;
}
Ejemplo n.º 2
0
bool URI::parse(const DOMString &str)
{

    parselen = str.size();
    parsebuf = new int[str.size()];
    if (!parsebuf)
        {
        error("parse : could not allocate parsebuf");
        return false;
        }

    DOMString::const_iterator iter;
    unsigned int i=0;
    for (iter= str.begin() ; iter!=str.end() ; ++iter)
        {
        int ch = *iter;
        if (ch == '\\')
            parsebuf[i++] = '/';
        else
            parsebuf[i++] = ch;
        }


    int p = parse(0);
    normalize();

    delete[] parsebuf;

    if (p < 0)
        {
        error("Syntax error");
        return false;
        }

    //printf("uri:%s\n", toString().c_str());
    //printf("parse:%s\n", toStr(path).c_str());

    return true;

}
int DOMString::compare(const DOMString &str) const
{
    int asize = chars.size();
    int bsize = str.size();

    int diff = 0;
    int index = 0;
    while (index < asize && index < bsize)
        {
        int a = (int) chars[index];
        int b = (int) str[index];
        diff = a - b;
        if (diff)
            return diff;
        index++;
        }

    //equal for their common length. lets see which is longer
    diff = asize - bsize;

    return diff;
}
Ejemplo n.º 4
0
int URI::parseHierarchicalPart(int p0)
{
    int p = p0;
    int ch;

    //# Authority field (host and port, for example)
    int p2 = match(p, "//");
    if (p2 > p)
        {
        p = p2;
        portSpecified = false;
        DOMString portStr;
        while (p < parselen)
            {
            ch = peek(p);
            if (ch == '/')
                break;
            else if (ch == '&') //IRI entity
                {
                int val;
                p2 = parseEntity(p, val);
                if (p2<p)
                    {
                    return -1;
                    }
                p = p2;
                authority.push_back((XMLCh)val);
                }
            else if (ch == '%') //ascii hex excape
                {
                int val;
                p2 = parseAsciiEntity(p, val);
                if (p2<p)
                    {
                    return -1;
                    }
                p = p2;
                authority.push_back((XMLCh)val);
                }
            else if (ch == ':')
                {
                portSpecified = true;
                p++;
                }
            else if (portSpecified)
                {
                portStr.push_back((XMLCh)ch);
                p++;
                }
            else
                {
                authority.push_back((XMLCh)ch);
                p++;
                }
            }
        if (portStr.size() > 0)
            {
            char *pstr = (char *)portStr.c_str();
            char *endStr;
            long val = strtol(pstr, &endStr, 10);
            if (endStr > pstr) //successful parse?
                port = val;
            }
        }

    //# Are we absolute?
    ch = peek(p);
    if (uni_is_letter(ch) && peek(p+1)==':')
        {
        absolute = true;
        path.push_back((XMLCh)'/');
        }
    else if (ch == '/')
        {
        absolute = true;
        if (p>p0) //in other words, if '/' is not the first char
            opaque = true;
        path.push_back((XMLCh)ch);
        p++;
        }

    while (p < parselen)
        {
        ch = peek(p);
        if (ch == '?' || ch == '#')
            break;
        else if (ch == '&') //IRI entity
            {
            int val;
            p2 = parseEntity(p, val);
            if (p2<p)
                {
                return -1;
                }
            p = p2;
            path.push_back((XMLCh)val);
            }
        else if (ch == '%') //ascii hex excape
            {
            int val;
            p2 = parseAsciiEntity(p, val);
            if (p2<p)
                {
                return -1;
                }
            p = p2;
            path.push_back((XMLCh)val);
            }
        else
            {
            path.push_back((XMLCh)ch);
            p++;
            }
        }
    //trace("path:%s", toStr(path).c_str());
    return p;
}