From de9c3ea2407eb2b307cb64ce774926d276ae5cce Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Mon, 9 Feb 2009 20:22:04 +0000 Subject: [PATCH] Implement the old dialog backslash behaviour. I'm not sure whether the old backslash behaviour is really a good idea but now we keep backwards compatibility. Also added a test case. --- data/scenario-test.cfg | 3 ++- src/gui/widgets/control.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/data/scenario-test.cfg b/data/scenario-test.cfg index c62f6e19f22..d70c6c13ca5 100644 --- a/data/scenario-test.cfg +++ b/data/scenario-test.cfg @@ -440,7 +440,8 @@ Xu , Xu , Qxu , Qxu , Ql , Ql [/option] [option] # Should have an empty first column. - message=" =A nice and black\nToo dark too see?=Take a sip and pass the bottle along" + # Should show \/\/ell a nice and black drink. Too dark too see?. + message=" =\\/\\/ell a \nice and black drink. Too dark too see?=Take a sip and pass the bottle along" [/option] [/message] [/event] diff --git a/src/gui/widgets/control.cpp b/src/gui/widgets/control.cpp index e2fa449e170..ead9c32a7d9 100644 --- a/src/gui/widgets/control.cpp +++ b/src/gui/widgets/control.cpp @@ -23,6 +23,8 @@ #include +#define WRN_CF LOG_STREAM(warn, config) + namespace gui2 { tcontrol::tcontrol(const unsigned canvas_count) @@ -407,8 +409,13 @@ std::string colour_prefix(const SDL_Color& colour) return result.str(); } -/** escapes a string to be used in a pango formatted string. */ -std::string escape_string(const std::string& str) +/** + * Escapes a string to be used in a pango formatted string. + * + * This function also changes every "\x" to "x" thus also "\\" to "\". This + * is used to mimic the old dialog behaviour. + */ +std::string escape_string(std::string str) { struct tconverter { @@ -425,6 +432,13 @@ std::string escape_string(const std::string& str) gchar* str; }; + size_t offset = str.find('\\', 0); + while (offset != std::string::npos) { + str.erase(offset, 1); + ++offset; + offset = str.find('\\', offset); + } + tconverter converter(str); return std::string(converter.str); }