コード例 #1
0
ファイル: URITest.cpp プロジェクト: lmtan91/common
int main( int argc, char*argv[] ) {
   LOG_NOTICE( "Test Started" );

   URI u;

   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );

   string ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );

   for (uint32_t i = 0; i < ARRAY_SIZE( test_urls ); i++) {
      bool res = u.setString( test_urls[i] );

#ifdef DEBUG_PRINTS
      cout << "scheme: " << u.getScheme() << endl;
      cout << "authority: " << u.getAuthority() << endl;
      cout << "host: " << u.getHost() << endl;
      cout << "port: " << u.getPort() << endl;
      cout << "query: " << u.getQuery() << endl;
      cout << "path: " << u.getPath() << endl;
      cout << "fragment: " << u.getFragment() << endl;
      cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
      cout << "query param \"e\": " << u.getQueryParam( "e" ) << endl;
      cout << "is relative: " << u.isRelative() << endl;
#endif

      if ( not res ) {
         LOG_WARN( "parse uri %s: FAILED", test_urls[i] );
         exit( 1 );
      } else {
         LOG_NOTICE( "parse uri %s: PASSED", test_urls[ i ] );
      }
   }

   u.clear();
   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );
   u.appendQueryParam( "a", "b" );
   u.appendQueryParam( "c", "d" );
   u.setFragment( "m" );

   URI copy = u;

   ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );
   ustr = copy.getString();
   LOG_NOTICE( "Copy is: %s", ustr.c_str() );

#ifdef DEBUG_PRINTS
   cout << "scheme: " << u.getScheme() << endl;
   cout << "scheme: " << copy.getScheme() << endl;
   cout << "authority: " << u.getAuthority() << endl;
   cout << "authority: " << copy.getAuthority() << endl;
   cout << "host: " << u.getHost() << endl;
   cout << "host: " << copy.getHost() << endl;
   cout << "port: " << u.getPort() << endl;
   cout << "port: " << copy.getPort() << endl;
   cout << "query: " << u.getQuery() << endl;
   cout << "query: " << copy.getQuery() << endl;
   cout << "path: " << u.getPath() << endl;
   cout << "path: " << copy.getPath() << endl;
   cout << "fragment: " << u.getFragment() << endl;
   cout << "fragment: " << copy.getFragment() << endl;
   cout << "query param \"a\": " << u.getQueryParam( "a" ) << endl;
   cout << "query param \"a\": " << copy.getQueryParam( "a" ) << endl;
   cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
   cout << "query param \"c\": " << copy.getQueryParam( "c" ) << endl;
   cout << "is relative: " << u.isRelative() << endl;
   cout << "is relative: " << copy.isRelative() << endl;
#endif

   if ( u.getScheme() != copy.getScheme()
         or u.getAuthority() != copy.getAuthority()
         or u.getQuery() != copy.getQuery() or u.getPath() != copy.getPath()
         or u.getFragment() != copy.getFragment()
         or u.getQueryParam( "a" ) != copy.getQueryParam( "a" )
         or u.getQueryParam( "c" ) != copy.getQueryParam( "c" )
         or u.isRelative() != copy.isRelative() ) {
      LOG_WARN( "copy of uri: FAILED" );
   } else {
      LOG_NOTICE( "copy of uri: PASSED" );
   }

   return 0;
}
コード例 #2
0
ファイル: uri-references.cpp プロジェクト: myutwo/inkscape
void URIReference::attach(const URI &uri) throw(BadURIException)
{
    SPDocument *document = NULL;

    // Attempt to get the document that contains the URI
    if (_owner) {
        document = _owner->document;
    } else if (_owner_document) {
        document = _owner_document;
    }

    // createChildDoc() assumes that the referenced file is an SVG.
    // PNG and JPG files are allowed (in the case of feImage).
    gchar *filename = uri.toString();
    bool skip = false;
    if( g_str_has_suffix( filename, ".jpg" ) ||
        g_str_has_suffix( filename, ".JPG" ) ||
        g_str_has_suffix( filename, ".png" ) ||
        g_str_has_suffix( filename, ".PNG" ) ) {
        skip = true;
    }
 
    // The path contains references to separate document files to load.
    if(document && uri.getPath() && !skip ) {
        std::string base = document->getBase() ? document->getBase() : "";
        std::string path = uri.getFullPath(base);
        if(!path.empty()) {
            document = document->createChildDoc(path);
        } else {
            document = NULL;
        }
    }
    if(!document) {
        g_warning("Can't get document for referenced URI: %s", filename);
        g_free( filename );
        return;
    }
    g_free( filename );

    gchar const *fragment = uri.getFragment();
    if ( !uri.isRelative() || uri.getQuery() || !fragment ) {
        throw UnsupportedURIException();
    }

    /* FIXME !!! real xpointer support should be delegated to document */
    /* for now this handles the minimal xpointer form that SVG 1.0
     * requires of us
     */
    gchar *id = NULL;
    if (!strncmp(fragment, "xpointer(", 9)) {
        /* FIXME !!! this is wasteful */
        /* FIXME: It looks as though this is including "))" in the id.  I suggest moving
           the strlen calculation and validity testing to before strdup, and copying just
           the id without the "))".  -- pjrm */
        if (!strncmp(fragment, "xpointer(id(", 12)) {
            id = g_strdup(fragment+12);
            size_t const len = strlen(id);
            if ( len < 3 || strcmp(id+len-2, "))") ) {
                g_free(id);
                throw MalformedURIException();
            }
        } else {
            throw UnsupportedURIException();
        }
    } else {
        id = g_strdup(fragment);
    }

    /* FIXME !!! validate id as an NCName somewhere */

    _connection.disconnect();
    delete _uri;
    _uri = new URI(uri);

    _setObject(document->getObjectById(id));
    _connection = document->connectIdChanged(id, sigc::mem_fun(*this, &URIReference::_setObject));

    g_free(id);
}