summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-10-22 05:37:30 +0000
committerDavid Robillard <d@drobilla.net>2011-10-22 05:37:30 +0000
commit1f7a9fc296605a2d58312a9133b1a4f90bdb3724 (patch)
tree7be1661057c881bf7c73c96876af564ad0f97c7b /src/serialisation
parent389da7d63b8e78baacf22cf52905dc5420079d71 (diff)
downloadingen-1f7a9fc296605a2d58312a9133b1a4f90bdb3724.tar.gz
ingen-1f7a9fc296605a2d58312a9133b1a4f90bdb3724.tar.bz2
ingen-1f7a9fc296605a2d58312a9133b1a4f90bdb3724.zip
Fix serialisation.
Fix Parser::relative_uri. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3590 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp37
-rw-r--r--src/serialisation/Serialiser.cpp31
2 files changed, 28 insertions, 40 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index 5a3ec2a7..318158fa 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -59,27 +59,30 @@ namespace Serialisation {
static Glib::ustring
relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash)
{
- const char* out = NULL;
- if (uri == base) {
- out = "";
- } else {
- SerdURI base_uri;
- if (serd_uri_parse((const uint8_t*)base.c_str(), &base_uri)) {
- LOG(error) << boost::format("Invalid base URI `%1%'") % base << endl;
- return "";
+ Glib::ustring ret;
+ if (uri != base) {
+ SerdURI base_uri;
+ serd_uri_parse((const uint8_t*)base.c_str(), &base_uri);
+
+ SerdURI normal_base_uri;
+ SerdNode normal_base_uri_node = serd_node_new_uri_from_string(
+ (const uint8_t*)".", &base_uri, &normal_base_uri);
+
+ Glib::ustring normal_base_str((const char*)normal_base_uri_node.buf);
+
+ ret = uri;
+ if (uri.length() >= normal_base_str.length()
+ && uri.substr(0, normal_base_str.length()) == normal_base_str) {
+ ret = uri.substr(normal_base_str.length());
+ if (leading_slash && ret[0] != '/')
+ ret = Glib::ustring("/") + ret;
}
-
- SerdURI out_uri;
- SerdNode out_node = serd_node_new_uri_from_string(
- (const uint8_t*)uri.c_str(), &base_uri, &out_uri);
-
- out = (const char*)out_node.buf;
}
- if (leading_slash && out[0] != '/') {
- return Glib::ustring("/").append(out);
+ if (leading_slash && ret[0] != '/') {
+ ret = Glib::ustring("/").append(ret);
}
- return out;
+ return ret;
}
static std::string
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index 3d528af4..8d9b490a 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -39,7 +39,6 @@
#include "raul/Atom.hpp"
#include "raul/AtomRDF.hpp"
#include "raul/Path.hpp"
-#include "raul/TableImpl.hpp"
#include "raul/log.hpp"
#include "sord/sordmm.hpp"
@@ -139,15 +138,6 @@ Serialiser::to_file(SharedPtr<const GraphObject> object,
finish();
}
-static
-std::string
-uri_to_symbol(const std::string& uri)
-{
- const std::string filename = Glib::filename_from_uri(uri);
- return Path::nameify(Glib::path_get_basename(
- filename.substr(0, filename.find_last_of('.'))));
-}
-
void
Serialiser::Impl::write_manifest(const std::string& bundle_path,
SharedPtr<const Patch> patch,
@@ -201,23 +191,16 @@ normal_bundle_uri(const std::string& uri)
void
Serialiser::write_bundle(SharedPtr<const Patch> patch,
- const std::string& uri)
+ const std::string& path)
{
- me->write_bundle(patch, uri);
+ me->write_bundle(patch, path);
}
void
Serialiser::Impl::write_bundle(SharedPtr<const Patch> patch,
- const std::string& uri)
+ const std::string& a_path)
{
- Glib::ustring path = "";
- try {
- path = Glib::filename_from_uri(uri);
- } catch (...) {
- LOG(error) << "Illegal file URI `" << uri << "'" << endl;
- return;
- }
-
+ std::string path(a_path);
if (Glib::file_test(path, Glib::FILE_TEST_EXISTS)
&& !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) {
path = Glib::path_get_dirname(path);
@@ -228,8 +211,10 @@ Serialiser::Impl::write_bundle(SharedPtr<const Patch> patch,
g_mkdir_with_parents(path.c_str(), 0744);
- const string symbol = uri_to_symbol(uri);
- const string root_file = path + symbol + ".ttl";
+ string symbol = Glib::path_get_basename(path);
+ symbol = symbol.substr(0, symbol.find("."));
+
+ const string root_file = Glib::build_filename(path, symbol + ".ttl");
start_to_filename(root_file);
const Path old_root_path = _root_path;