Skip to content

Commit

Permalink
fix: try to get rid of gcc-ASAN weird error
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Dec 20, 2024
1 parent 154e515 commit 34ac7ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ggiraph
Title: Make 'ggplot2' Graphics Interactive
Version: 0.8.11
Version: 0.8.12
Authors@R: c(
person("David", "Gohel", , "[email protected]", role = c("aut", "cre")),
person("Panagiotis", "Skintzos", , "[email protected]", role = "aut"),
Expand Down
14 changes: 12 additions & 2 deletions src/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include "dsvg.h"
#include <regex>

std::string safe_regex_replace(const std::string& input, const std::string& pattern, const std::string& replacement) {
size_t start_pos = 0;
std::string result = input;
while ((start_pos = result.find(pattern, start_pos)) != std::string::npos) {
result.replace(start_pos, pattern.length(), replacement);
start_pos += replacement.length(); // Advance past the replacement
}
return result;
}

INDEX InteractiveElements::push(SVGElement* el) {
const INDEX index = IndexedElements::push(el);
if (el) {
Expand Down Expand Up @@ -81,8 +91,8 @@ std::string compile_css(const std::string& cls_prefix, const char* cls_suffix,
const std::string& canvas_id, const char* data_attr,
const char* data_value, const char* css) {
std::string cls = cls_prefix + cls_suffix + canvas_id + "[" + data_attr + " = \"" + data_value + "\"]";
std::regex pattern("_CLASSNAME_");
return std::regex_replace(css, pattern, cls);
std::string css_str(css);
return safe_regex_replace(css_str, "_CLASSNAME_", cls);;
}

// [[Rcpp::export]]
Expand Down

0 comments on commit 34ac7ce

Please sign in to comment.