HTML entities in street names

This commit is contained in:
Dennis Luxen 2011-05-13 09:15:37 +00:00
parent 5c0ed9229d
commit 1cbf2ab0d7
2 changed files with 26 additions and 7 deletions

View File

@ -295,12 +295,12 @@ public:
return ed.distance;
}
inline std::string &GetNameForNameID(const NodeID nameID) const {
inline std::string &GetUnescapedNameForNameID(const NodeID nameID) const {
return (nameID >= _names->size() ? _names->at(0) : _names->at(nameID) );
}
inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
return (nameID >= _names->size() ? _names->at(0) : replaceAll(_names->at(nameID), "\"", "\\\"") );
return ( nameID >= _names->size() ? std::string("") : HTMLEntitize(_names->at(nameID)) );
}
inline short GetTypeOfEdgeForOriginDestinationNodeID(NodeID s, NodeID t) const {

View File

@ -79,12 +79,31 @@ inline void doubleToString(const double value, std::string & output)
output = buffer ;
}
inline std::string & replaceAll(std::string &s, const std::string &sub, const std::string &other) {
assert(!sub.empty());
size_t b = 0;
for (;;) {
b = s.find(sub, b);
if (b == s.npos) break;
s.replace(b, sub.size(), other);
b += other.size();
}
return s;
}
std::string replaceAll( std::string result, const std::string& replaceWhat, const std::string& replaceWithWhat) {
while(true) {
const int pos = result.find(replaceWhat);
if (pos==-1) break;
result.replace(pos,replaceWhat.size(),replaceWithWhat);
std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]"};
std::string entities[] = {"&amp;", "&quot;", "&lt;", "&gt;", "&#39;", "&91;", "&93;" };
std::string HTMLEntitize( std::string result) {
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); i++) {
result = replaceAll(result, originals[i], entities[i]);
}
return result;
}
std::string HTMLDeEntitize( std::string result) {
for(unsigned i = 0; i < sizeof(originals)/sizeof(std::string); i++) {
result = replaceAll(result, entities[i], originals[i]);
}
return result;
}