diff --git a/libs/ui/source/file_dialog.cpp b/libs/ui/source/file_dialog.cpp index c4b24b1c..b3183e49 100644 --- a/libs/ui/source/file_dialog.cpp +++ b/libs/ui/source/file_dialog.cpp @@ -98,6 +98,23 @@ namespace psemek::ui gfx::texture_2d file_; }; + std::string replace(std::string str, std::string const & match, std::string const & replacement) + { + for (std::size_t i = 0; (i = str.find(match, i)) != std::string::npos;) + { + str.replace(i, match.size(), replacement); + i += replacement.size(); + } + return str; + } + + std::string escape(std::string str) + { + str = replace(std::move(str), "[", "\\["); + str = replace(std::move(str), "]", "\\]"); + return str; + } + } std::shared_ptr make_file_dialog(file_dialog_options const & options) @@ -217,9 +234,9 @@ namespace psemek::ui for (auto const & component : new_path) { if (component.string() != "/") - path_str += "[link:" + util::to_string(++index) + "]" + component.string() + "[/link]/"; + path_str += "[link:" + util::to_string(++index) + "]" + escape(component.string()) + "[/link]/"; else - path_str += "[link:" + util::to_string(++index) + "]" + component.string() + "[/link]"; + path_str += "[link:" + util::to_string(++index) + "]" + escape(component.string()) + "[/link]"; } current_path_label->set_tagged_text(std::move(path_str)); @@ -265,7 +282,7 @@ namespace psemek::ui contents_str += "[image:file]"; contents_str += "[link:" + util::to_string(index++) + "]"; - contents_str += entry.path.filename().string() + "[/link]\n"; + contents_str += escape(entry.path.filename().string()) + "[/link]\n"; } directory_view->set_tagged_text(std::move(contents_str)); directory_view_scroller->set_position(scroller::direction::vertical, 0.f, false);