]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetQuotes.cpp
Constify InsetQuotesParams
[features.git] / src / insets / InsetQuotes.cpp
index aa2e41bea8217041e8fca20178d624623e56e6bb..b9b6557a5ebc3950d5a2d01af19c8c48b9d773bc 100644 (file)
 #include "LyXRC.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
-#include "output_xhtml.h"
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "texstream.h"
+#include "xml.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -100,7 +100,7 @@ char InsetQuotesParams::getStyleChar(QuoteStyle const & style) const
 
 
 InsetQuotesParams::QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s,
-                           bool const allow_wildcards, QuoteStyle fb)
+                           bool const allow_wildcards, QuoteStyle fb) const
 {
        QuoteStyle res = fb;
 
@@ -132,7 +132,7 @@ InsetQuotesParams::QuoteStyle InsetQuotesParams::getQuoteStyle(string const & s,
 
 
 InsetQuotesParams::QuoteSide InsetQuotesParams::getQuoteSide(string const & s,
-                       bool const allow_wildcards, QuoteSide fb)
+                       bool const allow_wildcards, QuoteSide fb) const
 {
        QuoteSide res = fb;
 
@@ -164,7 +164,7 @@ InsetQuotesParams::QuoteSide InsetQuotesParams::getQuoteSide(string const & s,
 
 
 InsetQuotesParams::QuoteLevel InsetQuotesParams::getQuoteLevel(string const & s,
-                       bool const allow_wildcards, QuoteLevel fb)
+                       bool const allow_wildcards, QuoteLevel fb) const
 {
        QuoteLevel res = fb;
 
@@ -430,7 +430,7 @@ docstring InsetQuotesParams::getLaTeXQuote(char_type c, string const & op,
        }
        // The following are fakes
        // This is just to get something symbolic
-       // in encodings where this chars would not be used ayway
+       // in encodings where this chars would not be used anyway
        case 0x300c: // LEFT CORNER BRACKET
                res = "\\ensuremath{\\lceil}";
                break;
@@ -538,74 +538,8 @@ docstring InsetQuotesParams::getHTMLQuote(char_type c) const
 
 docstring InsetQuotesParams::getXMLQuote(char_type c) const
 {
-       string res;
-
-       switch (c){
-               case 0x201a: // ,
-                       res = "‚";
-                       break;
-               case 0x2019: // '
-                       res = "’";
-                       break;
-               case 0x2018: // `
-                       res = "‘";
-                       break;
-               case 0x2039: // <
-                       res = "&#8249;";
-                       break;
-               case 0x203a: // >
-                       res = "&#8250;";
-                       break;
-               case 0x0027: // ' (plain)
-                       res = "&#x27;";
-                       break;
-               case 0x201e: // ,,
-                       res = "&#8222;";
-                       break;
-               case 0x201d: // ''
-                       res = "&#8221;";
-                       break;
-               case 0x201c: // ``
-                       res = "&#8220;";
-                       break;
-               case 0x00ab: // <<
-                       res = "&#171;";
-                       break;
-               case 0x00bb: // >>
-                       res = "&#187;";
-                       break;
-               case 0x0022: // "
-                       res = "&#34;";
-                       break;
-               case 0x300c: // LEFT CORNER BRACKET
-                       res = "&#x300c;";
-                       break;
-               case 0x300d: // RIGHT CORNER BRACKET
-                       res = "&#x300d;";
-                       break;
-               case 0x300e: // LEFT WHITE CORNER BRACKET
-                       res = "&#x300e;";
-                       break;
-               case 0x300f: // RIGHT WHITE CORNER BRACKET
-                       res = "&#x300f;";
-                       break;
-               case 0x300a: // LEFT DOUBLE ANGLE BRACKET
-                       res = "&#x300a;";
-                       break;
-               case 0x300b: // RIGHT DOUBLE ANGLE BRACKET
-                       res = "&#x300b;";
-                       break;
-               case 0x3008: // LEFT ANGLE BRACKET
-                       res = "&#x3008;";
-                       break;
-               case 0x3009: // RIGHT ANGLE BRACKET
-                       res = "&#x3009;";
-                       break;
-               default:
-                       break;
-       }
-
-       return from_ascii(res);
+       // Directly output the character Unicode form.
+       return from_ascii("&#" + to_string(c) + ";");
 }
 
 
@@ -640,7 +574,7 @@ map<string, docstring> InsetQuotesParams::getTypes() const
 }
 
 
-docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langdef)
+docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langdef) const
 {
        docstring const styledesc =
                bformat(_("%1$souter%2$s and %3$sinner%4$s[[quotation marks]]"),
@@ -658,7 +592,7 @@ docstring const InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langd
 }
 
 
-docstring const InsetQuotesParams::getShortGuiLabel(docstring const & str)
+docstring const InsetQuotesParams::getShortGuiLabel(docstring const & str) const
 {
        string const s = to_ascii(str);
        QuoteStyle const style = getQuoteStyle(s);
@@ -1024,6 +958,7 @@ docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
                        (style_ == InsetQuotesParams::DynamicQuotes) ? global_style_ : style_;
        docstring res = isHTML ? quoteparams.getHTMLQuote(quoteparams.getQuoteChar(style, level_, side_)) :
                                        quoteparams.getXMLQuote(quoteparams.getQuoteChar(style, level_, side_));
+
        // in French, thin spaces are added inside double guillemets
        if (prefixIs(context_lang_, "fr")
            && level_ == InsetQuotesParams::PrimaryQuotes
@@ -1032,19 +967,18 @@ docstring InsetQuotes::getQuoteEntity(bool isHTML) const {
                || style == InsetQuotesParams::SwissQuotes)) {
                // THIN SPACE (U+2009)
                docstring const thin_space = from_ascii("&#x2009;");
-               if (side_ == InsetQuotesParams::OpeningQuote)
+               if (side_ == InsetQuotesParams::OpeningQuote) // Open quote: space after
                        res += thin_space;
-               else
+               else // Close quote: space before
                        res = thin_space + res;
        }
        return res;
 }
 
 
-int InsetQuotes::docbook(odocstream & os, OutputParams const &) const
+void InsetQuotes::docbook(XMLStream & xs, OutputParams const &) const
 {
-       os << getQuoteEntity(false);
-       return 0;
+       xs << XMLStream::ESCAPE_NONE << getQuoteEntity(false);
 }
 
 
@@ -1123,10 +1057,10 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
        switch (type) {
        case 0x0027: {
                if (features.runparams().isFullUnicode() && fontspec_)
-                               features.require("textquotesinglep");
-                       else
-                               features.require("textcomp");
-                       break;
+                       features.require("textquotesinglep");
+               else
+                       features.require("textcomp");
+               break;
        }
        case 0x0022: {
                if (features.runparams().isFullUnicode() && fontspec_)