summaryrefslogtreecommitdiffstats
path: root/src/uscxml/URL.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2012-11-07 22:20:09 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2012-11-07 22:20:09 (GMT)
commitda08a1d3c3bca8070c9b029cfc1f8faf9e34dd25 (patch)
treeb285148ab6ca415814d9370148f91736f83c852c /src/uscxml/URL.cpp
parent0ae6c27d9322208053033d9b19c0ffffed3d99eb (diff)
downloaduscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.zip
uscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.tar.gz
uscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.tar.bz2
Committing local version again
Diffstat (limited to 'src/uscxml/URL.cpp')
-rw-r--r--src/uscxml/URL.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp
new file mode 100644
index 0000000..722352d
--- /dev/null
+++ b/src/uscxml/URL.cpp
@@ -0,0 +1,41 @@
+#include "URL.h"
+#include <glog/logging.h>
+#include <algorithm>
+
+namespace uscxml {
+
+std::ostream & operator<<(std::ostream & stream, const URL& url) {
+
+ std::string urlString = url._urlString;
+ std::string fileURL = "file://";
+
+ // strip file:// to support relative filenames
+ if(urlString.substr(0, fileURL.size()) == fileURL) {
+ urlString = urlString.substr(fileURL.size());
+#ifdef _WIN32
+ urlString = urlString.substr(0,1) + ":" + urlString.substr(1);
+// std::replace( urlString.begin(), urlString.end(), '/', '\\');
+#endif
+ }
+ LOG(ERROR) << "Trying to open " << urlString;
+ URL_FILE *handle = url_fopen(urlString.c_str(), "r");
+
+ if(!handle) {
+ LOG(ERROR) << "Cannot open URL " << url._urlString;
+ return stream;
+ }
+
+ int nread;
+ char buffer[256];
+
+ do {
+ nread = url_fread(buffer, 1,sizeof(buffer), handle);
+ stream.write(buffer, nread);
+ } while(nread);
+
+ url_fclose(handle);
+ return stream;
+}
+
+
+} \ No newline at end of file