]> git.lyx.org Git - features.git/commitdiff
Fix bug #253 (Incorrect protection of closing quotation marks)
authorEnrico Forestieri <forenr@lyx.org>
Fri, 5 Aug 2011 11:23:00 +0000 (11:23 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 5 Aug 2011 11:23:00 +0000 (11:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39420 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetQuotes.cpp
src/support/docstream.cpp
src/support/docstream.h

index 0792e15e91dbbb66a3f43c6f239e39d170f1b82f..8586ce18d5372382689ae1cbcacbb93ddede55f5 100644 (file)
@@ -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);
 }
index f5cf297c12644eb324e58e5e37acb17fb14fdd84..3fb0c032951db82adb812f49bc45aa0a2d62b705 100644 (file)
@@ -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<odocstream_manip>(endl))
+       if (pf == static_cast<odocstream_manip>(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 <typename Type>
 otexstream & operator<<(otexstream & ots, Type value)
 {
        ots.os() << value;
+       ots.lastChar(0);
        ots.canBreakLine(true);
        ots.protectSpace(false);
        return ots;
index 0ad670968578d00b07358c75a11ce6aa2677fbe7..f59030f9238ec7125023acc8a43ebd0e90aa5340 100644 (file)
@@ -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