diff --git a/DataStructures/PolylineCompressor.h b/DataStructures/PolylineCompressor.h index 56fd49a25..a6fff4409 100644 --- a/DataStructures/PolylineCompressor.h +++ b/DataStructures/PolylineCompressor.h @@ -78,10 +78,10 @@ public: output += "["; string tmp; for(unsigned i = 0; i < polyline.size(); i++) { - convertLatLon(polyline[i].lat, tmp); + convertInternalLatLonToString(polyline[i].lat, tmp); output += "["; output += tmp; - convertLatLon(polyline[i].lon, tmp); + convertInternalLatLonToString(polyline[i].lon, tmp); output += ", "; output += tmp; output += "]"; diff --git a/Plugins/GPXDescriptor.h b/Plugins/GPXDescriptor.h index c438b6fb4..56c743b30 100644 --- a/Plugins/GPXDescriptor.h +++ b/Plugins/GPXDescriptor.h @@ -49,9 +49,9 @@ public: startName = sEngine->GetEscapedNameForNameID(streetID); streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); targetName = sEngine->GetEscapedNameForNameID(streetID); - convertLatLon(phantomNodes->startCoord.lat, tmp); + convertInternalLatLonToString(phantomNodes->startCoord.lat, tmp); bodyString += ("\t\tstartCoord.lon, tmp); + convertInternalLatLonToString(phantomNodes->startCoord.lon, tmp); bodyString += (" lon=\""+tmp+"\">"); bodyString += ("\n\t\t\tStart from "); bodyString += startName; @@ -118,20 +118,15 @@ public: nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node); } - convertLatLon(current.lat, tmp); + convertInternalLatLonToString(current.lat, tmp); bodyString += "\n\t\t\n"; double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next); if(178 > angle || 182 < angle) { - convertLatLon(current.lon, tmp); + convertInternalCoordinateToString(current, tmp); lineString += tmp; - lineString += ","; - convertLatLon(current.lat, tmp); - lineString += tmp; - lineString += " "; - startOfSegment = current; } if(nextID == nameID) { @@ -150,9 +145,6 @@ public: bodyString += "follow road "; if(nameID != 0) bodyString += sEngine->GetEscapedNameForNameID(nameID); - string lat; string lon; - convertLatLon(lastPlace.lon, lon); - convertLatLon(lastPlace.lat, lat); lastPlace = current; if(angle > 160 && angle < 200) { bodyString += /* " (" << angle << ")*/"drive ahead, "; @@ -185,9 +177,9 @@ public: previous = current; type = nextType; } - convertLatLon(phantomNodes->targetCoord.lat, tmp); + convertInternalLatLonToString(phantomNodes->targetCoord.lat, tmp); bodyString += "\n\t\ttargetCoord.lon, tmp); + convertInternalLatLonToString(phantomNodes->targetCoord.lon, tmp); bodyString += "lon=\"" + tmp + "\">\n"; bodyString += "\t\t\t"; @@ -210,10 +202,7 @@ public: //put targetCoord to linestring - convertLatLon(phantomNodes->targetCoord.lon, tmp); - lineString += tmp; - lineString += ","; - convertLatLon(phantomNodes->targetCoord.lat, tmp); + convertInternalCoordinateToString(phantomNodes->targetCoord, tmp); lineString += tmp; ostringstream s; s << 10*(round(entireDistance/10.)); diff --git a/Plugins/KMLDescriptor.h b/Plugins/KMLDescriptor.h index cd0230a24..5b79169bb 100644 --- a/Plugins/KMLDescriptor.h +++ b/Plugins/KMLDescriptor.h @@ -77,12 +77,8 @@ public: reply.content += ("]]>\n"); //put start coord to linestring; - convertLatLon(phantomNodes->startCoord.lon, tmp); + convertInternalCoordinateToString(phantomNodes->startCoord, tmp); lineString += tmp; - lineString += ","; - convertLatLon(phantomNodes->startCoord.lat, tmp); - lineString += tmp; - lineString += " "; reply.content += ("\t\n"); _Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon); @@ -114,13 +110,8 @@ public: double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next); if(178 > angle || 182 < angle) { - convertLatLon(current.lon, tmp); + convertInternalCoordinateToString(current, tmp); lineString += tmp; - lineString += ","; - convertLatLon(current.lat, tmp); - lineString += tmp; - lineString += " "; - startOfSegment = current; } if(nextID == nameID) { @@ -153,9 +144,6 @@ public: reply.content += numberString.str(); numberString.str(""); reply.content += "m"; - string lat; string lon; - convertLatLon(lastPlace.lon, lon); - convertLatLon(lastPlace.lat, lat); lastPlace = current; // reply.content += "\n "; // reply.content += ""; @@ -217,10 +205,7 @@ public: reply.content += "\t\n"; //put targetCoord to linestring - convertLatLon(phantomNodes->targetCoord.lon, tmp); - lineString += tmp; - lineString += ","; - convertLatLon(phantomNodes->targetCoord.lat, tmp); + convertInternalCoordinateToString(phantomNodes->targetCoord, tmp); lineString += tmp; if(!config.geometry){ diff --git a/Util/StrIngUtil.h b/Util/StrIngUtil.h index 8ef5447a5..d2880c24e 100644 --- a/Util/StrIngUtil.h +++ b/Util/StrIngUtil.h @@ -52,8 +52,7 @@ inline char* printInt( char* buffer, int value ) return buffer; } -inline void intToString(const int value, std::string & output) -{ +inline void intToString(const int value, std::string & output) { // The largest 32-bit integer is 4294967295, that is 10 chars // On the safe side, add 1 for sign, and 1 for trailing zero char buffer[12] ; @@ -61,7 +60,7 @@ inline void intToString(const int value, std::string & output) output = buffer ; } -inline void convertLatLon(const int value, std::string & output) +inline void convertInternalLatLonToString(const int value, std::string & output) { char buffer[100]; buffer[10] = 0; // Nullterminierung @@ -69,9 +68,26 @@ inline void convertLatLon(const int value, std::string & output) output = string; } -/* used to be boosts lexical cast, but this was too slow */ -inline void doubleToString(const double value, std::string & output) -{ +inline void convertInternalCoordinateToString(const _Coordinate & coord, std::string & output) { + std::string tmp; + convertInternalLatLonToString(coord.lon, tmp); + output = tmp; + output += ","; + convertInternalLatLonToString(coord.lat, tmp); + output += tmp; + output += " "; +} +inline void convertInternalReversedCoordinateToString(const _Coordinate & coord, std::string & output) { + std::string tmp; + convertInternalLatLonToString(coord.lat, tmp); + output = tmp; + output += ","; + convertInternalLatLonToString(coord.lon, tmp); + output += tmp; + output += " "; +} + +inline void doubleToString(const double value, std::string & output){ // The largest 32-bit integer is 4294967295, that is 10 chars // On the safe side, add 1 for sign, and 1 for trailing zero char buffer[12] ; @@ -91,6 +107,22 @@ inline std::string & replaceAll(std::string &s, const std::string &sub, const st return s; } +std::vector &split(const std::string &s, char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while(std::getline(ss, item, delim)) { + if(item.size() > 0) + elems.push_back(item); + } + return elems; +} + +std::vector split(const std::string &s, char delim) { + std::vector elems; + return split(s, delim, elems); +} + + std::string originals[] = {"&", "\"", "<", ">", "'", "[", "]"}; std::string entities[] = {"&", """, "<", ">", "'", "&91;", "&93;" };