Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

void org::w3c::dom::URI::normalize (  )  [virtual]

This follows the Java URI algorithm: 1. All "." segments are removed. 2. If a ".." segment is preceded by a non-".." segment then both of these segments are removed. This step is repeated until it is no longer applicable. 3. If the path is relative, and if its first segment contains a colon character (':'), then a "." segment is prepended. This prevents a relative URI with a path such as "a:b/c/d" from later being re-parsed as an opaque URI with a scheme of "a" and a scheme-specific part of "b/c/d". (Deviation from RFC 2396)

Definition at line 454 of file uri.cpp.

{
    std::vector< std::vector<int> > segments;

    //## Collect segments
    if (path.size()<2)
        return;
    bool abs = false;
    int pos=0;
    int len = (int) path.size();

    if (path[0]=='/')
        {
        abs = true;
        pos++;
        }

    while (pos < len)
        {
        int pos2 = find(path, '/', pos);
        if (pos2 < 0)
            {
            std::vector<int> seg = substr(path, pos, path.size()-pos);
            //printf("last segment:%s\n", toStr(seg).c_str());
            segments.push_back(seg);
            break;
            }
        if (pos2>pos)
            {
            std::vector<int> seg = substr(path, pos, pos2-pos);
            //printf("segment:%s\n", toStr(seg).c_str());
            segments.push_back(seg);
            }
        pos = pos2;
        pos++;
        }

    //## Clean up (normalize) segments
    bool edited = false;
    std::vector< std::vector<int> >::iterator iter;
    for (iter=segments.begin() ; iter!=segments.end() ; )
        {
        std::vector<int> s = *iter;
        if (sequ(s,"."))
            {
            iter = segments.erase(iter);
            edited = true;
            }
        else if (sequ(s, "..") && iter != segments.begin() &&
                 !sequ(*(iter-1), ".."))
            {
            iter--; //back up, then erase two entries
            iter = segments.erase(iter);
            iter = segments.erase(iter);
            edited = true;
            }
        else
            iter++;
        }

    //## Rebuild path, if necessary
    if (edited)
        {
        path.clear();
        if (abs)
            {
            path.push_back('/');
            }
        std::vector< std::vector<int> >::iterator iter;
        for (iter=segments.begin() ; iter!=segments.end() ; iter++)
            {
            if (iter != segments.begin())
                path.push_back('/');
            std::vector<int> seg = *iter;
            for (unsigned int i = 0; i<seg.size() ; i++)
                path.push_back(seg[i]);
            }
        }

}


Generated by  Doxygen 1.6.0   Back to index