]> git.lyx.org Git - lyx.git/commitdiff
Docstringify getLongString in general and preamble snippets in particular
authorGuillaume Munch <gm@lyx.org>
Sun, 25 Sep 2016 10:37:40 +0000 (12:37 +0200)
committerGuillaume Munch <gm@lyx.org>
Sun, 16 Oct 2016 22:16:59 +0000 (00:16 +0200)
Prepare ground for TexRow InPreamble

27 files changed:
src/Buffer.cpp
src/BufferEncodings.cpp
src/BufferParams.cpp
src/BufferParams.h
src/Floating.cpp
src/Floating.h
src/LaTeXFeatures.cpp
src/LaTeXFeatures.h
src/LaTeXFonts.cpp
src/LaTeXFonts.h
src/Language.cpp
src/Language.h
src/Layout.cpp
src/Lexer.cpp
src/Lexer.h
src/Paragraph.cpp
src/TextClass.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiExternal.cpp
src/insets/ExternalTemplate.cpp
src/insets/ExternalTemplate.h
src/insets/InsetExternal.cpp
src/insets/InsetLayout.cpp
src/insets/InsetRef.cpp
src/mathed/InsetMathHull.cpp
src/support/lstrings.cpp
src/support/lstrings.h

index 8f04ae4e0b63bc413ccf007beed3f230911516c4..196d23d25eb907f84690f9952f58383c9ffc5f1c 100644 (file)
@@ -909,8 +909,8 @@ int Buffer::readHeader(Lexer & lex)
        params().html_latex_end.clear();
        params().html_math_img_scale = 1.0;
        params().output_sync_macro.erase();
-       params().setLocalLayout(string(), false);
-       params().setLocalLayout(string(), true);
+       params().setLocalLayout(docstring(), false);
+       params().setLocalLayout(docstring(), true);
 
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
@@ -1985,7 +1985,7 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname,
                else
                        os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
 
-               docstring preamble = from_utf8(params().preamble);
+               docstring preamble = params().preamble;
                if (runparams.flavor != OutputParams::XML ) {
                        preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
                        preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
@@ -2088,14 +2088,14 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
                if (!styles.empty())
                        os << "\n<!-- Text Class Preamble -->\n" << styles << '\n';
 
-               styles = from_utf8(features.getPreambleSnippets());
+               styles = features.getPreambleSnippets();
                if (!styles.empty())
                        os << "\n<!-- Preamble Snippets -->\n" << styles << '\n';
 
                // we will collect CSS information in a stream, and then output it
                // either here, as part of the header, or else in a separate file.
                odocstringstream css;
-               styles = from_utf8(features.getCSSSnippets());
+               styles = features.getCSSSnippets();
                if (!styles.empty())
                        css << "/* LyX Provided Styles */\n" << styles << '\n';
 
index 87000ac9c82402e7f24443f580926dc6c2340bf1..2cd07f2c2905d785c629a209543ca51ae43e5b7d 100644 (file)
@@ -81,7 +81,7 @@ void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_m
                                                features.require(feat);
                                        }
                                } else
-                                       features.addPreambleSnippet(mathpreamble);
+                                       features.addPreambleSnippet(from_utf8(mathpreamble));
                        }
                }
                // with utf8-plain, we do not load packages (see #7766)
@@ -96,7 +96,7 @@ void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_m
                                                features.require(feat);
                                        }
                                } else
-                                       features.addPreambleSnippet(textpreamble);
+                                       features.addPreambleSnippet(from_utf8(textpreamble));
                        }
                }
        }
index eff684d42edc91e0cb557ea0b445d97803a4abd6..3439095e447da9b2e5de15d3245cf91c90603ea8 100644 (file)
@@ -1082,9 +1082,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
        // then the preamble
        if (!preamble.empty()) {
                // remove '\n' from the end of preamble
-               string const tmppreamble = rtrim(preamble, "\n");
+               docstring const tmppreamble = rtrim(preamble, "\n");
                os << "\\begin_preamble\n"
-                  << tmppreamble
+                  << to_utf8(tmppreamble)
                   << "\n\\end_preamble\n";
        }
 
@@ -1135,20 +1135,20 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
           << convert<string>(maintain_unincluded_children) << '\n';
 
        // local layout information
-       string const local_layout = getLocalLayout(false);
+       docstring const local_layout = getLocalLayout(false);
        if (!local_layout.empty()) {
                // remove '\n' from the end
-               string const tmplocal = rtrim(local_layout, "\n");
+               docstring const tmplocal = rtrim(local_layout, "\n");
                os << "\\begin_local_layout\n"
-                  << tmplocal
+                  << to_utf8(tmplocal)
                   << "\n\\end_local_layout\n";
        }
-       string const forced_local_layout = getLocalLayout(true);
+       docstring const forced_local_layout = getLocalLayout(true);
        if (!forced_local_layout.empty()) {
                // remove '\n' from the end
-               string const tmplocal = rtrim(forced_local_layout, "\n");
+               docstring const tmplocal = rtrim(forced_local_layout, "\n");
                os << "\\begin_forced_local_layout\n"
-                  << tmplocal
+                  << to_utf8(tmplocal)
                   << "\n\\end_forced_local_layout\n";
        }
 
@@ -1931,11 +1931,11 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                || features.isRequired("varioref")
                || features.isRequired("vietnamese")
                || features.isRequired("japanese"))) {
+                       lyxpreamble += features.getBabelPresettings();
                        // FIXME UNICODE
-                       lyxpreamble += from_utf8(features.getBabelPresettings());
                        lyxpreamble += from_utf8(babelCall(language_options.str(),
                                                           features.needBabelLangOptions())) + '\n';
-                       lyxpreamble += from_utf8(features.getBabelPostsettings());
+                       lyxpreamble += features.getBabelPostsettings();
        }
 
        // The optional packages;
@@ -2031,13 +2031,12 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                        "User specified LaTeX commands.\n";
 
                // Check if the user preamble contains uncodable glyphs
-               docstring const u_preamble = from_utf8(preamble);
                odocstringstream user_preamble;
                docstring uncodable_glyphs;
                Encoding const * const enc = features.runparams().encoding;
                if (enc) {
-                       for (size_t n = 0; n < u_preamble.size(); ++n) {
-                               char_type c = u_preamble[n];
+                       for (size_t n = 0; n < preamble.size(); ++n) {
+                               char_type c = preamble[n];
                                if (!enc->encodable(c)) {
                                        docstring const glyph(1, c);
                                        LYXERR0("Uncodable character '"
@@ -2054,7 +2053,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                                        user_preamble.put(c);
                        }
                } else
-                       user_preamble << u_preamble;
+                       user_preamble << preamble;
 
                // On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs
                if (!features.runparams().dryrun && !uncodable_glyphs.empty()) {
@@ -2145,11 +2144,11 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                && !features.isRequired("varioref")
            && !features.isRequired("vietnamese")
            && !features.isRequired("japanese")) {
+               lyxpreamble += features.getBabelPresettings();
                // FIXME UNICODE
-               lyxpreamble += from_utf8(features.getBabelPresettings());
                lyxpreamble += from_utf8(babelCall(language_options.str(),
                                                   features.needBabelLangOptions())) + '\n';
-               lyxpreamble += from_utf8(features.getBabelPostsettings());
+               lyxpreamble += features.getBabelPostsettings();
        }
        if (features.isRequired("bicaption"))
                lyxpreamble += "\\usepackage{bicaption}\n";
@@ -2331,10 +2330,11 @@ void BufferParams::makeDocumentClass(bool const clone)
 
        TextClass::ReturnValues success = TextClass::OK;
        if (!forced_local_layout_.empty())
-               success = doc_class_->read(forced_local_layout_, TextClass::MODULE);
+               success = doc_class_->read(to_utf8(forced_local_layout_),
+                                          TextClass::MODULE);
        if (!local_layout_.empty() &&
            (success == TextClass::OK || success == TextClass::OK_OLDFORMAT))
-               success = doc_class_->read(local_layout_, TextClass::MODULE);
+               success = doc_class_->read(to_utf8(local_layout_), TextClass::MODULE);
        if (success != TextClass::OK && success != TextClass::OK_OLDFORMAT) {
                docstring const msg = _("Error reading internal layout information");
                frontend::Alert::warning(_("Read Error"), msg);
@@ -2354,16 +2354,16 @@ bool BufferParams::citationModuleCanBeAdded(string const & modName) const
 }
 
 
-std::string BufferParams::getLocalLayout(bool forced) const
+docstring BufferParams::getLocalLayout(bool forced) const
 {
        if (forced)
-               return doc_class_->forcedLayouts();
+               return from_utf8(doc_class_->forcedLayouts());
        else
                return local_layout_;
 }
 
 
-void BufferParams::setLocalLayout(string const & layout, bool forced)
+void BufferParams::setLocalLayout(docstring const & layout, bool forced)
 {
        if (forced)
                forced_local_layout_ = layout;
@@ -2576,7 +2576,7 @@ void BufferParams::readPreamble(Lexer & lex)
                lyxerr << "Error (BufferParams::readPreamble):"
                        "consistency check failed." << endl;
 
-       preamble = lex.getLongString("\\end_preamble");
+       preamble = lex.getLongString(from_ascii("\\end_preamble"));
 }
 
 
@@ -2590,9 +2590,9 @@ void BufferParams::readLocalLayout(Lexer & lex, bool forced)
 
        if (forced)
                forced_local_layout_ =
-                       lex.getLongString("\\end_forced_local_layout");
+                       lex.getLongString(from_ascii("\\end_forced_local_layout"));
        else
-               local_layout_ = lex.getLongString("\\end_local_layout");
+               local_layout_ = lex.getLongString(from_ascii("\\end_local_layout"));
 }
 
 
index aecf76b9813f9754a548962e9137a83c484b16b6..4efbe57deaa710d78844fbd399e9629e45d258bd 100644 (file)
@@ -159,9 +159,9 @@ public:
        /// Clear the removed module list
        void clearRemovedModules() { removed_modules_.clear(); }
        /// Get the local layouts
-       std::string getLocalLayout(bool) const;
+       docstring getLocalLayout(bool forced) const;
        /// Set the local layouts
-       void setLocalLayout(std::string const &, bool);
+       void setLocalLayout(docstring const & layout, bool forced);
 
        /// returns \c true if the buffer contains a LaTeX document
        bool isLatex() const;
@@ -321,7 +321,7 @@ public:
        ///
        std::string origin;
        ///
-       std::string preamble;
+       docstring preamble;
        ///
        std::string options;
        /// use the class options defined in the layout?
@@ -541,9 +541,9 @@ private:
        /// the user has chosen not to use
        std::list<std::string> removed_modules_;
        /// The local layouts without the forced ones
-       std::string local_layout_;
+       docstring local_layout_;
        /// Forced local layouts only for reading (use getLocalLayout() instead)
-       std::string forced_local_layout_;
+       docstring forced_local_layout_;
 
        /// the list of included children (for includeonly)
        std::list<std::string> included_children_;
index 8309e79caa1297f47c313b4597f30dc3262e3e62..72b81190a126f71c2bd3d2e3419d9d5bb4ca676b 100644 (file)
@@ -30,7 +30,7 @@ Floating::Floating(string const & type, string const & placement,
                   string const & listName, std::string const & listCmd,
                   string const & refPrefix, std::string const & allowedplacement,
                   string const & htmlTag, string const & htmlAttrib,
-                  string const & htmlStyle, bool usesfloat, bool ispredefined,
+                  docstring const & htmlStyle, bool usesfloat, bool ispredefined,
                   bool allowswide, bool allowssideways)
        : floattype_(type), placement_(placement), ext_(ext), within_(within),
          style_(style), name_(name), listname_(listName), listcommand_(listCmd),
index 8cf5c505a2cb80ef92c68a83542753f86c13dc2f..3de7d450fce8ac88862af073383b7787282dca14 100644 (file)
 #ifndef FLOATING_H
 #define FLOATING_H
 
+#include "support/strfwd.h"
+
 #include <string>
 
 
 namespace lyx {
-       
+
 /** This is a "float layout" object. It contains the parameters for how to
  *  handle the different kinds of floats, default ones and user created ones.
  *  Objects of this class is stored in a container in FloatList. The different
@@ -35,7 +37,7 @@ public:
                 std::string const & listName, std::string const & listCmd,
                 std::string const & refPrefix, std::string const & allowedplacement,
                 std::string const & htmlType, std::string const & htmlClass,
-                std::string const & htmlStyle, bool usesfloat, bool isprefined,
+                docstring const & htmlStyle, bool usesfloat, bool isprefined,
                 bool allowswide, bool allowssideways);
        ///
        std::string const & floattype() const { return floattype_; }
@@ -69,7 +71,7 @@ public:
        ///
        bool allowsSideways() const { return allowssideways_; }
        /// style information, for preamble
-       std::string const & htmlStyle() const { return html_style_; }
+       docstring const & htmlStyle() const { return html_style_; }
        /// class, for css, defaults to "float-" + type()
        std::string const & htmlAttrib() const;
        /// tag type, defaults to "div"
@@ -112,7 +114,7 @@ private:
        ///
        mutable std::string defaultcssclass_;
        /// 
-       std::string html_style_;
+       docstring html_style_;
 };
 
 
index e405b24848e0c7feef33df462103567dbcc07c0b..c33b9121a34121b529ee3f3e53f7d06af04db62b 100644 (file)
@@ -586,8 +586,8 @@ bool LaTeXFeatures::isAvailable(string const & name)
 }
 
 
-void LaTeXFeatures::addPreambleSnippet(string const & preamble,
-               bool allowdupes)
+void LaTeXFeatures::addPreambleSnippet(docstring const & preamble,
+                                       bool allowdupes)
 {
        SnippetList::const_iterator begin = preamble_snippets_.begin();
        SnippetList::const_iterator end   = preamble_snippets_.end();
@@ -598,10 +598,11 @@ void LaTeXFeatures::addPreambleSnippet(string const & preamble,
 
 void LaTeXFeatures::addCSSSnippet(std::string const & snippet)
 {
+       docstring const u_snippet = from_ascii(snippet);
        SnippetList::const_iterator begin = css_snippets_.begin();
        SnippetList::const_iterator end   = css_snippets_.end();
-       if (find(begin, end, snippet) == end)
-               css_snippets_.push_back(snippet);
+       if (find(begin, end, u_snippet) == end)
+               css_snippets_.push_back(u_snippet);
 }
 
 
@@ -1150,9 +1151,9 @@ string const LaTeXFeatures::getPackages() const
 }
 
 
-string LaTeXFeatures::getPreambleSnippets() const
+docstring LaTeXFeatures::getPreambleSnippets() const
 {
-       ostringstream snip;
+       odocstringstream snip;
        SnippetList::const_iterator pit  = preamble_snippets_.begin();
        SnippetList::const_iterator pend = preamble_snippets_.end();
        for (; pit != pend; ++pit)
@@ -1161,9 +1162,9 @@ string LaTeXFeatures::getPreambleSnippets() const
 }
 
 
-std::string LaTeXFeatures::getCSSSnippets() const
+docstring LaTeXFeatures::getCSSSnippets() const
 {
-       ostringstream snip;
+       odocstringstream snip;
        SnippetList::const_iterator pit  = css_snippets_.begin();
        SnippetList::const_iterator pend = css_snippets_.end();
        for (; pit != pend; ++pit)
@@ -1178,7 +1179,7 @@ docstring const LaTeXFeatures::getMacros() const
 
        if (!preamble_snippets_.empty()) {
                macros << '\n';
-               macros << from_utf8(getPreambleSnippets());
+               macros << getPreambleSnippets();
        }
 
        if (mustProvide("papersize")) {
@@ -1346,15 +1347,13 @@ docstring const LaTeXFeatures::getMacros() const
 }
 
 
-string const LaTeXFeatures::getBabelPresettings() const
+docstring const LaTeXFeatures::getBabelPresettings() const
 {
-       ostringstream tmp;
+       odocstringstream tmp;
 
-       LanguageList::const_iterator it  = UsedLanguages_.begin();
-       LanguageList::const_iterator end = UsedLanguages_.end();
-       for (; it != end; ++it)
-               if (!(*it)->babel_presettings().empty())
-                       tmp << (*it)->babel_presettings() << '\n';
+       for (Language const * lang : UsedLanguages_)
+               if (!lang->babel_presettings().empty())
+                       tmp << lang->babel_presettings() << '\n';
        if (!params_.language->babel_presettings().empty())
                tmp << params_.language->babel_presettings() << '\n';
 
@@ -1365,15 +1364,13 @@ string const LaTeXFeatures::getBabelPresettings() const
 }
 
 
-string const LaTeXFeatures::getBabelPostsettings() const
+docstring const LaTeXFeatures::getBabelPostsettings() const
 {
-       ostringstream tmp;
+       odocstringstream tmp;
 
-       LanguageList::const_iterator it  = UsedLanguages_.begin();
-       LanguageList::const_iterator end = UsedLanguages_.end();
-       for (; it != end; ++it)
-               if (!(*it)->babel_postsettings().empty())
-                       tmp << (*it)->babel_postsettings() << '\n';
+       for (Language const * lang : UsedLanguages_)
+               if (!lang->babel_postsettings().empty())
+                       tmp << lang->babel_postsettings() << '\n';
        if (!params_.language->babel_postsettings().empty())
                tmp << params_.language->babel_postsettings() << '\n';
 
index 6b1febf28bbbf1d26fb959005eff0fb582e52680..8216b9b4621ffe508aef1bb6384ae7bff905f80b 100644 (file)
@@ -62,9 +62,9 @@ public:
        /// The macros definitions needed by the document
        docstring const getMacros() const;
        /// Extra preamble code before babel is called
-       std::string const getBabelPresettings() const;
+       docstring const getBabelPresettings() const;
        /// Extra preamble code after babel is called
-       std::string const getBabelPostsettings() const;
+       docstring const getBabelPostsettings() const;
        /// Do we need to pass the languages to babel directly?
        bool needBabelLangOptions() const;
        /// Load AMS packages when appropriate
@@ -88,14 +88,13 @@ public:
        /// Print requirements to lyxerr
        void showStruct() const;
        ///
-       void addPreambleSnippet(std::string const & snippet, 
-                               bool allowdupes = false);
+       void addPreambleSnippet(docstring const & snippet, bool allowdupes = false);
        ///
-       std::string getPreambleSnippets() const;
+       docstring getPreambleSnippets() const;
        ///
        void addCSSSnippet(std::string const &);
        ///
-       std::string getCSSSnippets() const;
+       docstring getCSSSnippets() const;
        /// Add a feature name requirements
        void require(std::string const & name);
        /// Add a set of feature names requirements
@@ -175,7 +174,7 @@ private:
        ///
        Features features_;
        /// Static preamble bits, from external templates, or anywhere else
-       typedef std::list<std::string> SnippetList;
+       typedef std::list<docstring> SnippetList;
        ///
        SnippetList preamble_snippets_;
        ///
index bc4151cb2502cb16c7888b0d0c71dc8db10cb955..862e47451646798447ccf1fd8784f939705373ed 100644 (file)
@@ -304,7 +304,7 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
                os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale);
 
        if (!preamble_.empty())
-               os << preamble_;
+               os << to_utf8(preamble_);
 
        return os.str();
 }
@@ -420,7 +420,7 @@ bool LaTeXFont::readFont(Lexer & lex)
                        lex >> packageoption_;
                        break;
                case LF_PREAMBLE:
-                       preamble_ = lex.getLongString("EndPreamble");
+                       preamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
                case LF_PROVIDES: {
                        lex.eatLine();
index b5ab8c6f33293ded0af0c677d5e550b66b646e76..90d91b35190a54cb7d55324aadb1e0843cb62e33 100644 (file)
@@ -133,7 +133,7 @@ private:
        ///
        docstring requires_;
        ///
-       std::string preamble_;
+       docstring preamble_;
        ///
        bool osfdefault_;
        ///
index dc38bfcf242fb8d50a208a0037a813339faf4ac5..9801668846b998b1377535eff9f77cd01eb4f6ef 100644 (file)
@@ -169,11 +169,11 @@ bool Language::readLanguage(Lexer & lex)
                        break;
                case LA_POSTBABELPREAMBLE:
                        babel_postsettings_ =
-                               lex.getLongString("EndPostBabelPreamble");
+                               lex.getLongString(from_ascii("EndPostBabelPreamble"));
                        break;
                case LA_PREBABELPREAMBLE:
                        babel_presettings_ =
-                               lex.getLongString("EndPreBabelPreamble");
+                               lex.getLongString(from_ascii("EndPreBabelPreamble"));
                        break;
                case LA_REQUIRES:
                        lex >> requires_;
index ed1bd8715efe385cd397d8273fd70b0cb8d91eda..c26a77d568da374fd4df7ab1e658f68583fa6836 100644 (file)
@@ -72,9 +72,9 @@ public:
        /// set variety (needed for rc.spellchecker_alt_lang)
        void setVariety(std::string const & v) { variety_ = v; }
        /// preamble settings after babel was called
-       std::string const babel_postsettings() const { return babel_postsettings_; }
+       docstring babel_postsettings() const { return babel_postsettings_; }
        /// preamble settings before babel is called
-       std::string const babel_presettings() const { return babel_presettings_; }
+       docstring babel_presettings() const { return babel_presettings_; }
        /// This language internally sets a font encoding
        bool internalFontEncoding() const { return internal_enc_; }
        /// fontenc encoding(s)
@@ -119,9 +119,9 @@ private:
        ///
        trivstring variety_;
        ///
-       trivstring babel_postsettings_;
+       trivdocstring babel_postsettings_;
        ///
-       trivstring babel_presettings_;
+       trivdocstring babel_presettings_;
        ///
        trivstring fontenc_;
        ///
index f3af6986157156d6653baf834e263ce8e7ba8673..7893c5fe7e6cd8a3d3cfa35551087fa4b3ed8e4a 100644 (file)
@@ -465,15 +465,15 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
 
                case LT_PREAMBLE:
-                       preamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       preamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case LT_LANGPREAMBLE:
-                       langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
+                       langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
                        break;
 
                case LT_BABELPREAMBLE:
-                       babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
+                       babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
                        break;
 
                case LT_LABELTYPE:
@@ -635,7 +635,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
                        
                case LT_HTMLSTYLE:
-                       htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
+                       htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
                        break;
 
                case LT_HTMLFORCECSS:
@@ -643,7 +643,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
                        break;
 
                case LT_HTMLPREAMBLE:
-                       htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
                
                case LT_HTMLTITLE:
index 25d337a0793287e3ac6ba8e532dc74ca821b076f..78bf9f49c23394c86c265eabbadebd911d349b67 100644 (file)
@@ -718,28 +718,27 @@ docstring const Lexer::getDocString(bool trim) const
 // I would prefer to give a tag number instead of an explicit token
 // here, but it is not possible because Buffer::readDocument uses
 // explicit tokens (JMarc)
-string const Lexer::getLongString(string const & endtoken)
+docstring Lexer::getLongString(docstring const & endtoken)
 {
-       string str;
-       string prefix;
+       docstring str;
+       docstring prefix;
        bool firstline = true;
 
        while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
                if (!eatLine())
                        // blank line in the file being read
                        continue;
+               docstring tmpstr = getDocString();
+               docstring const token = trim(tmpstr, " \t");
 
-               string const token = trim(getString(), " \t");
-
-               LYXERR(Debug::PARSER, "LongString: `" << getString() << '\'');
+               LYXERR(Debug::PARSER, "LongString: `" << tmpstr << '\'');
 
                // We do a case independent comparison, like searchKeyword does.
-               if (compare_ascii_no_case(token, endtoken) == 0)
+               if (compare_no_case(token, endtoken) == 0)
                        break;
 
-               string tmpstr = getString();
                if (firstline) {
-                       size_t i = tmpstr.find_first_not_of(' ');
+                       size_t i = tmpstr.find_first_not_of(char_type(' '));
                        if (i != string::npos)
                                prefix = tmpstr.substr(0, i);
                        firstline = false;
@@ -755,7 +754,7 @@ string const Lexer::getLongString(string const & endtoken)
        }
 
        if (!pimpl_->is)
-               printError("Long string not ended by `" + endtoken + '\'');
+               printError("Long string not ended by `" + to_utf8(endtoken) + '\'');
 
        return str;
 }
index 5e87ebc78b546bfca08c10bb9ae2ce14d05d6769..6335fac8da28fc0dd258ba6726051c996d616002 100644 (file)
@@ -147,7 +147,7 @@ public:
            each following line. This mechanism does not work
            perfectly if you use tabs.
        */
-       std::string const getLongString(std::string const & endtag);
+       docstring getLongString(docstring const & endtag);
 
        /// Pushes a token list on a stack and replaces it with a new one.
        template<int N> void pushTable(LexerKeyword (&table)[N])
index 3bae5bc1da7a3b518955d8433ce5379d81868cbf..8986d38c49836a3d5d05cf7b31f77d97745e92f9 100644 (file)
@@ -1412,8 +1412,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
                                        latexArgInsets(*owner_, os, rp, layout_->postcommandargs(), "post:");
                                }
                        }
-                       string const snippet = to_utf8(ods.str());
-                       features.addPreambleSnippet(snippet, true);
+                       features.addPreambleSnippet(ods.str(), true);
                }
        }
 
index 5b71cb0496c9a3a38c629147f3225a86a79fc37c..2db8ee2344985099199badee8c57591d9865f712 100644 (file)
@@ -614,15 +614,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        break;
 
                case TC_PREAMBLE:
-                       preamble_ = from_utf8(lexrc.getLongString("EndPreamble"));
+                       preamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case TC_HTMLPREAMBLE:
-                       htmlpreamble_ = from_utf8(lexrc.getLongString("EndPreamble"));
+                       htmlpreamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case TC_HTMLSTYLES:
-                       htmlstyles_ = from_utf8(lexrc.getLongString("EndStyles"));
+                       htmlstyles_ = lexrc.getLongString(from_ascii("EndStyles"));
                        break;
 
                case TC_HTMLTOCSECTION:
@@ -630,15 +630,15 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                        break;
 
                case TC_ADDTOPREAMBLE:
-                       preamble_ += from_utf8(lexrc.getLongString("EndPreamble"));
+                       preamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case TC_ADDTOHTMLPREAMBLE:
-                       htmlpreamble_ += from_utf8(lexrc.getLongString("EndPreamble"));
+                       htmlpreamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
                        break;
 
                case TC_ADDTOHTMLSTYLES:
-                       htmlstyles_ += from_utf8(lexrc.getLongString("EndStyles"));
+                       htmlstyles_ += lexrc.getLongString(from_ascii("EndStyles"));
                        break;
 
                case TC_PROVIDES: {
@@ -1155,7 +1155,7 @@ bool TextClass::readFloat(Lexer & lexrc)
 
        string ext;
        string htmlattr;
-       string htmlstyle;
+       docstring htmlstyle;
        string htmltag;
        string listname;
        string listcommand;
@@ -1259,7 +1259,7 @@ bool TextClass::readFloat(Lexer & lexrc)
                        break;
                case FT_HTMLSTYLE:
                        lexrc.next();
-                       htmlstyle = lexrc.getLongString("EndHTMLStyle");
+                       htmlstyle = lexrc.getLongString(from_ascii("EndHTMLStyle"));
                        break;
                case FT_HTMLTAG:
                        lexrc.next();
index e96e9ace434f27c386be8e093b35983949e4e42f..c0e9605118ffe4ee1252c39baeb49935da9c8a1b 100644 (file)
@@ -494,7 +494,7 @@ void PreambleModule::update(BufferParams const & params, BufferId id)
 
 void PreambleModule::apply(BufferParams & params)
 {
-       params.preamble = fromqstr(preambleTE->document()->toPlainText());
+       params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
 }
 
 
@@ -540,7 +540,8 @@ void LocalLayout::update(BufferParams const & params, BufferId id)
 
 void LocalLayout::apply(BufferParams & params)
 {
-       string const layout = fromqstr(locallayoutTE->document()->toPlainText());
+       docstring const layout =
+               qstring_to_ucs4(locallayoutTE->document()->toPlainText());
        params.setLocalLayout(layout, false);
 }
 
index c72a65a8599b266dc360d016b0073e7970e021e9..2e7b6f633c91f3b73d030b3efa6594cbb24ed54e 100644 (file)
@@ -539,7 +539,7 @@ void GuiExternal::updateContents()
 void GuiExternal::updateTemplate()
 {
        external::Template templ = getTemplate(externalCO->currentIndex());
-       externalTB->setPlainText(qt_(templ.helpText));
+       externalTB->setPlainText(toqstr(translateIfPossible(templ.helpText)));
 
        // Ascertain which (if any) transformations the template supports
        // and disable tabs and Group Boxes hosting unsupported transforms.
index db12e68b8cb56c1ed97c283706cc2bc76cfad264..64f31343a67d13817daa093e40e5b6dfbd5c2d5c 100644 (file)
@@ -78,7 +78,7 @@ public:
 
        void operator()(value_type const & vt) {
                os_ << "PreambleDef " << vt.first << '\n'
-                   << vt.second
+                   << to_utf8(vt.second)
                    << "PreambleDefEnd" << endl;
        }
 
@@ -99,7 +99,7 @@ public:
                os_ << "Template " << et.lyxName << '\n'
                    << "\tGuiName " << et.guiName << '\n'
                    << "\tHelpText\n"
-                   << et.helpText
+                   << to_utf8(et.helpText)
                    << "\tHelpTextEnd\n"
                    << "\tInputFormat " << et.inputFormat << '\n'
                    << "\tFileFilter " << et.fileRegExp << '\n'
@@ -228,16 +228,15 @@ TemplateManager::getTemplateByName(string const & name) const
 }
 
 
-string const
-TemplateManager::getPreambleDefByName(string const & name) const
+docstring TemplateManager::getPreambleDefByName(string const & name) const
 {
        string const trimmed_name = trim(name);
        if (trimmed_name.empty())
-               return string();
+               return docstring();
 
        PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
        if (it == preambledefs.end())
-               return string();
+               return docstring();
 
        return it->second;
 }
@@ -278,7 +277,7 @@ void TemplateManager::readTemplates(FileName const & path)
                case TM_PREAMBLEDEF: {
                        lex.next();
                        string const name = lex.getString();
-                       preambledefs[name] = lex.getLongString(preamble_end_tag);
+                       preambledefs[name] = lex.getLongString(from_ascii(preamble_end_tag));
                }
                break;
 
@@ -341,7 +340,7 @@ void Template::readTemplate(Lexer & lex)
                        break;
 
                case TO_HELPTEXT:
-                       helpText = lex.getLongString("HelpTextEnd");
+                       helpText = lex.getLongString(from_ascii("HelpTextEnd"));
                        break;
 
                case TO_INPUTFORMAT:
index d6be5734ab6dc6a18456f213da2d7f3b9c380369..e5b6755059700b009b756ea12edea6b70cc19a47 100644 (file)
@@ -53,7 +53,7 @@ public:
        /// What will the button in the GUI say?
        std::string guiName;
        /// A short help text
-       std::string helpText;
+       docstring helpText;
        /** The format of the input file. Can be "*", in which case we try and
         *   ascertain the format from the contents of the file.
         */
@@ -112,7 +112,7 @@ public:
        /** Map from the LyX name of the preamble definition to the preamble
         *  definition itself.
         */
-       typedef std::map<std::string, std::string> PreambleDefs;
+       typedef std::map<std::string, docstring> PreambleDefs;
 
        static TemplateManager & get();
 
@@ -124,7 +124,7 @@ public:
        /** return the preamble definition by LyX name.
         *  If it isn't found, return an empty std::string.
         */
-       std::string const getPreambleDefByName(std::string const & name) const;
+       docstring getPreambleDefByName(std::string const & name) const;
        /// noncopyable
        TemplateManager(TemplateManager const &) = delete;
        void operator=(TemplateManager const &) = delete;
index e208137940f6dce2cfe61bd40d4622276720fa24..b68a09d77fc10e1663b7f645eb1ed6dabac70018 100644 (file)
@@ -828,10 +828,8 @@ void InsetExternal::validate(LaTeXFeatures & features) const
 
        external::TemplateManager & etm = external::TemplateManager::get();
 
-       it  = cit->second.preambleNames.begin();
-       end = cit->second.preambleNames.end();
-       for (; it != end; ++it) {
-               string const preamble = etm.getPreambleDefByName(*it);
+       for (string const & name : cit->second.preambleNames) {
+               docstring const preamble = etm.getPreambleDefByName(name);
                if (!preamble.empty())
                        features.addPreambleSnippet(preamble);
        }
index 088e4bc6e36292158c23b85ebf7faeb5e96777b1..3c4fc9bb9fce398d57e79d37a0312f0f67987098 100644 (file)
@@ -407,13 +407,13 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                        bgcolor_ = lcolor.getFromLyXName(tmp);
                        break;
                case IL_PREAMBLE:
-                       preamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       preamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
                case IL_BABELPREAMBLE:
-                       babelpreamble_ = from_utf8(lex.getLongString("EndBabelPreamble"));
+                       babelpreamble_ = lex.getLongString(from_ascii("EndBabelPreamble"));
                        break;
                case IL_LANGPREAMBLE:
-                       langpreamble_ = from_utf8(lex.getLongString("EndLangPreamble"));
+                       langpreamble_ = lex.getLongString(from_ascii("EndLangPreamble"));
                        break;
                case IL_REFPREFIX:
                        lex >> refprefix_;
@@ -440,10 +440,10 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                        lex >> htmlisblock_;
                        break;
                case IL_HTMLSTYLE:
-                       htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
+                       htmlstyle_ = lex.getLongString(from_ascii("EndHTMLStyle"));
                        break;
                case IL_HTMLPREAMBLE:
-                       htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
+                       htmlpreamble_ = lex.getLongString(from_ascii("EndPreamble"));
                        break;
                case IL_REQUIRES: {
                        lex.eatLine();
index 146a85dd492ed2740eda08852e9b2577d3b75547..8cb8c58027f22d8877a8040fcf1d7b98f912f4ba 100644 (file)
@@ -323,14 +323,14 @@ void InsetRef::validate(LaTeXFeatures & features) const
                docstring const data = getEscapedLabel(features.runparams());
                docstring label;
                docstring prefix;
-               string const fcmd = to_utf8(getFormattedCmd(data, label, prefix));
+               docstring const fcmd = getFormattedCmd(data, label, prefix);
                if (buffer().params().use_refstyle) {
                        features.require("refstyle");
                        if (prefix == "cha")
-                               features.addPreambleSnippet("\\let\\charef=\\chapref");
+                               features.addPreambleSnippet(from_ascii("\\let\\charef=\\chapref"));
                        else if (!prefix.empty()) {
-                               string lcmd = "\\AtBeginDocument{\\providecommand" + 
-                                               fcmd + "[1]{\\ref{" + to_utf8(prefix) + ":#1}}}";
+                               docstring lcmd = "\\AtBeginDocument{\\providecommand" +
+                                               fcmd + "[1]{\\ref{" + prefix + ":#1}}}";
                                features.addPreambleSnippet(lcmd);
                        }
                } else {
@@ -338,7 +338,7 @@ void InsetRef::validate(LaTeXFeatures & features) const
                        // prettyref uses "cha" for chapters, so we provide a kind of
                        // translation.
                        if (prefix == "chap")
-                               features.addPreambleSnippet("\\let\\pr@chap=\\pr@cha");
+                               features.addPreambleSnippet(from_ascii("\\let\\pr@chap=\\pr@cha"));
                }
        } else if (cmd == "eqref" && !buffer().params().use_refstyle)
                // with refstyle, we simply output "(\ref{label})"
index 89fe4bb9d7c7dd7e6e44acb361019538363f0c62..76b3613ec1c9e78817c484b25157a19574c343b4 100644 (file)
@@ -955,14 +955,14 @@ void InsetMathHull::validate(LaTeXFeatures & features) const
 
                if (type_ == hullRegexp) {
                        features.require("color");
-                       string frcol = lcolor.getLaTeXName(Color_regexpframe);
-                       string bgcol = "white";
+                       docstring frcol = from_utf8(lcolor.getLaTeXName(Color_regexpframe));
+                       docstring bgcol = from_ascii("white");
                        features.addPreambleSnippet(
-                               string("\\newcommand{\\regexp}[1]{\\fcolorbox{")
-                               + frcol + string("}{")
-                               + bgcol + string("}{\\ensuremath{\\mathtt{#1}}}}"));
+                               "\\newcommand{\\regexp}[1]{\\fcolorbox{"
+                               + frcol + "}{"
+                               + bgcol + "}{\\ensuremath{\\mathtt{#1}}}}");
                        features.addPreambleSnippet(
-                               string("\\newcommand{\\endregexp}{}"));
+                               from_ascii("\\newcommand{\\endregexp}{}"));
                }
 
                // Validation is necessary only if not using AMS math.
index 2c3203b5c72f441baf5e5d96de303715708b2b1c..9eb9e43d5fbe975367e8b527f313db11f4fdee7e 100644 (file)
@@ -717,6 +717,12 @@ bool containsOnly(string const & s, string const & cset)
 }
 
 
+bool containsOnly(docstring const & s, string const & cset)
+{
+       return s.find_first_not_of(from_ascii(cset)) == string::npos;
+}
+
+
 // ale970405+lasgoutt-970425
 // rewritten to use new string (Lgb)
 string const token(string const & a, char delim, int n)
index ac310c59c43dcc598e6a6016c447e91a0bc274d2..fa61414d1c64882c9a5661afad1c33b49bf7ae29 100644 (file)
@@ -151,8 +151,11 @@ inline bool contains(docstring const & a, char_type b)
        return a.find(b) != docstring::npos;
 }
 
-///
+/// Returns true if the first argument is made of ascii chars given in the
+/// second argument.
 bool containsOnly(std::string const &, std::string const &);
+///
+bool containsOnly(docstring const &, std::string const &);
 
 /** Extracts a token from this string at the nth delim.
     Doesn't modify the original string. Similar to strtok.