Beispiel #1
0
bool URI::equals(URI& uri)
{
    char* own = this->normalize();
    char* other = uri.normalize();
    unsigned int length = strlen(own);
    bool inEncoding = false;
    
    if( strlen(own) != strlen(other) )
        return false;
    else {
        for( unsigned int i = 0; i < length; i++ ) {
            if( ! inEncoding ) {
                if( own[i] != other[i] )
                    return false;
                
                if( own[i] == '%' )
                    inEncoding = true;
            }
            else {
                if( own[i] != other[i] ) {
                    /* Compare them in a case insensitive way. */
                    int result = (int)(own[i] - other[i]);
                    if( result != 32 && result != -32 )
                        return false;
                }
                
                /* See if we are at the end of the encoded string */
                if( i > 0 && ( own[i - 1] != '%' ) )
                    inEncoding = false;
            }
        }
    }
    
    return true;
}
Beispiel #2
0
URI URI::resolve(const URI &other) const
{
    //### According to w3c, this is handled in 3 cases

    //## 1
    if (opaque || other.isAbsolute())
        return other;

    //## 2
    if (!other.fragment.empty()     &&
        other.path.empty()          &&
        other.scheme == SCHEME_NONE &&
        other.authority.empty()     &&
        other.query.empty())
        {
        URI fragUri = *this;
        fragUri.fragment = other.fragment;
        return fragUri;
        }

    //## 3 http://www.ietf.org/rfc/rfc2396.txt, section 5.2
    URI newUri;
    //# 3.1
    newUri.scheme    = scheme;
    newUri.schemeStr = schemeStr;
    newUri.query     = other.query;
    newUri.fragment  = other.fragment;
    if (!other.authority.empty())
        {
        //# 3.2
        if (absolute || other.absolute)
            newUri.absolute = true;
        newUri.authority = other.authority;
        newUri.port      = other.port;//part of authority
        newUri.path      = other.path;
        }
    else
        {
        //# 3.3
        if (other.absolute)
            {
            newUri.absolute = true;
            newUri.path     = other.path;
            }
        else
            {
            int pos = findLast(path, '/');
            if (pos >= 0)
                {
                newUri.path.clear();
                //# append my path up to and including the '/'
                for (int i = 0; i<=pos ; i++)
                       newUri.path.push_back(path[i]);
                //# append other path
                for (unsigned int i = 0; i<other.path.size() ; i++)
                       newUri.path.push_back(other.path[i]);
                }
            else
                newUri.path = other.path;
            }
        }

    newUri.normalize();

    return newUri;
}