diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-01-25 01:05:26 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-01-25 01:05:26 +0000 |
| commit | ddb8af8009f151c7107daf0c2127f0ba2d882649 (patch) | |
| tree | 7ce918b452da5860dee2f5fd5926e28a1907c71b /src | |
| parent | fixed user description of VS command (diff) | |
| download | inkscape-ddb8af8009f151c7107daf0c2127f0ba2d882649.tar.gz inkscape-ddb8af8009f151c7107daf0c2127f0ba2d882649.zip | |
Move absolute path generator to URI and use std::strings
(bzr r12977)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 21 | ||||
| -rw-r--r-- | src/document.h | 2 | ||||
| -rw-r--r-- | src/uri-references.cpp | 8 | ||||
| -rw-r--r-- | src/uri.cpp | 13 | ||||
| -rw-r--r-- | src/uri.h | 3 |
5 files changed, 28 insertions, 19 deletions
diff --git a/src/document.cpp b/src/document.cpp index b7f5cb097..e456f2b81 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -67,8 +67,6 @@ #include "xml/rebase-hrefs.h" #include "libcroco/cr-cascade.h" -#include <glibmm/miscutils.h> - using Inkscape::DocumentUndo; using Inkscape::Util::unit_table; @@ -480,22 +478,14 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, /** * Fetches a document and attaches it to the current document as a child href */ -SPDocument *SPDocument::createChildDoc(gchar const *uri) { - - // Calculate the absolute path from an available document - if(strncmp(uri, "/", 1)!=0) { - std::string basePath = std::string( this->getBase() ); - std::string absPath = Glib::build_filename(basePath, std::string( uri ) ); - // free uri first? - uri = absPath.c_str(); - } - +SPDocument *SPDocument::createChildDoc(std::string const uri) +{ SPDocument *parent = this; SPDocument *document = NULL; while(parent != NULL && document == NULL) { // Check myself and any parents int he chain - if(strcmp(parent->getURI(), uri)==0) { + if(uri.compare(parent->getURI())==0) { document = parent; break; } @@ -503,7 +493,7 @@ SPDocument *SPDocument::createChildDoc(gchar const *uri) { boost::ptr_list<SPDocument>::iterator iter; for (iter = parent->_child_documents.begin(); iter != parent->_child_documents.end(); ++iter) { - if(strcmp(iter->getURI(), uri)==0) { + if(uri.compare(iter->getURI())==0) { document = &*iter; break; } @@ -513,7 +503,8 @@ SPDocument *SPDocument::createChildDoc(gchar const *uri) { // Load a fresh document from the svg source. if(!document) { - document = createNewDoc(uri, false, false, this); + const char *path = g_strdup(uri.c_str()); + document = createNewDoc(path, false, false, this); } return document; } diff --git a/src/document.h b/src/document.h index 79381e0c2..110db11c6 100644 --- a/src/document.h +++ b/src/document.h @@ -225,7 +225,7 @@ public: static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false, SPDocument *parent=NULL ); static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive); - SPDocument *createChildDoc(gchar const *uri); + SPDocument *createChildDoc(std::string const uri); /** * Returns the bottommost item from the list which is at the point, or NULL if none. diff --git a/src/uri-references.cpp b/src/uri-references.cpp index f2df55213..dc0101024 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -57,9 +57,11 @@ void URIReference::attach(const URI &uri) throw(BadURIException) } // The path contains references to seperate document files to load. - const char *path = uri.getPath(); - if(path && document != NULL) { - document = document->createChildDoc(path); + if(document && uri.getPath()) { + std::string base = std::string(g_strdup(document->getBase())); + std::string path = uri.getFullPath(base); + if(!path.empty()) + document = document->createChildDoc(path); } if(!document) { g_warning("Can't get document for referenced URI: %s", uri.toString()); diff --git a/src/uri.cpp b/src/uri.cpp index de6a454ec..8d0e49139 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -10,7 +10,9 @@ #include <glib.h> #include "uri.h" +#include <string> #include <glibmm/ustring.h> +#include <glibmm/miscutils.h> namespace Inkscape { @@ -134,6 +136,17 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) return filename; } +const std::string URI::getFullPath(std::string const base) const { + std::string path = std::string(_impl->getPath()); + // Calculate the absolute path from an available base + if(!path.empty() && !base.empty() && path.compare(0, 1, "/") != 0) { + path = Glib::build_filename(base, path); + } + // TODO: Check existance of file here + return path; +} + + /* TODO !!! proper error handling */ gchar *URI::toNativeFilename() const throw(BadURIException) { gchar *uriString = toString(); @@ -15,6 +15,7 @@ #include <exception> #include <libxml/uri.h> #include "bad-uri-exception.h" +#include <string> namespace Inkscape { @@ -101,6 +102,8 @@ public: static gchar *to_native_filename(gchar const* uri) throw(BadURIException); + const std::string getFullPath(std::string const base) const; + gchar *toNativeFilename() const throw(BadURIException); /** |
