diff options
author | tradke <tradke@83718e91-0e4f-0410-abf4-91180603181f> | 2006-08-01 09:19:38 +0000 |
---|---|---|
committer | tradke <tradke@83718e91-0e4f-0410-abf4-91180603181f> | 2006-08-01 09:19:38 +0000 |
commit | 89675b01d88750bfe336d6c9f803067d8e6a71b4 (patch) | |
tree | 970d4552243f523d8ad1e3a350bff47383fe9d7a | |
parent | 151b03203ee1269c6156604be41a9683a18943f3 (diff) |
Added utility function rdf::cleanURI() to convert a string into a correct URI
string.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@110 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r-- | src/rdf.cc | 29 | ||||
-rw-r--r-- | src/rdf.hh | 4 |
2 files changed, 31 insertions, 2 deletions
@@ -239,8 +239,10 @@ namespace Formaline assert (ierr >= 0); if (ierr > 0) break; + // brackets in array parameter names have to be escaped msgbuf << "\t<cctk:hasParameter rdf:resource=\"#Parameters/" - << pdata->thorn << "/" << pdata->name << "\"/>" << endl; + << pdata->thorn << "/" << cleanURI (pdata->name) << "\"/>" + << endl; // get its value const void* const pvalue @@ -296,8 +298,10 @@ namespace Formaline } // switch (pdata->type) + // brackets in array parameter names have to be escaped parambuf << "<cctk:" << paramtype << " rdf:about=\"#Parameters/" - << pdata->thorn << "/" << pdata->name << "\">" << endl + << pdata->thorn << "/" << cleanURI (pdata->name) << "\">" + << endl << "\t<cctk:hasName>" << fullname << "</cctk:hasName>" << endl << "\t<cctk:hasValue>" << paramvaluebuf.str() @@ -558,6 +562,27 @@ namespace Formaline } + string rdf:: + cleanURI (string const & uri) + const + { + const string allowed_charset ("-_.!~*'()/"); + ostringstream buf; + + for (string::const_iterator p = uri.begin(); p != uri.end(); ++ p) { + if (isalnum (*p) or allowed_charset.find (*p, 0) != string::npos) { + buf << *p; + } else if (*p == ' ') { + buf << '+'; + } else { + buf << '%' << hex << int (*p); + } + } + + return buf.str(); + } + + #if 0 static list<string> @@ -55,6 +55,10 @@ namespace Formaline clean (std::string const & txt) const; + std::string + cleanURI (std::string const & uri) + const; + void Initial (void); void Update (cGH const * cctkGH); }; |