Răsfoiți Sursa

Fix compile issues related to std::string use in the SVG plugin (#872)

Trévis Morvany 1 lună în urmă
părinte
comite
e5c8e5dd6b
2 a modificat fișierele cu 9 adăugiri și 5 ștergeri
  1. 3 1
      Source/SVG/ElementSVG.cpp
  2. 6 4
      Source/SVG/SVGCache.cpp

+ 3 - 1
Source/SVG/ElementSVG.cpp

@@ -120,8 +120,10 @@ void ElementSVG::SetInnerRML(const String& content)
 	if (!source.empty())
 		return;
 
+	// We use CreateString instead of std::to_string to avoid having to create an extra std::string and convert it to Rml::String in case clients use
+	// a non-std string.
 	if (!HasAttribute("rmlui-svgdata-id"))
-		SetAttribute("rmlui-svgdata-id", "svgdata:" + std::to_string(internal_id_counter++));
+		SetAttribute("rmlui-svgdata-id", "svgdata:" + CreateString("%lu", internal_id_counter++));
 
 	svg_data = "" + content;
 	svg_dirty = true;

+ 6 - 4
Source/SVG/SVGCache.cpp

@@ -189,14 +189,16 @@ namespace SVG {
 					return {};
 				}
 
-				// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr)
-				doc.svg_document.reset(lunasvg::Document::loadFromData(svg_data).release());
+				// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr). We also use
+				// loadFromData(char*, size_t) instead of loadFromData(std::string) in case clients use a non-std string.
+				doc.svg_document.reset(lunasvg::Document::loadFromData(svg_data.data(), svg_data.size()).release());
 			}
 			else
 			{
 				RMLUI_SVG_DEBUG_LOG("Loading SVG document from element %s contents", source_id.c_str());
-				// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr)
-				doc.svg_document.reset(lunasvg::Document::loadFromData(source).release());
+				// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr). We also use
+				// loadFromData(char*, size_t) instead of loadFromData(std::string) in case clients use a non-std string.
+				doc.svg_document.reset(lunasvg::Document::loadFromData(source.data(), source.size()).release());
 			}
 
 			if (!doc.svg_document)