commit 1f945177b9628b213c60872df88f2d155c3d6c54
Author: Guillaume Munch <[email protected]>
Date: Sun Sep 25 12:37:40 2016 +0200
Docstringify getLongString in general and preamble snippets in particular
Prepare ground for TexRow InPreamble
---
src/Buffer.cpp | 10 ++++----
src/BufferEncodings.cpp | 4 +-
src/BufferParams.cpp | 48 ++++++++++++++++++------------------
src/BufferParams.h | 10 ++++----
src/Floating.cpp | 2 +-
src/Floating.h | 10 ++++---
src/LaTeXFeatures.cpp | 43 +++++++++++++++-----------------
src/LaTeXFeatures.h | 13 ++++-----
src/LaTeXFonts.cpp | 4 +-
src/LaTeXFonts.h | 2 +-
src/Language.cpp | 4 +-
src/Language.h | 8 +++---
src/Layout.cpp | 10 ++++----
src/Lexer.cpp | 19 +++++++-------
src/Lexer.h | 2 +-
src/Paragraph.cpp | 3 +-
src/TextClass.cpp | 16 ++++++------
src/frontends/qt4/GuiDocument.cpp | 5 ++-
src/frontends/qt4/GuiExternal.cpp | 2 +-
src/insets/ExternalTemplate.cpp | 15 +++++------
src/insets/ExternalTemplate.h | 6 ++--
src/insets/InsetExternal.cpp | 6 +---
src/insets/InsetLayout.cpp | 10 ++++----
src/insets/InsetRef.cpp | 10 ++++----
src/mathed/InsetMathHull.cpp | 12 ++++----
src/support/lstrings.cpp | 6 ++++
src/support/lstrings.h | 5 +++-
27 files changed, 144 insertions(+), 141 deletions(-)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 8f04ae4..196d23d 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -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';
diff --git a/src/BufferEncodings.cpp b/src/BufferEncodings.cpp
index 87000ac..2cd07f2 100644
--- a/src/BufferEncodings.cpp
+++ b/src/BufferEncodings.cpp
@@ -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));
}
}
}
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index eff684d..3439095 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -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"));
}
diff --git a/src/BufferParams.h b/src/BufferParams.h
index aecf76b..4efbe57 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -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_;
diff --git a/src/Floating.cpp b/src/Floating.cpp
index 8309e79..72b8119 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -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),
diff --git a/src/Floating.h b/src/Floating.h
index 8cf5c50..3de7d45 100644
--- a/src/Floating.h
+++ b/src/Floating.h
@@ -12,11 +12,13 @@
#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_;
};
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index e405b24..c33b912 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -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';
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 6b1febf..8216b9b 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -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_;
///
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index bc4151c..862e474 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -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();
diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h
index b5ab8c6..90d91b3 100644
--- a/src/LaTeXFonts.h
+++ b/src/LaTeXFonts.h
@@ -133,7 +133,7 @@ private:
///
docstring requires_;
///
- std::string preamble_;
+ docstring preamble_;
///
bool osfdefault_;
///
diff --git a/src/Language.cpp b/src/Language.cpp
index dc38bfc..9801668 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -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_;
diff --git a/src/Language.h b/src/Language.h
index ed1bd87..c26a77d 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -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_;
///
diff --git a/src/Layout.cpp b/src/Layout.cpp
index f3af698..7893c5f 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -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:
diff --git a/src/Lexer.cpp b/src/Lexer.cpp
index 25d337a..78bf9f4 100644
--- a/src/Lexer.cpp
+++ b/src/Lexer.cpp
@@ -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;
}
diff --git a/src/Lexer.h b/src/Lexer.h
index 5e87ebc..6335fac 100644
--- a/src/Lexer.h
+++ b/src/Lexer.h
@@ -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])
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 3bae5bc..8986d38 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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);
}
}
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 5b71cb0..2db8ee2 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -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();
diff --git a/src/frontends/qt4/GuiDocument.cpp
b/src/frontends/qt4/GuiDocument.cpp
index e96e9ac..c0e9605 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -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);
}
diff --git a/src/frontends/qt4/GuiExternal.cpp
b/src/frontends/qt4/GuiExternal.cpp
index c72a65a..2e7b6f6 100644
--- a/src/frontends/qt4/GuiExternal.cpp
+++ b/src/frontends/qt4/GuiExternal.cpp
@@ -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.
diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp
index db12e68..64f3134 100644
--- a/src/insets/ExternalTemplate.cpp
+++ b/src/insets/ExternalTemplate.cpp
@@ -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:
diff --git a/src/insets/ExternalTemplate.h b/src/insets/ExternalTemplate.h
index d6be573..e5b6755 100644
--- a/src/insets/ExternalTemplate.h
+++ b/src/insets/ExternalTemplate.h
@@ -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;
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index e208137..b68a09d 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -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);
}
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 088e4bc..3c4fc9b 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -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();
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 146a85d..8cb8c58 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -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})"
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 89fe4bb..76b3613 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -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.
diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 2c3203b..9eb9e43 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -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)
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index ac310c5..fa61414 100644
--- a/src/support/lstrings.h
+++ b/src/support/lstrings.h
@@ -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.