summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-03-10 03:31:40 +0000
committerDavid Robillard <d@drobilla.net>2012-03-10 03:31:40 +0000
commit81040bd8c8fb95e0d387b53b3cf25e4c0669a6f7 (patch)
tree2ecdf501f743879bd339f8521867b6147634c92c
parent90a703bad8e7df5c0b154c17dfb201dc708f6069 (diff)
downloadsord-81040bd8c8fb95e0d387b53b3cf25e4c0669a6f7.tar.gz
sord-81040bd8c8fb95e0d387b53b3cf25e4c0669a6f7.tar.bz2
sord-81040bd8c8fb95e0d387b53b3cf25e4c0669a6f7.zip
Use proper URI <=> path conversion.
git-svn-id: http://svn.drobilla.net/sord/trunk@205 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--sord/sordmm.hpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp
index 8a08c83..6fb9f93 100644
--- a/sord/sordmm.hpp
+++ b/sord/sordmm.hpp
@@ -473,37 +473,35 @@ Model::load_file(SerdEnv* env,
const std::string& data_uri,
const std::string& base_uri)
{
- if (data_uri.substr(0, 5) != "file:") {
+ uint8_t* path = serd_file_uri_parse((const uint8_t*)data_uri.c_str(), NULL);
+ if (!path) {
+ fprintf(stderr, "Failed to parse file URI <%s>\n", data_uri.c_str());
return;
}
- const uint8_t* path = (const uint8_t*)(data_uri.c_str() + 5);
-
// FIXME: blank prefix parameter?
SerdReader* reader = sord_new_reader(_c_obj, env, syntax, NULL);
serd_reader_read_file(reader, path);
serd_reader_free(reader);
+ free(path);
}
inline SerdStatus
Model::write_to_file(const std::string& uri, SerdSyntax syntax, SerdStyle style)
{
- if (uri.substr(0, 5) != "file:") {
+ uint8_t* path = serd_file_uri_parse((const uint8_t*)uri.c_str(), NULL);
+ if (!path) {
+ fprintf(stderr, "Failed to parse file URI <%s>\n", uri.c_str());
return SERD_ERR_BAD_ARG;
}
- const uint8_t* path;
- if (uri.substr(0, 7) == "file://") {
- path = (const uint8_t*)uri.c_str() + 7;
- } else {
- path = (const uint8_t*)uri.c_str() + 5;
- }
-
FILE* const fd = fopen((const char*)path, "w");
if (!fd) {
fprintf(stderr, "Failed to open file %s\n", path);
+ free(path);
return SERD_ERR_UNKNOWN;
}
+ free(path);
SerdURI base_uri = SERD_URI_NULL;
if (serd_uri_parse((const uint8_t*)uri.c_str(), &base_uri)) {