From: Enrico Forestieri Date: Fri, 5 Aug 2011 11:23:00 +0000 (+0000) Subject: Fix bug #253 (Incorrect protection of closing quotation marks) X-Git-Tag: 2.1.0beta1~2855 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2de1163efcde07edd731845e4c68ff8b597a40a8;p=features.git Fix bug #253 (Incorrect protection of closing quotation marks) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39420 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index 0792e15e91..8586ce18d5 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -287,8 +287,11 @@ void InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const } // Always guard against unfortunate ligatures (!` ?`) - if (prefixIs(qstr, "`")) - qstr.insert(0, "{}"); + if (prefixIs(qstr, "`")) { + char_type const lastchar = os.lastChar(); + if (lastchar == '!' || lastchar == '?') + qstr.insert(0, "{}"); + } os << from_ascii(qstr); } diff --git a/src/support/docstream.cpp b/src/support/docstream.cpp index f5cf297c12..3fb0c03295 100644 --- a/src/support/docstream.cpp +++ b/src/support/docstream.cpp @@ -411,6 +411,7 @@ void otexstream::put(char_type const & c) protectspace_ = false; } os_.put(c); + lastchar_ = c; if (c == '\n') { texrow_.newline(); canbreakline_ = false; @@ -427,6 +428,7 @@ otexstream & operator<<(otexstream & ots, BreakLine) { if (ots.canBreakLine()) { ots.os().put('\n'); + ots.lastChar('\n'); ots.canBreakLine(false); ots.texrow().newline(); } @@ -439,6 +441,7 @@ otexstream & operator<<(otexstream & ots, SafeBreakLine) { if (ots.canBreakLine()) { ots.os() << "%\n"; + ots.lastChar('\n'); ots.canBreakLine(false); ots.texrow().newline(); } @@ -450,8 +453,10 @@ otexstream & operator<<(otexstream & ots, SafeBreakLine) otexstream & operator<<(otexstream & ots, odocstream_manip pf) { ots.os() << pf; - if (pf == static_cast(endl)) + if (pf == static_cast(endl)) { + ots.lastChar('\n'); ots.texrow().newline(); + } return ots; } @@ -470,6 +475,7 @@ otexstream & operator<<(otexstream & ots, docstring const & s) ots.protectSpace(false); } ots.os() << s; + ots.lastChar(s[len - 1]); ots.texrow().newlines(count(s.begin(), s.end(), '\n')); ots.canBreakLine(s[len - 1] != '\n'); return ots; @@ -490,6 +496,7 @@ otexstream & operator<<(otexstream & ots, char const * s) ots.protectSpace(false); } ots.os() << s; + ots.lastChar(s[len - 1]); ots.texrow().newlines(count(s, s + len, '\n')); ots.canBreakLine(s[len - 1] != '\n'); return ots; @@ -504,6 +511,7 @@ otexstream & operator<<(otexstream & ots, char c) ots.protectSpace(false); } ots.os() << c; + ots.lastChar(c); if (c == '\n') ots.texrow().newline(); ots.canBreakLine(c != '\n'); @@ -515,6 +523,7 @@ template otexstream & operator<<(otexstream & ots, Type value) { ots.os() << value; + ots.lastChar(0); ots.canBreakLine(true); ots.protectSpace(false); return ots; diff --git a/src/support/docstream.h b/src/support/docstream.h index 0ad6709685..f59030f923 100644 --- a/src/support/docstream.h +++ b/src/support/docstream.h @@ -93,6 +93,7 @@ typedef odocstream & (*odocstream_manip)(odocstream &); they were iomanip's to ensure that the next output will start at the beginning of a line. Using "breakln", a '\n' char will be output if needed, while using "safebreakln", "%\n" will be output if needed. + The class also records the last output character. */ class otexstream { @@ -100,7 +101,7 @@ public: /// otexstream(odocstream & os, TexRow & texrow) : os_(os), texrow_(texrow), - canbreakline_(false), protectspace_(false) {} + canbreakline_(false), protectspace_(false), lastchar_(0) {} /// odocstream & os() { return os_; } /// @@ -115,6 +116,10 @@ public: void protectSpace(bool protectspace) { protectspace_ = protectspace; } /// bool protectSpace() const { return protectspace_; } + /// + void lastChar(char_type const & c) { lastchar_ = c; } + /// + char_type lastChar() const { return lastchar_; } private: /// odocstream & os_; @@ -124,6 +129,8 @@ private: bool canbreakline_; /// bool protectspace_; + /// + char_type lastchar_; }; /// Helper structs for breaking a line