Skip to content

Commit e5c8e5d

Browse files
authored
Fix compile issues related to std::string use in the SVG plugin (#872)
1 parent f96fec3 commit e5c8e5d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Source/SVG/ElementSVG.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ void ElementSVG::SetInnerRML(const String& content)
120120
if (!source.empty())
121121
return;
122122

123+
// 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
124+
// a non-std string.
123125
if (!HasAttribute("rmlui-svgdata-id"))
124-
SetAttribute("rmlui-svgdata-id", "svgdata:" + std::to_string(internal_id_counter++));
126+
SetAttribute("rmlui-svgdata-id", "svgdata:" + CreateString("%lu", internal_id_counter++));
125127

126128
svg_data = "" + content;
127129
svg_dirty = true;

Source/SVG/SVGCache.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,16 @@ namespace SVG {
189189
return {};
190190
}
191191

192-
// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr)
193-
doc.svg_document.reset(lunasvg::Document::loadFromData(svg_data).release());
192+
// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr). We also use
193+
// loadFromData(char*, size_t) instead of loadFromData(std::string) in case clients use a non-std string.
194+
doc.svg_document.reset(lunasvg::Document::loadFromData(svg_data.data(), svg_data.size()).release());
194195
}
195196
else
196197
{
197198
RMLUI_SVG_DEBUG_LOG("Loading SVG document from element %s contents", source_id.c_str());
198-
// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr)
199-
doc.svg_document.reset(lunasvg::Document::loadFromData(source).release());
199+
// We use a reset-release approach here in case clients use a non-std unique_ptr (lunasvg uses std::unique_ptr). We also use
200+
// loadFromData(char*, size_t) instead of loadFromData(std::string) in case clients use a non-std string.
201+
doc.svg_document.reset(lunasvg::Document::loadFromData(source.data(), source.size()).release());
200202
}
201203

202204
if (!doc.svg_document)

0 commit comments

Comments
 (0)