From de6418f37765fe452f135f96dee6d49897bff215 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sun, 22 Oct 2006 10:15:23 +0000 Subject: [PATCH] use more unicode in math git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15462 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/cmake/config.h.cmake | 2 +- development/cmake/modules/FindZLIB.cmake | 1 + src/CutAndPaste.C | 16 +- src/CutAndPaste.h | 4 +- src/buffer.C | 6 +- src/buffer.h | 9 +- src/buffer_funcs.C | 12 +- src/bufferparams.C | 10 +- src/coordcache.C | 2 +- src/cursor.C | 43 ++- src/cursor.h | 8 +- src/encoding.C | 30 +- src/encoding.h | 43 +-- src/factory.C | 2 +- src/frontends/controllers/biblio.C | 2 +- src/insets/inset.h | 6 +- src/insets/insetbase.C | 4 +- src/insets/insetbase.h | 6 +- src/insets/insetbox.C | 2 +- src/insets/insetbranch.C | 2 +- src/insets/insetcaption.C | 8 +- src/insets/insetcharstyle.C | 2 +- src/insets/insetcollapsable.C | 2 +- src/insets/insetenv.C | 7 +- src/insets/insetert.C | 2 +- src/insets/insetfloat.C | 2 +- src/insets/insetfoot.C | 4 +- src/insets/insetfootlike.C | 2 +- src/insets/insetmarginal.C | 4 +- src/insets/insetnote.C | 2 +- src/insets/insetquotes.C | 8 +- src/insets/insetwrap.C | 2 +- src/lyxfind.C | 2 +- src/lyxfunc.C | 5 +- src/mathed/InsetFormulaMacro.h | 10 +- src/mathed/InsetMath.C | 15 +- src/mathed/InsetMath.h | 14 +- src/mathed/InsetMathAMSArray.C | 19 +- src/mathed/InsetMathAMSArray.h | 8 +- src/mathed/InsetMathArray.C | 25 +- src/mathed/InsetMathArray.h | 14 +- src/mathed/InsetMathBig.C | 20 +- src/mathed/InsetMathBig.h | 12 +- src/mathed/InsetMathBinom.C | 6 +- src/mathed/InsetMathBoldSymbol.C | 4 +- src/mathed/InsetMathBoldSymbol.h | 2 +- src/mathed/InsetMathBox.C | 6 +- src/mathed/InsetMathBox.h | 6 +- src/mathed/InsetMathBoxed.C | 4 +- src/mathed/InsetMathBoxed.h | 2 +- src/mathed/InsetMathBrace.C | 6 +- src/mathed/InsetMathBrace.h | 4 +- src/mathed/InsetMathCases.C | 10 +- src/mathed/InsetMathCases.h | 2 +- src/mathed/InsetMathChar.C | 22 +- src/mathed/InsetMathChar.h | 8 +- src/mathed/InsetMathColor.C | 33 +- src/mathed/InsetMathColor.h | 6 +- src/mathed/InsetMathCommand.C | 14 +- src/mathed/InsetMathCommand.h | 8 +- src/mathed/InsetMathComment.C | 10 +- src/mathed/InsetMathComment.h | 6 +- src/mathed/InsetMathDFrac.C | 8 +- src/mathed/InsetMathDFrac.h | 4 +- src/mathed/InsetMathDecoration.C | 4 +- src/mathed/InsetMathDecoration.h | 2 +- src/mathed/InsetMathDelim.C | 39 +- src/mathed/InsetMathDelim.h | 10 +- src/mathed/InsetMathDiff.C | 4 +- src/mathed/InsetMathDiff.h | 2 +- src/mathed/InsetMathDots.C | 4 +- src/mathed/InsetMathDots.h | 2 +- src/mathed/InsetMathEnv.C | 6 +- src/mathed/InsetMathEnv.h | 6 +- src/mathed/InsetMathExFunc.C | 28 +- src/mathed/InsetMathExFunc.h | 10 +- src/mathed/InsetMathExInt.C | 8 +- src/mathed/InsetMathExInt.h | 12 +- src/mathed/InsetMathFBox.C | 4 +- src/mathed/InsetMathFBox.h | 2 +- src/mathed/InsetMathFont.C | 9 +- src/mathed/InsetMathFont.h | 4 +- src/mathed/InsetMathFontOld.C | 4 +- src/mathed/InsetMathFontOld.h | 2 +- src/mathed/InsetMathFrac.C | 16 +- src/mathed/InsetMathFrac.h | 4 +- src/mathed/InsetMathFrameBox.C | 2 +- src/mathed/InsetMathGrid.C | 49 ++- src/mathed/InsetMathGrid.h | 18 +- src/mathed/InsetMathHull.C | 153 ++++---- src/mathed/InsetMathHull.h | 20 +- src/mathed/InsetMathKern.C | 10 +- src/mathed/InsetMathKern.h | 2 +- src/mathed/InsetMathLefteqn.C | 6 +- src/mathed/InsetMathLefteqn.h | 4 +- src/mathed/InsetMathLim.C | 4 +- src/mathed/InsetMathLim.h | 2 +- src/mathed/InsetMathMacro.C | 37 +- src/mathed/InsetMathMacro.h | 12 +- src/mathed/InsetMathMakebox.C | 8 +- src/mathed/InsetMathMakebox.h | 2 +- src/mathed/InsetMathMatrix.C | 4 +- src/mathed/InsetMathMatrix.h | 4 +- src/mathed/InsetMathNest.C | 128 +++---- src/mathed/InsetMathNest.h | 10 +- src/mathed/InsetMathNumber.C | 13 +- src/mathed/InsetMathNumber.h | 8 +- src/mathed/InsetMathOverset.C | 2 +- src/mathed/InsetMathPar.C | 4 +- src/mathed/InsetMathPar.h | 2 +- src/mathed/InsetMathPhantom.C | 4 +- src/mathed/InsetMathPhantom.h | 2 +- src/mathed/InsetMathRef.C | 42 +-- src/mathed/InsetMathRef.h | 14 +- src/mathed/InsetMathRoot.C | 4 +- src/mathed/InsetMathRoot.h | 2 +- src/mathed/InsetMathScript.C | 12 +- src/mathed/InsetMathScript.h | 6 +- src/mathed/InsetMathSize.C | 4 +- src/mathed/InsetMathSize.h | 2 +- src/mathed/InsetMathSpace.C | 4 +- src/mathed/InsetMathSpace.h | 2 +- src/mathed/InsetMathSplit.C | 13 +- src/mathed/InsetMathSplit.h | 10 +- src/mathed/InsetMathSqrt.C | 4 +- src/mathed/InsetMathSqrt.h | 2 +- src/mathed/InsetMathStackrel.C | 2 +- src/mathed/InsetMathString.C | 20 +- src/mathed/InsetMathString.h | 11 +- src/mathed/InsetMathSubstack.C | 4 +- src/mathed/InsetMathSubstack.h | 2 +- src/mathed/InsetMathSymbol.C | 21 +- src/mathed/InsetMathSymbol.h | 10 +- src/mathed/InsetMathTFrac.C | 8 +- src/mathed/InsetMathTFrac.h | 4 +- src/mathed/InsetMathTabular.C | 16 +- src/mathed/InsetMathTabular.h | 15 +- src/mathed/InsetMathUnderset.C | 2 +- src/mathed/InsetMathUnknown.C | 19 +- src/mathed/InsetMathUnknown.h | 10 +- src/mathed/InsetMathXArrow.C | 4 +- src/mathed/InsetMathXArrow.h | 4 +- src/mathed/InsetMathXYMatrix.C | 4 +- src/mathed/InsetMathXYMatrix.h | 2 +- src/mathed/MathAutoCorrect.C | 26 +- src/mathed/MathData.C | 2 +- src/mathed/MathData.h | 1 - src/mathed/MathExtern.C | 178 ++++----- src/mathed/MathExtern.h | 11 +- src/mathed/MathFactory.C | 82 ++--- src/mathed/MathFactory.h | 7 +- src/mathed/MathGridInfo.h | 6 +- src/mathed/MathMLStream.C | 385 -------------------- src/mathed/MathMLStream.h | 298 ---------------- src/mathed/MathMacroArgument.C | 11 +- src/mathed/MathMacroArgument.h | 2 +- src/mathed/MathMacroTable.C | 20 +- src/mathed/MathMacroTable.h | 22 +- src/mathed/MathMacroTemplate.C | 17 +- src/mathed/MathMacroTemplate.h | 10 +- src/mathed/MathParser.C | 124 +++---- src/mathed/MathParser.h | 23 +- src/mathed/MathStream.C | 436 +++++++++++++++++++++-- src/mathed/MathStream.h | 310 +++++++++++++++- src/mathed/MathSupport.C | 65 ++-- src/mathed/MathSupport.h | 15 +- src/metricsinfo.C | 12 + src/metricsinfo.h | 7 +- src/paragraph.C | 6 +- src/paragraph.h | 2 +- src/rowpainter.C | 4 +- src/sgml.h | 4 +- src/support/docstring.h | 2 +- src/support/lstrings.C | 15 +- src/support/lstrings.h | 20 +- src/text.C | 6 +- src/text3.C | 2 +- src/undo.C | 2 +- 178 files changed, 1818 insertions(+), 1856 deletions(-) delete mode 100644 src/mathed/MathMLStream.C delete mode 100644 src/mathed/MathMLStream.h diff --git a/development/cmake/config.h.cmake b/development/cmake/config.h.cmake index d45c48d29c..515d1ae677 100644 --- a/development/cmake/config.h.cmake +++ b/development/cmake/config.h.cmake @@ -164,6 +164,6 @@ #endif - +#include "../trunk/stdafx.h" #endif diff --git a/development/cmake/modules/FindZLIB.cmake b/development/cmake/modules/FindZLIB.cmake index 9534d5ec95..61d85c18d2 100644 --- a/development/cmake/modules/FindZLIB.cmake +++ b/development/cmake/modules/FindZLIB.cmake @@ -14,6 +14,7 @@ FIND_PATH(ZLIB_INCLUDE_DIR zlib.h set(POTENTIAL_Z_LIBS z zlib zdll) FIND_LIBRARY(ZLIB_LIBRARY NAMES ${POTENTIAL_Z_LIBS} PATHS + "C:\\Programme\\Microsoft Visual Studio 8\\VC\\lib" /usr/lib /usr/local/lib ) diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index ca094a33e0..1423323e00 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -379,11 +379,11 @@ void copySelectionHelper(Buffer const & buf, ParagraphList & pars, namespace cap { -string grabAndEraseSelection(LCursor & cur) +docstring grabAndEraseSelection(LCursor & cur) { if (!cur.selection()) - return string(); - string res = grabSelection(cur); + return docstring(); + docstring res = grabSelection(cur); eraseSelection(cur); return res; } @@ -748,10 +748,10 @@ void selClearOrDel(LCursor & cur) } -string grabSelection(LCursor const & cur) +docstring grabSelection(LCursor const & cur) { if (!cur.selection()) - return string(); + return docstring(); // FIXME: What is wrong with the following? #if 0 @@ -770,7 +770,7 @@ string grabSelection(LCursor const & cur) MathArray::const_iterator it = i1.cell().begin(); return asString(MathArray(it + i1.pos(), it + i2.pos())); } else { - return "unknown selection 1"; + return from_ascii("unknown selection 1"); } } @@ -778,7 +778,7 @@ string grabSelection(LCursor const & cur) InsetBase::col_type c1, c2; region(i1, i2, r1, r2, c1, c2); - string data; + docstring data; if (i1.inset().asInsetMath()) { for (InsetBase::row_type row = r1; row <= r2; ++row) { if (row > r1) @@ -791,7 +791,7 @@ string grabSelection(LCursor const & cur) } } } else { - data = "unknown selection 2"; + data = from_ascii("unknown selection 2"); } return data; } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index a713bc30af..6b6e6bb189 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -69,11 +69,11 @@ void switchBetweenClasses(textclass_type c1, textclass_type c2, InsetText & in, ErrorList &); /// -std::string grabSelection(LCursor const & cur); +docstring grabSelection(LCursor const & cur); /// void eraseSelection(LCursor & cur); /// -std::string grabAndEraseSelection(LCursor & cur); +docstring grabAndEraseSelection(LCursor & cur); // other selection methods /// void selCut(LCursor & cur); diff --git a/src/buffer.C b/src/buffer.C index 2206d32966..6de77efc09 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1511,19 +1511,19 @@ Buffer * Buffer::getMasterBuffer() } -MacroData const & Buffer::getMacro(std::string const & name) const +MacroData const & Buffer::getMacro(docstring const & name) const { return pimpl_->macros.get(name); } -bool Buffer::hasMacro(string const & name) const +bool Buffer::hasMacro(docstring const & name) const { return pimpl_->macros.has(name); } -void Buffer::insertMacro(string const & name, MacroData const & data) +void Buffer::insertMacro(docstring const & name, MacroData const & data) { MacroTable::globalMacros().insert(name, data); pimpl_->macros.insert(name, data); diff --git a/src/buffer.h b/src/buffer.h index 09745b4121..b29d61e083 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -207,7 +207,7 @@ public: */ std::string const getLatexName(bool no_path = true) const; - /// Get the name and type of the log. + /// Get thee name and type of the log. std::pair const getLogName() const; /// Change name of buffer. Updates "read-only" flag. @@ -328,11 +328,12 @@ public: /// void buildMacros(); /// - bool hasMacro(std::string const & name) const; + bool hasMacro(docstring const & name) const; /// - MacroData const & getMacro(std::string const & name) const; + MacroData const & getMacro(docstring const & name) const; /// - void insertMacro(std::string const & name, MacroData const & data); + void insertMacro(docstring const & name, MacroData const & data); + /// void saveCursor(StableDocIterator cursor, StableDocIterator anchor); /// diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 6e2d056f85..aea3e0b20c 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -469,11 +469,11 @@ void setLabel(Buffer const & buf, ParIterator & it) if (par.bibitem()) par.bibitem()->setCounter(number); // FIXME UNICODE - par.params().labelString(buf.B_(lyx::to_ascii(layout->labelstring()))); + par.params().labelString(buf.B_(to_ascii(layout->labelstring()))); // In biblio should't be following counters but... } else if (layout->labeltype == LABEL_SENSITIVE) { // Search for the first float or wrap inset in the iterator - string type; + docstring type; size_t i = it.depth(); while (i > 0) { --i; @@ -487,7 +487,7 @@ void setLabel(Buffer const & buf, ParIterator & it) docstring s; if (!type.empty()) { - Floating const & fl = textclass.floats().getType(type); + Floating const & fl = textclass.floats().getType(to_ascii(type)); // FIXME UNICODE counters.step(from_ascii(fl.type())); @@ -496,7 +496,7 @@ void setLabel(Buffer const & buf, ParIterator & it) } else { // par->SetLayout(0); // FIXME UNICODE - s = buf.B_(lyx::to_ascii(layout->labelstring())); + s = buf.B_(to_ascii(layout->labelstring())); } par.params().labelString(s); @@ -504,7 +504,7 @@ void setLabel(Buffer const & buf, ParIterator & it) par.params().labelString(docstring()); else // FIXME UNICODE - par.params().labelString(buf.B_(lyx::to_ascii(layout->labelstring()))); + par.params().labelString(buf.B_(to_ascii(layout->labelstring()))); } } // anon namespace @@ -597,7 +597,7 @@ docstring expandLabel(Buffer const & buf, LyXTextClass const & tclass = buf.params().getLyXTextClass(); // FIXME UNICODE - docstring fmt = buf.B_(lyx::to_ascii(appendix ? layout->labelstring_appendix() + docstring fmt = buf.B_(to_ascii(appendix ? layout->labelstring_appendix() : layout->labelstring())); // handle 'inherited level parts' in 'fmt', diff --git a/src/bufferparams.C b/src/bufferparams.C index 973ef55f98..420df763da 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -727,10 +727,10 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, } // custom, A3, B3 and B4 paper sizes need geometry - bool nonstandard_papersize = (papersize == PAPER_B3) || - (papersize == PAPER_B4) || - (papersize == PAPER_A3) || - (papersize == PAPER_CUSTOM); + bool nonstandard_papersize = papersize == PAPER_B3 + || papersize == PAPER_B4 + || papersize == PAPER_A3 + || papersize == PAPER_CUSTOM; if (!use_geometry) { switch (papersize) { @@ -993,7 +993,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, break; case VSpace::LENGTH: os << "\\setlength\\parskip{" - << from_ascii(getDefSkip().length().asLatexString()) + << from_utf8(getDefSkip().length().asLatexString()) << "}\n"; break; default: // should never happen // Then delete it. diff --git a/src/coordcache.C b/src/coordcache.C index cd652063d5..0f7575cc9e 100644 --- a/src/coordcache.C +++ b/src/coordcache.C @@ -81,7 +81,7 @@ CoordCache::dump() const { for (CoordCacheBase::cache_type::const_iterator i = getInsets().getData().begin(); i != getInsets().getData().end(); ++i) { InsetBase const * inset = (*i).first; Point p = (*i).second; - lyxerr << "Inset " << inset << "(" << inset->getInsetName() << ") has point " << p.x_ << "," << p.y_ << std::endl; + lyxerr << "Inset " << inset << "(" << to_utf8(inset->getInsetName()) << ") has point " << p.x_ << "," << p.y_ << std::endl; } } diff --git a/src/cursor.C b/src/cursor.C index a6a357201f..69095b37ee 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -514,7 +514,7 @@ void LCursor::clearTargetX() -void LCursor::info(std::ostream & os) const +void LCursor::info(odocstream & os) const { for (int i = 1, n = depth(); i < n; ++i) { operator[](i).inset().infoize(os); @@ -569,13 +569,13 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur) /////////////////////////////////////////////////////////////////// #include "mathed/InsetMathChar.h" -#include "mathed/MathFactory.h" #include "mathed/InsetMathGrid.h" -#include "mathed/MathMacroArgument.h" -#include "mathed/MathMLStream.h" #include "mathed/InsetMathScript.h" -#include "mathed/MathSupport.h" #include "mathed/InsetMathUnknown.h" +#include "mathed/MathFactory.h" +#include "mathed/MathMacroArgument.h" +#include "mathed/MathStream.h" +#include "mathed/MathSupport.h" namespace lyx { @@ -657,7 +657,7 @@ void LCursor::plainInsert(MathAtom const & t) } -void LCursor::insert(string const & str) +void LCursor::insert(docstring const & str) { for_each(str.begin(), str.end(), boost::bind(static_cast @@ -696,11 +696,10 @@ void LCursor::insert(InsetBase * inset) } -void LCursor::niceInsert(string const & t) +void LCursor::niceInsert(docstring const & t) { MathArray ar; - // FIXME UNICODE - asArray(from_utf8(t), ar); + asArray(t, ar); if (ar.size() == 1) niceInsert(ar[0]); else @@ -711,7 +710,7 @@ void LCursor::niceInsert(string const & t) void LCursor::niceInsert(MathAtom const & t) { macroModeClose(); - string const safe = cap::grabAndEraseSelection(*this); + docstring const safe = cap::grabAndEraseSelection(*this); plainInsert(t); // enter the new inset and move the contents of the selection if possible if (t->isActive()) { @@ -721,8 +720,7 @@ void LCursor::niceInsert(MathAtom const & t) pushLeft(*nextInset()); // We may not use niceInsert here (recursion) MathArray ar; - // FIXME UNICODE - asArray(from_utf8(safe), ar); + asArray(safe, ar); insert(ar); } } @@ -847,7 +845,7 @@ bool LCursor::macroModeClose() return false; InsetMathUnknown * p = activeMacro(); p->finalize(); - string const s = p->name(); + docstring const s = p->name(); --pos(); cell().erase(pos()); @@ -858,7 +856,7 @@ bool LCursor::macroModeClose() // prevent entering of recursive macros // FIXME: this is only a weak attempt... only prevents immediate // recursion - string const name = s.substr(1); + docstring const name = s.substr(1); InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE); if (macro && macro->getInsetName() == name) lyxerr << "can't enter recursive macro" << endl; @@ -871,9 +869,9 @@ bool LCursor::macroModeClose() } -string LCursor::macroName() +docstring LCursor::macroName() { - return inMacroMode() ? activeMacro()->name() : string(); + return inMacroMode() ? activeMacro()->name() : docstring(); } @@ -881,8 +879,7 @@ void LCursor::handleNest(MathAtom const & a, int c) { //lyxerr << "LCursor::handleNest: " << c << endl; MathAtom t = a; - // FIXME UNICODE - asArray(from_utf8(cap::grabAndEraseSelection(*this)), t.nucleus()->cell(c)); + asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c)); insert(t); posLeft(); pushLeft(*nextInset()); @@ -1077,7 +1074,7 @@ bool LCursor::goUpDown(bool up) void LCursor::handleFont(string const & font) { lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl; - string safe; + docstring safe; if (selection()) { macroModeClose(); safe = cap::grabAndEraseSelection(*this); @@ -1094,7 +1091,7 @@ void LCursor::handleFont(string const & font) } else { // cursor in between. split cell MathArray::iterator bt = cell().begin(); - MathAtom at = createInsetMath(font); + MathAtom at = createInsetMath(from_utf8(font)); at.nucleus()->cell(0) = MathArray(bt, bt + pos()); cell().erase(bt, bt + pos()); popLeft(); @@ -1156,7 +1153,7 @@ docstring LCursor::selectionAsString(bool label) const } if (inMathed()) - return from_utf8(cap::grabSelection(*this)); + return cap::grabSelection(*this); return docstring(); } @@ -1165,9 +1162,9 @@ docstring LCursor::selectionAsString(bool label) const string LCursor::currentState() { if (inMathed()) { - std::ostringstream os; + odocstringstream os; info(os); - return os.str(); + return to_utf8(os.str()); } if (inTexted()) diff --git a/src/cursor.h b/src/cursor.h index e3b019c600..1f22fc07d9 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -116,7 +116,7 @@ public: /// insert a single char void insert(char_type c); /// insert a string - void insert(std::string const & str); + void insert(docstring const & str); /// in pixels from left of screen int targetX() const; @@ -138,7 +138,7 @@ public: /// access to owning Buffer Buffer & buffer() const; /// get some interesting description of top position - void info(std::ostream & os) const; + void info(odocstream & os) const; /// are we in math mode (2), text mode (1) or unsure (0)? int currentMode(); /// reset cursor bottom to the beginning of the given inset @@ -251,7 +251,7 @@ public: /// void niceInsert(MathAtom const & at); /// - void niceInsert(std::string const & str); + void niceInsert(docstring const & str); /// in pixels from top of screen void setScreenPos(int x, int y); @@ -295,7 +295,7 @@ public: bool goUpDown(bool up); /// the name of the macro we are currently inputting - std::string macroName(); + docstring macroName(); /// where in the curent cell does the macro name start? int macroNamePos(); /// can we enter the inset? diff --git a/src/encoding.C b/src/encoding.C index 9ff1b3cfee..9c8f15c67d 100644 --- a/src/encoding.C +++ b/src/encoding.C @@ -33,7 +33,7 @@ Encodings encodings; namespace { -Uchar tab_iso8859_1[256] = { +char_type tab_iso8859_1[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, @@ -53,7 +53,7 @@ Uchar tab_iso8859_1[256] = { }; #ifdef USE_UNICODE_FOR_SYMBOLS -Uchar tab_symbol[256] = { +char_type tab_symbol[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, @@ -106,7 +106,7 @@ Uchar tab_symbol[256] = { #endif -unsigned char arabic_table2[63][4] = { +char_type arabic_table2[63][4] = { {0x41, 0x41, 0x41, 0x41}, // 0xc1 = hamza {0x42, 0xa1, 0x42, 0xa1}, // 0xc2 = ligature madda on alef {0x43, 0xa2, 0x43, 0xa2}, // 0xc3 = ligature hamza on alef @@ -176,7 +176,7 @@ unsigned char arabic_table2[63][4] = { }; -unsigned char arabic_table[63][2] = { +char_type arabic_table[63][2] = { {0xc1, 0xc1}, // 0xc1 = hamza {0xc2, 0xc2}, // 0xc2 = ligature madda on alef {0xc3, 0xc3}, // 0xc3 = ligature hamza on alef @@ -246,12 +246,20 @@ unsigned char arabic_table[63][2] = { }; -unsigned char const arabic_start = 0xc1; +char_type const arabic_start = 0xc1; } // namespace anon -bool Encodings::isComposeChar_hebrew(unsigned char c) + +char_type Encoding::ucs(char_type c) const +{ + BOOST_ASSERT(c < 256); + return encoding_table[c]; +} + + +bool Encodings::isComposeChar_hebrew(char_type c) { return c <= 0xd2 && c >= 0xc0 && c != 0xce && c != 0xd0; @@ -262,7 +270,7 @@ bool Encodings::isComposeChar_hebrew(unsigned char c) // they are hamza, alef_madda, alef_hamza, waw_hamza, alef_hamza_under, // alef, tah_marbota, dal, thal, rah, zai, wow, alef_maksoura -bool Encodings::is_arabic_special(unsigned char c) +bool Encodings::is_arabic_special(char_type c) { return (c >= 0xc1 && c <= 0xc5) || c == 0xc7 || c == 0xc9 || @@ -271,19 +279,19 @@ bool Encodings::is_arabic_special(unsigned char c) c == 0xe9; } -bool Encodings::isComposeChar_arabic(unsigned char c) +bool Encodings::isComposeChar_arabic(char_type c) { return c >= 0xeb && c <= 0xf2; } -bool Encodings::is_arabic(unsigned char c) +bool Encodings::is_arabic(char_type c) { return c >= arabic_start && arabic_table[c-arabic_start][0]; } -unsigned char Encodings::transformChar(unsigned char c, +char_type Encodings::transformChar(char_type c, Encodings::Letter_Form form) { if (!is_arabic(c)) @@ -340,7 +348,7 @@ void Encodings::read(string const & filename) lex.next(); string const latexname = lex.getString(); lyxerr[Debug::INFO] << "Reading encoding " << name << endl; - Uchar table[256]; + char_type table[256]; for (unsigned int i = 0; i < 256; ++i) { lex.next(); string const tmp = lex.getString(); diff --git a/src/encoding.h b/src/encoding.h index b80dd613d3..1463126c03 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -16,43 +16,35 @@ #include #include +#include "support/types.h" namespace lyx { - -/// -typedef unsigned short int Uchar; - /// class Encoding { public: /// Encoding() {} /// - Encoding(std::string const & n, std::string const & l, Uchar const * e) - : Name_(n), LatexName_(l) { + Encoding(std::string const & n, std::string const & l, char_type const * e) + : Name_(n), LatexName_(l) + { for (int i = 0; i < 256; ++i) encoding_table[i] = e[i]; } /// - std::string const & name() const { - return Name_; - } + std::string const & name() const { return Name_; } /// - std::string const & latexName() const { - return LatexName_; - } + std::string const & latexName() const { return LatexName_; } /// - Uchar ucs(unsigned char c) const { - return encoding_table[c]; - } + char_type ucs(char_type c) const; private: /// std::string Name_; /// std::string LatexName_; /// - Uchar encoding_table[256]; + char_type encoding_table[256]; }; extern Encoding symbol_encoding; @@ -68,9 +60,7 @@ public: /// Encoding const * getEncoding(std::string const & encoding) const; /// - Encoding const * symbol_encoding() { - return &symbol_encoding_; - } + Encoding const * symbol_encoding() { return &symbol_encoding_; } /// enum Letter_Form { @@ -84,20 +74,15 @@ public: FORM_MEDIAL }; /// - static - bool isComposeChar_hebrew(unsigned char c); + static bool isComposeChar_hebrew(char_type c); /// - static - bool isComposeChar_arabic(unsigned char c); + static bool isComposeChar_arabic(char_type c); /// - static - bool is_arabic_special(unsigned char c); + static bool is_arabic_special(char_type c); /// - static - bool is_arabic(unsigned char c); + static bool is_arabic(char_type c); /// - static - unsigned char transformChar(unsigned char c, Letter_Form form); + static char_type transformChar(char_type c, Letter_Form form); private: /// diff --git a/src/factory.C b/src/factory.C index d5287d895a..43930ac8c5 100644 --- a/src/factory.C +++ b/src/factory.C @@ -491,7 +491,7 @@ InsetBase * readInset(LyXLex & lex, Buffer const & buf) (tmpl->name(), tmpl->asMacroData()); lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION - << ": creating local macro " << tmpl->name() + << ": creating local macro " << to_utf8(tmpl->name()) << endl; } } diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index a4f16144e6..5a7fb20d81 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -465,7 +465,7 @@ searchKeys(InfoMap const & theMap, // (See Meyer's Effective STL, Item 28.) return (++rit).base(); } - catch (boost::regex_error & regerr) { + catch (boost::regex_error &) { return keys.end(); } } diff --git a/src/insets/inset.h b/src/insets/inset.h index 13a1109236..e7f4ea68f6 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -43,9 +43,9 @@ public: int width() const; /// - void setInsetName(std::string const & s) { name_ = s; } + void setInsetName(docstring const & s) { name_ = s; } /// - virtual std::string const & getInsetName() const { return name_; } + virtual docstring const & getInsetName() const { return name_; } /// virtual void setBackgroundColor(LColor_color); /// @@ -63,7 +63,7 @@ private: InsetOld & operator=(InsetOld const &) const; /// - std::string name_; + docstring name_; /** We store the LColor::color value as an int to get LColor.h out * of the header file. */ diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 86436782b1..fb9a1b5fb7 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -248,9 +248,9 @@ docstring const InsetBase::editMessage() const } -std::string const & InsetBase::getInsetName() const +docstring const & InsetBase::getInsetName() const { - static std::string const name = "unknown"; + static docstring const name = from_ascii("unknown"); return name; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index a7489406d0..538e99dfaf 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -185,9 +185,9 @@ public: std::vector & /* list */) const {} /// describe content if cursor inside - virtual void infoize(std::ostream &) const {} + virtual void infoize(odocstream &) const {} /// describe content if cursor behind - virtual void infoize2(std::ostream &) const {} + virtual void infoize2(odocstream &) const {} /// plain text output in ucs4 encoding virtual int plaintext(Buffer const &, odocstream &, @@ -337,7 +337,7 @@ public: virtual bool forceDefaultParagraphs(idx_type) const { return false; } /// - virtual std::string const & getInsetName() const; + virtual docstring const & getInsetName() const; /// used to toggle insets /// is the inset open? /// should this inset be handled like a normal charater diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index ce28dccd9a..7b87c85421 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -88,7 +88,7 @@ BoxTranslator const & boxtranslator_loc() void InsetBox::init() { - setInsetName("Box"); + setInsetName(from_ascii("Box")); setButtonLabel(); } diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 1ea9126951..9671ef86b5 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -38,7 +38,7 @@ using std::ostringstream; void InsetBranch::init() { - setInsetName("Branch"); + setInsetName(from_utf8("Branch")); setButtonLabel(); } diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index da1e7ae70a..87f327c804 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -101,21 +101,21 @@ void InsetCaption::setLabel(LCursor & cur) const InsetBase * const in = &cur[i].inset(); if (in->lyxCode() == InsetBase::FLOAT_CODE || in->lyxCode() == InsetBase::WRAP_CODE) { - s = in->getInsetName(); + s = to_utf8(in->getInsetName()); break; } } Floating const & fl = textclass_.floats().getType(s); s = fl.name(); - string num; + docstring num; if (s.empty()) s = "Senseless"; else - num = convert(counter_); + num = convert(counter_); // Generate the label label = to_utf8( - bformat(from_ascii("%1$s %2$s:"), _(s), from_ascii(num))); + bformat(from_ascii("%1$s %2$s:"), _(s), num)); } } diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index 3e9730858a..aa8d3ea292 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -51,7 +51,7 @@ using std::ostringstream; void InsetCharStyle::init() { - setInsetName("CharStyle"); + setInsetName(from_utf8("CharStyle")); setInlined(); setDrawFrame(false); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index ea5dea78ac..7d95df18c7 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -58,7 +58,7 @@ InsetCollapsable::InsetCollapsable setAutoBreakRows(true); setDrawFrame(true); setFrameColor(LColor::collapsableframe); - setInsetName("Collapsable"); + setInsetName(from_ascii("Collapsable")); setButtonLabel(); } diff --git a/src/insets/insetenv.C b/src/insets/insetenv.C index 24f18050b9..fd2d2cca4f 100644 --- a/src/insets/insetenv.C +++ b/src/insets/insetenv.C @@ -30,7 +30,7 @@ InsetEnvironment::InsetEnvironment (BufferParams const & bp, string const & name) : InsetText(bp), layout_(bp.getLyXTextClass()[name]) { - setInsetName(name); + setInsetName(from_utf8(name)); setAutoBreakRows(true); setDrawFrame(true); } @@ -49,7 +49,7 @@ auto_ptr InsetEnvironment::doClone() const void InsetEnvironment::write(Buffer const & buf, ostream & os) const { - os << "Environment " << getInsetName() << "\n"; + os << "Environment " << to_utf8(getInsetName()) << "\n"; InsetText::write(buf, os); } @@ -62,8 +62,7 @@ void InsetEnvironment::read(Buffer const & buf, LyXLex & lex) docstring const InsetEnvironment::editMessage() const { - // FIXME UNICODE - return _("Opened Environment Inset: ") + from_utf8(getInsetName()); + return _("Opened Environment Inset: ") + getInsetName(); } diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 12421345f5..26d82f1168 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -62,7 +62,7 @@ void InsetERT::init() text_.current_font.setLanguage(latex_language); text_.real_current_font.setLanguage(latex_language); - setInsetName("ERT"); + setInsetName(from_ascii("ERT")); } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 0ba647db47..fb48320dd7 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -127,7 +127,7 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type) font.setColor(LColor::collapsable); setLabelFont(font); params_.type = type; - setInsetName(type); + setInsetName(from_utf8(type)); } diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index b1b554f7ac..b9be27578b 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -35,7 +35,7 @@ InsetFoot::InsetFoot(BufferParams const & bp) : InsetFootlike(bp) { setLabel(_("foot")); - setInsetName("Foot"); + setInsetName(from_ascii("Foot")); } @@ -43,7 +43,7 @@ InsetFoot::InsetFoot(InsetFoot const & in) : InsetFootlike(in) { setLabel(_("foot")); - setInsetName("Foot"); + setInsetName(from_ascii("Foot")); } diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index ba832222c6..c071c3cfbc 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -65,7 +65,7 @@ void InsetFootlike::draw(PainterInfo & pi, int x, int y) const void InsetFootlike::write(Buffer const & buf, std::ostream & os) const { - os << getInsetName() << "\n"; + os << to_utf8(getInsetName()) << "\n"; InsetCollapsable::write(buf, os); } diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 936257e25d..c8f418bcb0 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -30,7 +30,7 @@ InsetMarginal::InsetMarginal(BufferParams const & bp) : InsetFootlike(bp) { setLabel(_("margin")); - setInsetName("Marginal"); + setInsetName(from_ascii("Marginal")); } @@ -38,7 +38,7 @@ InsetMarginal::InsetMarginal(InsetMarginal const & in) : InsetFootlike(in) { setLabel(_("margin")); - setInsetName("Marginal"); + setInsetName(from_ascii("Marginal")); } diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index b51078611a..d9ef2f787b 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -112,7 +112,7 @@ void InsetNoteParams::read(LyXLex & lex) void InsetNote::init() { - setInsetName("Note"); + setInsetName(from_utf8("Note")); setButtonLabel(); } diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 8e7b76c1c4..46b9a99e05 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -85,14 +85,14 @@ char const * const latex_quote_babel[2][5] = InsetQuotes::InsetQuotes(string const & str) { parseString(str); - setInsetName("InsetQuotes"); + setInsetName(from_utf8("InsetQuotes")); } InsetQuotes::InsetQuotes(quote_language l, quote_side s, quote_times t) : language_(l), side_(s), times_(t) { - setInsetName("InsetQuotes"); + setInsetName(from_utf8("InsetQuotes")); } @@ -100,7 +100,7 @@ InsetQuotes::InsetQuotes(char_type c, BufferParams const & params) : language_(params.quotes_language), times_(params.quotes_times) { getPosition(c); - setInsetName("InsetQuotes"); + setInsetName(from_utf8("InsetQuotes")); } @@ -108,7 +108,7 @@ InsetQuotes::InsetQuotes(char_type c, quote_language l, quote_times t) : language_(l), times_(t) { getPosition(c); - setInsetName("InsetQuotes"); + setInsetName(from_utf8("InsetQuotes")); } diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 13f1831a57..c6ef786c2d 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -54,7 +54,7 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type) setLabelFont(font); params_.type = type; params_.width = LyXLength(50, LyXLength::PCW); - setInsetName(type); + setInsetName(from_utf8(type)); } diff --git a/src/lyxfind.C b/src/lyxfind.C index dd4588ca5e..60892d6320 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -186,7 +186,7 @@ int replaceAll(BufferView * bv, = cur.paragraph().getFontSettings(buf.params(), pos); int striked = ssize - cur.paragraph().erase(pos, pos + ssize, buf.params().trackChanges); - cur.paragraph().insert(pos, replacestr, font, + cur.paragraph().insert(pos, from_utf8(replacestr), font, Change(buf.params().trackChanges ? Change::INSERTED : Change::UNCHANGED)); for (int i = 0; i < rsize + striked; ++i) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index ae6109d094..1ff7b53754 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -223,11 +223,10 @@ void LyXFunc::setLyXView(LyXView * lv) void LyXFunc::handleKeyFunc(kb_action action) { - char c = encoded_last_key; + char_type c = encoded_last_key; - if (keyseq->length()) { + if (keyseq->length()) c = 0; - } lyx_view_->view()->getIntl().getTransManager() .deadkey(c, get_accent(action).accent, view()->getLyXText()); diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 663367e949..ad27ec2101 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -31,9 +31,9 @@ public: /// InsetFormulaMacro(); /// construct a macro hull from its name and the number of arguments - InsetFormulaMacro(std::string const & name, int nargs, std::string const & t); + InsetFormulaMacro(docstring const & name, int nargs, docstring const & t); /// constructs a mocro from its LaTeX definition - explicit InsetFormulaMacro(std::string const & s); + explicit InsetFormulaMacro(docstring const & s); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -58,7 +58,7 @@ public: /// InsetBase::Code lyxCode() const { return MATHMACRO_CODE; } /// - std::string const & getInsetName() const { return name_; } + docstring const & getInsetName() const { return name_; } /// EDITABLE editable() const { return HIGHLY_EDITABLE; } private: @@ -67,9 +67,9 @@ private: /// void read(std::istream & is); /// prefix in inset - std::string prefix() const; + docstring prefix() const; /// - std::string name_; + docstring name_; }; diff --git a/src/mathed/InsetMath.C b/src/mathed/InsetMath.C index a73024deef..2a6d4462a4 100644 --- a/src/mathed/InsetMath.C +++ b/src/mathed/InsetMath.C @@ -13,7 +13,7 @@ #include "InsetMath.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "debug.h" #include "support/lstrings.h" @@ -23,7 +23,6 @@ namespace lyx { -using std::string; using std::endl; @@ -73,8 +72,8 @@ void InsetMath::drawT(TextPainter &, int, int) const void InsetMath::write(WriteStream & os) const { - string const s = name(); - os << '\\' << s.c_str(); + docstring const s = name(); + os << "\\" << s; // We need an extra ' ' unless this is a single-char-non-ASCII name // or anything non-ASCII follows if (s.size() != 1 || isalpha(s[0])) @@ -84,7 +83,7 @@ void InsetMath::write(WriteStream & os) const void InsetMath::normalize(NormalStream & os) const { - os << '[' << name().c_str() << "] "; + os << '[' << name() << "] "; } @@ -116,7 +115,7 @@ void InsetMath::mathematica(MathematicaStream & os) const } -void InsetMath::mathmlize(MathMLStream & os) const +void InsetMath::mathmlize(MathStream & os) const { NormalStream ns(os.os()); normalize(ns); @@ -129,9 +128,9 @@ HullType InsetMath::getType() const } -string InsetMath::name() const +docstring InsetMath::name() const { - return "unknown"; + return from_ascii("unknown"); } diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index a08734589d..3cfc107e58 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -34,8 +34,8 @@ enum HullType { hullGather }; -HullType hullType(std::string const & name); -std::string hullName(HullType type); +HullType hullType(docstring const & name); +docstring hullName(HullType type); /** @@ -77,7 +77,7 @@ class OctaveStream; class MapleStream; class MaximaStream; class MathematicaStream; -class MathMLStream; +class MathStream; class WriteStream; class InfoStream; @@ -153,12 +153,12 @@ public: virtual bool extraBraces() const { return false; } /// return the content as char if the inset is able to do so - virtual char getChar() const { return 0; } + virtual char_type getChar() const { return 0; } /// identifies things that can get \limits or \nolimits virtual bool takesLimits() const { return false; } /// char char code if possible - virtual void handleFont(std::string const &) {} + virtual void handleFont(docstring const &) {} /// replace things by other things virtual void replace(ReplaceData &) {} /// do we contain a given subsequence? @@ -179,7 +179,7 @@ public: /// write content as something readable by Mathematica virtual void mathematica(MathematicaStream &) const; /// write content as something resembling MathML - virtual void mathmlize(MathMLStream &) const; + virtual void mathmlize(MathStream &) const; /// write content as something readable by Octave virtual void octave(OctaveStream &) const; @@ -193,7 +193,7 @@ public: /// change type virtual void mutate(HullType /*newtype*/) {} /// usually the latex name - virtual std::string name() const; + virtual docstring name() const; /// math stuff usually isn't allowed in text mode virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; } diff --git a/src/mathed/InsetMathAMSArray.C b/src/mathed/InsetMathAMSArray.C index 2a6e00ae72..18b3502ed8 100644 --- a/src/mathed/InsetMathAMSArray.C +++ b/src/mathed/InsetMathAMSArray.C @@ -13,7 +13,7 @@ #include "LaTeXFeatures.h" #include "InsetMathAMSArray.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" @@ -24,21 +24,19 @@ #include "support/lstrings.h" #include "support/std_ostream.h" -using std::string; using std::auto_ptr; - namespace lyx { using support::bformat; -InsetMathAMSArray::InsetMathAMSArray(string const & name, int m, int n) +InsetMathAMSArray::InsetMathAMSArray(docstring const & name, int m, int n) : InsetMathGrid(m, n), name_(name) {} -InsetMathAMSArray::InsetMathAMSArray(string const & name) +InsetMathAMSArray::InsetMathAMSArray(docstring const & name) : InsetMathGrid(1, 1), name_(name) {} @@ -94,8 +92,8 @@ void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const { int const yy = y - dim_.ascent(); // Drawing the deco after an ArrayChanger does not work - mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left()); - mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), name_right()); + mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left())); + mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right())); ArrayChanger dummy(pi.base); InsetMathGrid::drawWithMargin(pi, x, y, 6, 8); } @@ -109,8 +107,7 @@ bool InsetMathAMSArray::getStatus(LCursor & cur, FuncRequest const & cmd, docstring const & s = cmd.argument(); if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( - from_utf8(N_("Can't add vertical grid lines in '%1$s'")), - from_utf8(name_))); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); flag.enabled(false); return true; } @@ -130,9 +127,9 @@ void InsetMathAMSArray::write(WriteStream & os) const } -void InsetMathAMSArray::infoize(std::ostream & os) const +void InsetMathAMSArray::infoize(odocstream & os) const { - string name = name_; + docstring name = name_; name[0] = support::uppercase(name[0]); os << name << ' '; } diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index 4b885f9e39..b5f7255b37 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -21,9 +21,9 @@ namespace lyx { class InsetMathAMSArray : public InsetMathGrid { public: /// - InsetMathAMSArray(std::string const & name, int m, int n); + InsetMathAMSArray(docstring const & name, int m, int n); /// - InsetMathAMSArray(std::string const & name); + InsetMathAMSArray(docstring const & name); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -39,7 +39,7 @@ public: /// void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void normalize(NormalStream &) const; /// @@ -52,7 +52,7 @@ private: char const * name_right() const; /// - std::string name_; + docstring name_; }; } // namespace lyx diff --git a/src/mathed/InsetMathArray.C b/src/mathed/InsetMathArray.C index 5ab84f5800..83b94dcea6 100644 --- a/src/mathed/InsetMathArray.C +++ b/src/mathed/InsetMathArray.C @@ -14,7 +14,7 @@ #include "InsetMathArray.h" #include "MathData.h" #include "MathParser.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "support/lstrings.h" @@ -26,36 +26,35 @@ namespace lyx { using std::getline; - -using std::string; using std::auto_ptr; using std::istringstream; using std::istream_iterator; using std::vector; +using std::string; -InsetMathArray::InsetMathArray(string const & name, int m, int n) +InsetMathArray::InsetMathArray(docstring const & name, int m, int n) : InsetMathGrid(m, n), name_(name) {} -InsetMathArray::InsetMathArray(string const & name, int m, int n, - char valign, string const & halign) +InsetMathArray::InsetMathArray(docstring const & name, int m, int n, + char valign, docstring const & halign) : InsetMathGrid(m, n, valign, halign), name_(name) {} -InsetMathArray::InsetMathArray(string const & name, char valign, - string const & halign) +InsetMathArray::InsetMathArray(docstring const & name, char valign, + docstring const & halign) : InsetMathGrid(valign, halign), name_(name) {} -InsetMathArray::InsetMathArray(string const & name, string const & str) +InsetMathArray::InsetMathArray(docstring const & name, docstring const & str) : InsetMathGrid(1, 1), name_(name) { vector< vector > dat; - istringstream is(str); + istringstream is(to_utf8(str)); string line; while (getline(is, line)) { istringstream ls(line); @@ -71,7 +70,7 @@ InsetMathArray::InsetMathArray(string const & name, string const & str) addCol(0); for (row_type row = 0; row < dat.size(); ++row) for (col_type col = 0; col < dat[0].size(); ++col) - mathed_parse_cell(cell(index(row, col)), dat[row][col]); + mathed_parse_cell(cell(index(row, col)), from_utf8(dat[row][col])); } @@ -118,9 +117,9 @@ void InsetMathArray::write(WriteStream & os) const } -void InsetMathArray::infoize(std::ostream & os) const +void InsetMathArray::infoize(odocstream & os) const { - string name = name_; + docstring name = name_; name[0] = support::uppercase(name[0]); os << name << ' '; } diff --git a/src/mathed/InsetMathArray.h b/src/mathed/InsetMathArray.h index 832ba7cdb0..b14f9b2e4e 100644 --- a/src/mathed/InsetMathArray.h +++ b/src/mathed/InsetMathArray.h @@ -22,14 +22,14 @@ namespace lyx { class InsetMathArray : public InsetMathGrid { public: /// - InsetMathArray(std::string const &, int m, int n); + InsetMathArray(docstring const &, int m, int n); /// - InsetMathArray(std::string const &, int m, int n, - char valign, std::string const & halign); + InsetMathArray(docstring const &, int m, int n, + char valign, docstring const & halign); /// - InsetMathArray(std::string const &, char valign, std::string const & halign); + InsetMathArray(docstring const &, char valign, docstring const & halign); /// convenience constructor from whitespace/newline separated data - InsetMathArray(std::string const &, std::string const & str); + InsetMathArray(docstring const &, docstring const & str); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -42,7 +42,7 @@ public: /// void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void normalize(NormalStream & os) const; /// @@ -52,7 +52,7 @@ public: private: virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; }; diff --git a/src/mathed/InsetMathBig.C b/src/mathed/InsetMathBig.C index b2ac392e4a..49dbcd73c0 100644 --- a/src/mathed/InsetMathBig.C +++ b/src/mathed/InsetMathBig.C @@ -12,7 +12,7 @@ #include "InsetMathBig.h" #include "MathSupport.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "frontends/FontMetrics.h" @@ -22,17 +22,15 @@ namespace lyx { - -using std::string; using std::auto_ptr; -InsetMathBig::InsetMathBig(string const & name, string const & delim) +InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim) : name_(name), delim_(delim) {} -string InsetMathBig::name() const +docstring InsetMathBig::name() const { return name_; } @@ -80,8 +78,8 @@ void InsetMathBig::draw(PainterInfo & pi, int x, int y) const // mathed_draw_deco does not use the leading backslash, so remove it. // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco // would treat it as |. - string const delim = (delim_ == "\\|") ? "Vert" : - support::ltrim(delim_, "\\"); + docstring const delim = + (delim_ == "\\|") ? from_ascii("Vert") : support::ltrim(delim_, "\\"); mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(), delim); setPosCache(pi, x, y); @@ -98,17 +96,17 @@ void InsetMathBig::write(WriteStream & os) const void InsetMathBig::normalize(NormalStream & os) const { - os << '[' << name_ << ' ' << delim_ << ']'; + os << '[' << name_ << ' ' << delim_ << ']'; } -void InsetMathBig::infoize2(std::ostream & os) const +void InsetMathBig::infoize2(odocstream & os) const { os << name_; } -bool InsetMathBig::isBigInsetDelim(string const & delim) +bool InsetMathBig::isBigInsetDelim(docstring const & delim) { // mathed_draw_deco must handle these static char const * const delimiters[] = { @@ -120,7 +118,7 @@ bool InsetMathBig::isBigInsetDelim(string const & delim) "\\uparrow", "\\Uparrow", "\\updownarrow", "\\Updownarrow", "" }; - return (support::findToken(delimiters, delim) >= 0); + return support::findToken(delimiters, to_utf8(delim)) >= 0; } diff --git a/src/mathed/InsetMathBig.h b/src/mathed/InsetMathBig.h index 6ffa83fd18..336c376067 100644 --- a/src/mathed/InsetMathBig.h +++ b/src/mathed/InsetMathBig.h @@ -23,9 +23,9 @@ namespace lyx { class InsetMathBig : public InsetMathDim { public: /// - InsetMathBig(std::string const & name, std::string const & delim); + InsetMathBig(docstring const & name, docstring const & delim); /// - std::string name() const; + docstring name() const; /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -35,9 +35,9 @@ public: /// void normalize(NormalStream & os) const; /// - void infoize2(std::ostream & os) const; + void infoize2(odocstream & os) const; /// - static bool isBigInsetDelim(std::string const &); + static bool isBigInsetDelim(docstring const &); private: virtual std::auto_ptr doClone() const; @@ -47,9 +47,9 @@ private: double increase() const; /// \\bigl or what? - std::string const name_; + docstring const name_; /// ( or [ or \\Vert... - std::string const delim_; + docstring const delim_; }; diff --git a/src/mathed/InsetMathBinom.C b/src/mathed/InsetMathBinom.C index b31c2f3fcc..8597514000 100644 --- a/src/mathed/InsetMathBinom.C +++ b/src/mathed/InsetMathBinom.C @@ -13,7 +13,7 @@ #include "InsetMathBinom.h" #include "MathData.h" #include "MathSupport.h" -#include "MathMLStream.h" +#include "MathStream.h" namespace lyx { @@ -64,9 +64,9 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const ScriptChanger dummy(pi.base); cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5); cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 3 - 5); - mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), "("); + mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("(")); mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(), - dw(), dim_.height(), ")"); + dw(), dim_.height(), from_ascii(")")); drawMarkers2(pi, x, y); } diff --git a/src/mathed/InsetMathBoldSymbol.C b/src/mathed/InsetMathBoldSymbol.C index a796958c95..402648983d 100644 --- a/src/mathed/InsetMathBoldSymbol.C +++ b/src/mathed/InsetMathBoldSymbol.C @@ -11,7 +11,7 @@ #include #include "InsetMathBoldSymbol.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathData.h" #include "LaTeXFeatures.h" #include "support/std_ostream.h" @@ -77,7 +77,7 @@ void InsetMathBoldSymbol::write(WriteStream & os) const } -void InsetMathBoldSymbol::infoize(std::ostream & os) const +void InsetMathBoldSymbol::infoize(odocstream & os) const { os << "Boldsymbol "; } diff --git a/src/mathed/InsetMathBoldSymbol.h b/src/mathed/InsetMathBoldSymbol.h index f73c74b322..cc50dae5e6 100644 --- a/src/mathed/InsetMathBoldSymbol.h +++ b/src/mathed/InsetMathBoldSymbol.h @@ -36,7 +36,7 @@ public: /// void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathBox.C b/src/mathed/InsetMathBox.C index 6749d2e1de..cdae7fdd89 100644 --- a/src/mathed/InsetMathBox.C +++ b/src/mathed/InsetMathBox.C @@ -12,7 +12,7 @@ #include "InsetMathBox.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "support/std_ostream.h" @@ -23,7 +23,7 @@ using std::string; using std::auto_ptr; -InsetMathBox::InsetMathBox(string const & name) +InsetMathBox::InsetMathBox(docstring const & name) : InsetMathNest(1), name_(name) {} @@ -65,7 +65,7 @@ void InsetMathBox::draw(PainterInfo & pi, int x, int y) const } -void InsetMathBox::infoize(std::ostream & os) const +void InsetMathBox::infoize(odocstream & os) const { os << "Box: " << name_; } diff --git a/src/mathed/InsetMathBox.h b/src/mathed/InsetMathBox.h index e3bd98277d..0591d29e0a 100644 --- a/src/mathed/InsetMathBox.h +++ b/src/mathed/InsetMathBox.h @@ -27,7 +27,7 @@ class LyXFont; class InsetMathBox : public InsetMathNest { public: /// - explicit InsetMathBox(std::string const & name); + explicit InsetMathBox(docstring const & name); /// mode_type currentMode() const { return TEXT_MODE; } /// @@ -39,12 +39,12 @@ public: /// void normalize(NormalStream & ns) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; }; diff --git a/src/mathed/InsetMathBoxed.C b/src/mathed/InsetMathBoxed.C index 076e668e55..0f8d830284 100644 --- a/src/mathed/InsetMathBoxed.C +++ b/src/mathed/InsetMathBoxed.C @@ -12,7 +12,7 @@ #include "InsetMathBoxed.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "MathStream.h" #include "LaTeXFeatures.h" @@ -67,7 +67,7 @@ void InsetMathBoxed::normalize(NormalStream & os) const } -void InsetMathBoxed::infoize(std::ostream & os) const +void InsetMathBoxed::infoize(odocstream & os) const { os << "Boxed: "; } diff --git a/src/mathed/InsetMathBoxed.h b/src/mathed/InsetMathBoxed.h index c4a20f10f2..2764b8aa6c 100644 --- a/src/mathed/InsetMathBoxed.h +++ b/src/mathed/InsetMathBoxed.h @@ -34,7 +34,7 @@ public: /// write normalized content void normalize(NormalStream & ns) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathBrace.C b/src/mathed/InsetMathBrace.C index 2119e9322c..03c7c567db 100644 --- a/src/mathed/InsetMathBrace.C +++ b/src/mathed/InsetMathBrace.C @@ -12,7 +12,7 @@ #include "InsetMathBrace.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "LColor.h" #include "support/std_ostream.h" @@ -93,7 +93,7 @@ void InsetMathBrace::octave(OctaveStream & os) const } -void InsetMathBrace::mathmlize(MathMLStream & os) const +void InsetMathBrace::mathmlize(MathStream & os) const { os << MTag("mrow") << cell(0) << ETag("mrow"); } @@ -105,7 +105,7 @@ void InsetMathBrace::mathematica(MathematicaStream & os) const } -void InsetMathBrace::infoize(std::ostream & os) const +void InsetMathBrace::infoize(odocstream & os) const { os << "Nested Block: "; } diff --git a/src/mathed/InsetMathBrace.h b/src/mathed/InsetMathBrace.h index 74104f9430..fd673f36fe 100644 --- a/src/mathed/InsetMathBrace.h +++ b/src/mathed/InsetMathBrace.h @@ -44,9 +44,9 @@ public: /// void octave(OctaveStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathCases.C b/src/mathed/InsetMathCases.C index d0eca4f5e8..46c09caa2c 100644 --- a/src/mathed/InsetMathCases.C +++ b/src/mathed/InsetMathCases.C @@ -12,7 +12,7 @@ #include "InsetMathCases.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "FuncStatus.h" #include "LaTeXFeatures.h" @@ -33,13 +33,11 @@ using std::endl; using std::max; using std::min; using std::swap; -using std::string; - using std::auto_ptr; InsetMathCases::InsetMathCases(row_type n) - : InsetMathGrid(2, n, 'c', "ll") + : InsetMathGrid(2, n, 'c', from_ascii("ll")) {} @@ -59,7 +57,7 @@ void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathCases::draw(PainterInfo & pi, int x, int y) const { - mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), "{"); + mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), from_ascii("{")); InsetMathGrid::drawWithMargin(pi, x, y, 8, 0); setPosCache(pi, x, y); } @@ -131,7 +129,7 @@ void InsetMathCases::maple(MapleStream & os) const } -void InsetMathCases::infoize(std::ostream & os) const +void InsetMathCases::infoize(odocstream & os) const { os << "Cases "; } diff --git a/src/mathed/InsetMathCases.h b/src/mathed/InsetMathCases.h index ed80121830..bae0cd7619 100644 --- a/src/mathed/InsetMathCases.h +++ b/src/mathed/InsetMathCases.h @@ -35,7 +35,7 @@ public: FuncStatus & flag) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void normalize(NormalStream &) const; /// diff --git a/src/mathed/InsetMathChar.C b/src/mathed/InsetMathChar.C index 0809b56ec0..18437ff6cf 100644 --- a/src/mathed/InsetMathChar.C +++ b/src/mathed/InsetMathChar.C @@ -13,7 +13,7 @@ #include "InsetMathChar.h" #include "MathSupport.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "debug.h" #include "dimension.h" @@ -31,13 +31,13 @@ extern bool has_math_fonts; namespace { - bool isBinaryOp(char c) + bool isBinaryOp(char_type c) { - return support::contains("+-<>=/*", c); + return support::contains("+-<>=/*", static_cast(c)); } - bool slanted(char c) + bool slanted(char_type c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); } @@ -45,7 +45,7 @@ namespace { } -InsetMathChar::InsetMathChar(char c) +InsetMathChar::InsetMathChar(char_type c) : char_(c) {} @@ -132,29 +132,31 @@ void InsetMathChar::drawT(TextPainter & pain, int x, int y) const void InsetMathChar::write(WriteStream & os) const { - os << char_; + os.os().put(char_); } void InsetMathChar::normalize(NormalStream & os) const { - os << "[char " << char_ << " mathalpha]"; + os << "[char "; + os.os().put(char_); + os << " mathalpha]"; } void InsetMathChar::octave(OctaveStream & os) const { - os << char_; + os.os().put(char_); } -void InsetMathChar::mathmlize(MathMLStream & ms) const +void InsetMathChar::mathmlize(MathStream & ms) const { switch (char_) { case '<': ms << "<"; break; case '>': ms << ">"; break; case '&': ms << "&"; break; - default: ms << char_; break; + default: ms.os().put(char_); break; } } diff --git a/src/mathed/InsetMathChar.h b/src/mathed/InsetMathChar.h index acbbccd67a..140c16829b 100644 --- a/src/mathed/InsetMathChar.h +++ b/src/mathed/InsetMathChar.h @@ -21,7 +21,7 @@ namespace lyx { class InsetMathChar : public InsetMath { public: /// - explicit InsetMathChar(char c); + explicit InsetMathChar(char_type c); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -40,18 +40,18 @@ public: /// void octave(OctaveStream & os) const; /// - void mathmlize(MathMLStream & ms) const; + void mathmlize(MathStream & ms) const; /// identifies Charinsets InsetMathChar const * asCharInset() const { return this; } /// - char getChar() const { return char_; } + char_type getChar() const { return char_; } /// bool isRelOp() const; private: virtual std::auto_ptr doClone() const; /// the character - char char_; + char_type char_; /// cached width mutable int width_; }; diff --git a/src/mathed/InsetMathColor.C b/src/mathed/InsetMathColor.C index bf23aa904f..55d9c656cb 100644 --- a/src/mathed/InsetMathColor.C +++ b/src/mathed/InsetMathColor.C @@ -12,10 +12,8 @@ #include "InsetMathColor.h" #include "MathData.h" -#include "MathMLStream.h" #include "MathStream.h" #include "MathSupport.h" - #include "LaTeXFeatures.h" #include "support/std_ostream.h" @@ -26,25 +24,13 @@ namespace lyx { using std::auto_ptr; using std::string; - -namespace { - -/// color "none" (reset to default) needs special treatment -bool normalcolor(string const & color) -{ - return color == "none"; -} - -} // namespace anon - - InsetMathColor::InsetMathColor(bool oldstyle, LColor_color const & color) : InsetMathNest(1), oldstyle_(oldstyle), - color_(lcolor.getLaTeXName(color)) + color_(from_utf8(lcolor.getLaTeXName(color))) {} -InsetMathColor::InsetMathColor(bool oldstyle, string const & color) +InsetMathColor::InsetMathColor(bool oldstyle, docstring const & color) : InsetMathNest(1), oldstyle_(oldstyle), color_(color) {} @@ -66,7 +52,7 @@ void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathColor::draw(PainterInfo & pi, int x, int y) const { LColor_color origcol = pi.base.font.color(); - pi.base.font.setColor(lcolor.getFromLaTeXName(color_)); + pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_))); cell(0).draw(pi, x + 1, y); pi.base.font.setColor(origcol); drawMarkers(pi, x, y); @@ -74,6 +60,13 @@ void InsetMathColor::draw(PainterInfo & pi, int x, int y) const } +/// color "none" (reset to default) needs special treatment +static bool normalcolor(docstring const & color) +{ + return color == "none"; +} + + void InsetMathColor::validate(LaTeXFeatures & features) const { InsetMathNest::validate(features); @@ -88,9 +81,9 @@ void InsetMathColor::write(WriteStream & os) const // reset to default color inside another color inset os << "{\\normalcolor " << cell(0) << '}'; else if (oldstyle_) - os << "{\\color" << '{' << color_ << '}' << cell(0) << '}'; + os << "{\\color{" << color_ << '}' << cell(0) << '}'; else - os << "\\textcolor" << '{' << color_ << "}{" << cell(0) << '}'; + os << "\\textcolor{" << color_ << "}{" << cell(0) << '}'; } @@ -100,7 +93,7 @@ void InsetMathColor::normalize(NormalStream & os) const } -void InsetMathColor::infoize(std::ostream & os) const +void InsetMathColor::infoize(odocstream & os) const { os << "Color: " << color_; } diff --git a/src/mathed/InsetMathColor.h b/src/mathed/InsetMathColor.h index 68c0f47f58..71fada0473 100644 --- a/src/mathed/InsetMathColor.h +++ b/src/mathed/InsetMathColor.h @@ -27,7 +27,7 @@ public: explicit InsetMathColor(bool oldstyle, LColor_color const & color = LColor::none); /// Create a color inset from LaTeX color name - explicit InsetMathColor(bool oldstyle, std::string const & color); + explicit InsetMathColor(bool oldstyle, docstring const & color); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// we write extra braces in any case... @@ -42,7 +42,7 @@ public: /// write normalized content void normalize(NormalStream & ns) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; /// width of '[' in current font @@ -50,7 +50,7 @@ private: /// bool oldstyle_; /// Our color. Only valid LaTeX colors are allowed. - std::string color_; + docstring color_; }; diff --git a/src/mathed/InsetMathCommand.C b/src/mathed/InsetMathCommand.C index f63babaafb..415c72b355 100644 --- a/src/mathed/InsetMathCommand.C +++ b/src/mathed/InsetMathCommand.C @@ -12,7 +12,7 @@ #include "InsetMathCommand.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "dispatchresult.h" #include "funcrequest.h" @@ -21,11 +21,10 @@ namespace lyx { -using std::string; using std::auto_ptr; +using std::string; - -CommandInset::CommandInset(string const & name) +CommandInset::CommandInset(docstring const & name) : InsetMathNest(2), name_(name), set_label_(false) { lock_ = true; @@ -74,18 +73,17 @@ void CommandInset::write(WriteStream & os) const docstring const CommandInset::screenLabel() const { - return from_ascii(name_); + return name_; } string const CommandInset::createDialogStr(string const & name) const { odocstringstream os; - os << from_ascii(name) << " LatexCommand "; + os << from_ascii(name + " LatexCommand "); WriteStream ws(os); write(ws); - ws << "\n\\end_inset\n\n"; - return to_utf8(os.str()); + return to_utf8(os.str()) + "\n\\end_inset\n\n"; } diff --git a/src/mathed/InsetMathCommand.h b/src/mathed/InsetMathCommand.h index 1b00daf3fd..a95ec06c68 100644 --- a/src/mathed/InsetMathCommand.h +++ b/src/mathed/InsetMathCommand.h @@ -25,7 +25,7 @@ namespace lyx { class CommandInset : public InsetMathNest { public: /// - explicit CommandInset(std::string const & name); + explicit CommandInset(docstring const & name); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -35,18 +35,18 @@ public: /// void write(WriteStream & os) const; // - // void infoize(std::ostream & os) const; + // void infoize(odocstream & os) const; /// virtual docstring const screenLabel() const; /// generate something that will be understood by the Dialogs. std::string const createDialogStr(std::string const & name) const; /// - std::string const & commandname() const { return name_; } + docstring const & commandname() const { return name_; } private: virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; /// mutable bool set_label_; /// diff --git a/src/mathed/InsetMathComment.C b/src/mathed/InsetMathComment.C index c4cf1b820d..650c27f25d 100644 --- a/src/mathed/InsetMathComment.C +++ b/src/mathed/InsetMathComment.C @@ -12,7 +12,7 @@ #include "InsetMathComment.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "support/std_ostream.h" @@ -28,11 +28,11 @@ InsetMathComment::InsetMathComment() {} -InsetMathComment::InsetMathComment(string const & str) +InsetMathComment::InsetMathComment(docstring const & str) : InsetMathNest(1) { // FIXME UNICODE - asArray(from_utf8(str), cell(0)); + asArray(str, cell(0)); } @@ -89,13 +89,13 @@ void InsetMathComment::octave(OctaveStream &) const {} -void InsetMathComment::mathmlize(MathMLStream & os) const +void InsetMathComment::mathmlize(MathStream & os) const { os << MTag("comment") << cell(0) << cell(1) << ETag("comment"); } -void InsetMathComment::infoize(std::ostream & os) const +void InsetMathComment::infoize(odocstream & os) const { os << "Comment"; } diff --git a/src/mathed/InsetMathComment.h b/src/mathed/InsetMathComment.h index 53bb347b25..184c7bd142 100644 --- a/src/mathed/InsetMathComment.h +++ b/src/mathed/InsetMathComment.h @@ -25,7 +25,7 @@ public: /// InsetMathComment(); /// - explicit InsetMathComment(std::string const &); + explicit InsetMathComment(docstring const &); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -44,9 +44,9 @@ public: /// void octave(OctaveStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathDFrac.C b/src/mathed/InsetMathDFrac.C index cc2f0f64e8..e2c771e091 100644 --- a/src/mathed/InsetMathDFrac.C +++ b/src/mathed/InsetMathDFrac.C @@ -12,7 +12,7 @@ #include "InsetMathDFrac.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "LaTeXFeatures.h" #include "LColor.h" #include "frontends/Painter.h" @@ -58,13 +58,13 @@ void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const } -string InsetMathDFrac::name() const +docstring InsetMathDFrac::name() const { - return "dfrac"; + return from_ascii("dfrac"); } -void InsetMathDFrac::mathmlize(MathMLStream & os) const +void InsetMathDFrac::mathmlize(MathStream & os) const { os << MTag("mdfrac") << cell(0) << cell(1) << ETag("mdfrac"); } diff --git a/src/mathed/InsetMathDFrac.h b/src/mathed/InsetMathDFrac.h index 4929df48e4..596f3f5522 100644 --- a/src/mathed/InsetMathDFrac.h +++ b/src/mathed/InsetMathDFrac.h @@ -28,9 +28,9 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - std::string name() const; + docstring name() const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void validate(LaTeXFeatures & features) const; private: diff --git a/src/mathed/InsetMathDecoration.C b/src/mathed/InsetMathDecoration.C index d7e15839cc..0d67122d85 100644 --- a/src/mathed/InsetMathDecoration.C +++ b/src/mathed/InsetMathDecoration.C @@ -15,7 +15,7 @@ #include "MathData.h" #include "MathSupport.h" #include "MathParser.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "LaTeXFeatures.h" @@ -149,7 +149,7 @@ void InsetMathDecoration::normalize(NormalStream & os) const } -void InsetMathDecoration::infoize(std::ostream & os) const +void InsetMathDecoration::infoize(odocstream & os) const { os << "Deco: " << key_->name; } diff --git a/src/mathed/InsetMathDecoration.h b/src/mathed/InsetMathDecoration.h index 70e5c011c3..030836617f 100644 --- a/src/mathed/InsetMathDecoration.h +++ b/src/mathed/InsetMathDecoration.h @@ -34,7 +34,7 @@ public: /// void normalize(NormalStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// bool isScriptable() const; /// diff --git a/src/mathed/InsetMathDelim.C b/src/mathed/InsetMathDelim.C index 78f3fb8ef5..b59ca12fea 100644 --- a/src/mathed/InsetMathDelim.C +++ b/src/mathed/InsetMathDelim.C @@ -13,7 +13,7 @@ #include "InsetMathDelim.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" @@ -25,42 +25,26 @@ using std::string; using std::max; using std::auto_ptr; -namespace { -string convertDelimToLatexName(string const & name) +static docstring convertDelimToLatexName(docstring const & name) { - if (name == "<") - return name; - if (name == "(") - return name; - if (name == "[") - return name; - if (name == ".") - return name; - if (name == ">") - return name; - if (name == ")") - return name; - if (name == "]") - return name; - if (name == "/") - return name; - if (name == "|") - return name; + if (name.size() == 1) { + char_type const c = name[0]; + if (c == '<' || c == '(' || c == '[' || c == '.' + || c == '>' || c == ')' || c == ']' || c == '/' || c == '|') + return name; + } return '\\' + name + ' '; } -} - - -InsetMathDelim::InsetMathDelim(string const & l, string const & r) +InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r) : InsetMathNest(1), left_(l), right_(r) {} InsetMathDelim::InsetMathDelim - (string const & l, string const & r, MathArray const & ar) + (docstring const & l, docstring const & r, MathArray const & ar) : InsetMathNest(1), left_(l), right_(r) { cell(0) = ar; @@ -148,6 +132,7 @@ void InsetMathDelim::maple(MapleStream & os) const os << left_ << cell(0) << right_; } + void InsetMathDelim::maxima(MaximaStream & os) const { if (isAbs()) { @@ -174,7 +159,7 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const } -void InsetMathDelim::mathmlize(MathMLStream & os) const +void InsetMathDelim::mathmlize(MathStream & os) const { os << "" << cell(0) << ""; diff --git a/src/mathed/InsetMathDelim.h b/src/mathed/InsetMathDelim.h index 03f8835268..cc34e54980 100644 --- a/src/mathed/InsetMathDelim.h +++ b/src/mathed/InsetMathDelim.h @@ -24,9 +24,9 @@ namespace lyx { class InsetMathDelim : public InsetMathNest { public: /// - InsetMathDelim(std::string const & left, std::string const & right); + InsetMathDelim(docstring const & left, docstring const & right); /// - InsetMathDelim(std::string const & left, std::string const & right, MathArray const &); + InsetMathDelim(docstring const & left, docstring const & right, MathArray const &); /// InsetMathDelim * asDelimInset() { return this; } /// @@ -55,13 +55,13 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; /// - std::string left_; + docstring left_; /// - std::string right_; + docstring right_; private: virtual std::auto_ptr doClone() const; /// diff --git a/src/mathed/InsetMathDiff.C b/src/mathed/InsetMathDiff.C index 837ff895ab..8b74d26b26 100644 --- a/src/mathed/InsetMathDiff.C +++ b/src/mathed/InsetMathDiff.C @@ -12,7 +12,7 @@ #include "InsetMathDiff.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "debug.h" @@ -98,7 +98,7 @@ void InsetMathDiff::mathematica(MathematicaStream & os) const } -void InsetMathDiff::mathmlize(MathMLStream & os) const +void InsetMathDiff::mathmlize(MathStream & os) const { os << "diff("; for (idx_type idx = 0; idx < nargs(); ++idx) { diff --git a/src/mathed/InsetMathDiff.h b/src/mathed/InsetMathDiff.h index f981b67ea2..3dfc0b1864 100644 --- a/src/mathed/InsetMathDiff.h +++ b/src/mathed/InsetMathDiff.h @@ -39,7 +39,7 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void maxima(MaximaStream &) const; /// diff --git a/src/mathed/InsetMathDots.C b/src/mathed/InsetMathDots.C index a967167d14..0d6c954b0f 100644 --- a/src/mathed/InsetMathDots.C +++ b/src/mathed/InsetMathDots.C @@ -12,7 +12,7 @@ #include #include "InsetMathDots.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "MathParser.h" @@ -68,7 +68,7 @@ void InsetMathDots::draw(PainterInfo & pain, int x, int y) const } -string InsetMathDots::name() const +docstring InsetMathDots::name() const { return key_->name; } diff --git a/src/mathed/InsetMathDots.h b/src/mathed/InsetMathDots.h index 5d1f6a5f4e..424a0f738a 100644 --- a/src/mathed/InsetMathDots.h +++ b/src/mathed/InsetMathDots.h @@ -29,7 +29,7 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - std::string name() const; + docstring name() const; protected: /// cache for the thing's height mutable int dh_; diff --git a/src/mathed/InsetMathEnv.C b/src/mathed/InsetMathEnv.C index 958b7565ec..e86ec67b40 100644 --- a/src/mathed/InsetMathEnv.C +++ b/src/mathed/InsetMathEnv.C @@ -12,7 +12,7 @@ #include "InsetMathEnv.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "support/std_ostream.h" @@ -24,7 +24,7 @@ using std::string; using std::auto_ptr; -InsetMathEnv::InsetMathEnv(string const & name) +InsetMathEnv::InsetMathEnv(docstring const & name) : InsetMathNest(1), name_(name) {} @@ -62,7 +62,7 @@ void InsetMathEnv::normalize(NormalStream & os) const } -void InsetMathEnv::infoize(std::ostream & os) const +void InsetMathEnv::infoize(odocstream & os) const { os << "Env: " << name_; } diff --git a/src/mathed/InsetMathEnv.h b/src/mathed/InsetMathEnv.h index a15c30e4f4..75252bb18a 100644 --- a/src/mathed/InsetMathEnv.h +++ b/src/mathed/InsetMathEnv.h @@ -24,7 +24,7 @@ namespace lyx { class InsetMathEnv : public InsetMathNest { public: /// - InsetMathEnv(std::string const & name_); + InsetMathEnv(docstring const & name_); /// void draw(PainterInfo &, int x, int y) const; /// @@ -34,12 +34,12 @@ public: /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; /// name of that environment - std::string name_; + docstring name_; }; diff --git a/src/mathed/InsetMathExFunc.C b/src/mathed/InsetMathExFunc.C index 5f6fcca641..4b9ba777cb 100644 --- a/src/mathed/InsetMathExFunc.C +++ b/src/mathed/InsetMathExFunc.C @@ -12,25 +12,24 @@ #include "InsetMathExFunc.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" namespace lyx { - -using std::string; using std::auto_ptr; using std::vector; +using std::string; -InsetMathExFunc::InsetMathExFunc(string const & name) +InsetMathExFunc::InsetMathExFunc(docstring const & name) : InsetMathNest(1), name_(name) {} -InsetMathExFunc::InsetMathExFunc(string const & name, MathArray const & ar) +InsetMathExFunc::InsetMathExFunc(docstring const & name, MathArray const & ar) : InsetMathNest(1), name_(name) { cell(0) = ar; @@ -45,20 +44,17 @@ auto_ptr InsetMathExFunc::doClone() const void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & /*dim*/) const { - // FIXME UNICODE - vector n(name_.begin(), name_.end()); - mathed_string_dim(mi.base.font, n, dim_); + mathed_string_dim(mi.base.font, name_, dim_); } void InsetMathExFunc::draw(PainterInfo & pi, int x, int y) const { - // FIXME UNICODE - drawStrBlack(pi, x, y, from_utf8(name_)); + drawStrBlack(pi, x, y, name_); } -string InsetMathExFunc::name() const +docstring InsetMathExFunc::name() const { return name_; } @@ -82,7 +78,7 @@ void InsetMathExFunc::maxima(MaximaStream & os) const } -string asMathematicaName(string const & name) +static string asMathematicaName(string const & name) { if (name == "sin") return "Sin"; if (name == "sinh") return "Sinh"; @@ -114,13 +110,19 @@ string asMathematicaName(string const & name) } +static docstring asMathematicaName(docstring const & name) +{ + return from_utf8(asMathematicaName(to_utf8(name))); +} + + void InsetMathExFunc::mathematica(MathematicaStream & os) const { os << asMathematicaName(name_) << '[' << cell(0) << ']'; } -void InsetMathExFunc::mathmlize(MathMLStream & os) const +void InsetMathExFunc::mathmlize(MathStream & os) const { os << MTag(name_.c_str()) << cell(0) << ETag(name_.c_str()); } diff --git a/src/mathed/InsetMathExFunc.h b/src/mathed/InsetMathExFunc.h index 2a12899d11..1dc39f6b8f 100644 --- a/src/mathed/InsetMathExFunc.h +++ b/src/mathed/InsetMathExFunc.h @@ -26,15 +26,15 @@ namespace lyx { class InsetMathExFunc : public InsetMathNest { public: /// - explicit InsetMathExFunc(std::string const & name); + explicit InsetMathExFunc(docstring const & name); /// - InsetMathExFunc(std::string const & name, MathArray const & ar); + InsetMathExFunc(docstring const & name, MathArray const & ar); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// - std::string name() const; + docstring name() const; /// void maple(MapleStream &) const; @@ -43,14 +43,14 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; private: virtual std::auto_ptr doClone() const; /// - std::string const name_; + docstring const name_; }; } // namespace lyx diff --git a/src/mathed/InsetMathExInt.C b/src/mathed/InsetMathExInt.C index 3563c172f9..a349946a7e 100644 --- a/src/mathed/InsetMathExInt.C +++ b/src/mathed/InsetMathExInt.C @@ -12,7 +12,7 @@ #include "InsetMathExInt.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "InsetMathSymbol.h" #include "debug.h" @@ -28,7 +28,7 @@ using std::auto_ptr; using std::endl; -InsetMathExInt::InsetMathExInt(string const & name) +InsetMathExInt::InsetMathExInt(docstring const & name) : InsetMathNest(4), symbol_(name) {} @@ -44,7 +44,7 @@ auto_ptr InsetMathExInt::doClone() const } -void InsetMathExInt::symbol(string const & symbol) +void InsetMathExInt::symbol(docstring const & symbol) { symbol_ = symbol; } @@ -128,7 +128,7 @@ void InsetMathExInt::mathematica(MathematicaStream & os) const } -void InsetMathExInt::mathmlize(MathMLStream & os) const +void InsetMathExInt::mathmlize(MathStream & os) const { boost::scoped_ptr sym(new InsetMathSymbol(symbol_)); //if (hasScripts()) diff --git a/src/mathed/InsetMathExInt.h b/src/mathed/InsetMathExInt.h index 3f1b821c72..50ea077f37 100644 --- a/src/mathed/InsetMathExInt.h +++ b/src/mathed/InsetMathExInt.h @@ -18,19 +18,16 @@ #include "InsetMathNest.h" -#include - namespace lyx { - // cell(0) is stuff before the 'd', cell(1) the stuff after class InsetMathExInt : public InsetMathNest { public: /// - explicit InsetMathExInt(std::string const & name_); + explicit InsetMathExInt(docstring const & name_); /// - void symbol(std::string const &); + void symbol(docstring const &); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -45,7 +42,7 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void write(WriteStream & os) const; private: @@ -54,10 +51,11 @@ private: bool hasScripts() const; /// - std::string symbol_; + docstring symbol_; }; } // namespace lyx + #endif diff --git a/src/mathed/InsetMathFBox.C b/src/mathed/InsetMathFBox.C index de63ba0351..7306c6ed61 100644 --- a/src/mathed/InsetMathFBox.C +++ b/src/mathed/InsetMathFBox.C @@ -12,7 +12,7 @@ #include "InsetMathFBox.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "MathStream.h" #include "LColor.h" @@ -74,7 +74,7 @@ void InsetMathFBox::normalize(NormalStream & os) const } -void InsetMathFBox::infoize(std::ostream & os) const +void InsetMathFBox::infoize(odocstream & os) const { os << "FBox: "; } diff --git a/src/mathed/InsetMathFBox.h b/src/mathed/InsetMathFBox.h index 99ceca0456..1cd2b9d17c 100644 --- a/src/mathed/InsetMathFBox.h +++ b/src/mathed/InsetMathFBox.h @@ -34,7 +34,7 @@ public: /// write normalized content void normalize(NormalStream & ns) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathFont.C b/src/mathed/InsetMathFont.C index 198778e040..7326b69817 100644 --- a/src/mathed/InsetMathFont.C +++ b/src/mathed/InsetMathFont.C @@ -12,7 +12,7 @@ #include "InsetMathFont.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "LaTeXFeatures.h" #include "support/std_ostream.h" @@ -20,7 +20,6 @@ namespace lyx { -using std::string; using std::auto_ptr; @@ -47,7 +46,7 @@ InsetMath::mode_type InsetMathFont::currentMode() const void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const { - FontSetChanger dummy(mi.base, key_->name.c_str()); + FontSetChanger dummy(mi.base, key_->name); cell(0).metrics(mi, dim); metricsMarkers(dim); dim_ = dim; @@ -75,7 +74,7 @@ void InsetMathFont::drawT(TextPainter & pain, int x, int y) const } -string InsetMathFont::name() const +docstring InsetMathFont::name() const { return key_->name; } @@ -95,7 +94,7 @@ void InsetMathFont::validate(LaTeXFeatures & features) const } -void InsetMathFont::infoize(std::ostream & os) const +void InsetMathFont::infoize(odocstream & os) const { os << "Font: " << key_->name; } diff --git a/src/mathed/InsetMathFont.h b/src/mathed/InsetMathFont.h index eec65728b4..b83910523f 100644 --- a/src/mathed/InsetMathFont.h +++ b/src/mathed/InsetMathFont.h @@ -32,7 +32,7 @@ public: /// are we in math mode, text mode, or unsure? mode_type currentMode() const; /// - std::string name() const; + docstring name() const; /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -44,7 +44,7 @@ public: /// void validate(LaTeXFeatures & features) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; diff --git a/src/mathed/InsetMathFontOld.C b/src/mathed/InsetMathFontOld.C index e2c360d44e..a78e4e77d2 100644 --- a/src/mathed/InsetMathFontOld.C +++ b/src/mathed/InsetMathFontOld.C @@ -12,7 +12,7 @@ #include "InsetMathFontOld.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "MathStream.h" #include "support/std_ostream.h" @@ -77,7 +77,7 @@ void InsetMathFontOld::normalize(NormalStream & os) const } -void InsetMathFontOld::infoize(std::ostream & os) const +void InsetMathFontOld::infoize(odocstream & os) const { os << "Font: " << key_->name; } diff --git a/src/mathed/InsetMathFontOld.h b/src/mathed/InsetMathFontOld.h index 463f1c67af..7e44e08c9f 100644 --- a/src/mathed/InsetMathFontOld.h +++ b/src/mathed/InsetMathFontOld.h @@ -42,7 +42,7 @@ public: /// void normalize(NormalStream &) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; diff --git a/src/mathed/InsetMathFrac.C b/src/mathed/InsetMathFrac.C index ea6a4a34a3..714043d573 100644 --- a/src/mathed/InsetMathFrac.C +++ b/src/mathed/InsetMathFrac.C @@ -13,7 +13,7 @@ #include "InsetMathFrac.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "TextPainter.h" #include "LaTeXFeatures.h" #include "LColor.h" @@ -137,20 +137,20 @@ void InsetMathFrac::write(WriteStream & os) const } -string InsetMathFrac::name() const +docstring InsetMathFrac::name() const { switch (kind_) { case FRAC: - return "frac"; + return from_ascii("frac"); case OVER: - return "over"; + return from_ascii("over"); case NICEFRAC: - return "nicefrac"; + return from_ascii("nicefrac"); case ATOP: - return "atop"; + return from_ascii("atop"); } // shut up stupid compiler - return string(); + return docstring(); } @@ -178,7 +178,7 @@ void InsetMathFrac::octave(OctaveStream & os) const } -void InsetMathFrac::mathmlize(MathMLStream & os) const +void InsetMathFrac::mathmlize(MathStream & os) const { os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac"); } diff --git a/src/mathed/InsetMathFrac.h b/src/mathed/InsetMathFrac.h index b7e8eab4b0..dc4ed0bf52 100644 --- a/src/mathed/InsetMathFrac.h +++ b/src/mathed/InsetMathFrac.h @@ -45,7 +45,7 @@ public: /// identifies FracInsets InsetMathFrac const * asFracInset() const; /// - std::string name() const; + docstring name() const; /// bool extraBraces() const; @@ -58,7 +58,7 @@ public: /// void octave(OctaveStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void validate(LaTeXFeatures & features) const; public: diff --git a/src/mathed/InsetMathFrameBox.C b/src/mathed/InsetMathFrameBox.C index 37f5f3c337..6636442967 100644 --- a/src/mathed/InsetMathFrameBox.C +++ b/src/mathed/InsetMathFrameBox.C @@ -12,7 +12,7 @@ #include "InsetMathFrameBox.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "LColor.h" #include "frontends/Painter.h" diff --git a/src/mathed/InsetMathGrid.C b/src/mathed/InsetMathGrid.C index 1be4830aae..7d52295604 100644 --- a/src/mathed/InsetMathGrid.C +++ b/src/mathed/InsetMathGrid.C @@ -12,7 +12,6 @@ #include "InsetMathGrid.h" #include "MathData.h" -#include "MathMLStream.h" #include "MathStream.h" #include "BufferView.h" @@ -80,9 +79,9 @@ void mathed_parse_normal(InsetMathGrid &, string const & argument); namespace { -string verboseHLine(int n) +docstring verboseHLine(int n) { - string res; + docstring res; for (int i = 0; i < n; ++i) res += "\\hline"; if (n) @@ -138,7 +137,7 @@ InsetMathGrid::ColInfo::ColInfo() ////////////////////////////////////////////////////////////// -InsetMathGrid::InsetMathGrid(char v, string const & h) +InsetMathGrid::InsetMathGrid(char v, docstring const & h) : InsetMathNest(guessColumns(h)), rowinfo_(2), colinfo_(guessColumns(h) + 1), @@ -173,7 +172,7 @@ InsetMathGrid::InsetMathGrid(col_type m, row_type n) } -InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, string const & h) +InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h) : InsetMathNest(m * n), rowinfo_(n + 1), colinfo_(m + 1), @@ -218,18 +217,18 @@ void InsetMathGrid::setDefaults() } -void InsetMathGrid::halign(string const & hh) +void InsetMathGrid::halign(docstring const & hh) { col_type col = 0; - for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) { - char c = *it; + for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) { + char_type c = *it; if (c == '|') { colinfo_[col].lines_++; } else if (col >= ncols()) { // Only '|' is allowed in the last dummy column break; } else if (c == 'c' || c == 'l' || c == 'r') { - colinfo_[col].align_ = c; + colinfo_[col].align_ = (char)c; ++col; colinfo_[col].lines_ = 0; } else { @@ -247,10 +246,10 @@ void InsetMathGrid::halign(string const & hh) } -InsetMathGrid::col_type InsetMathGrid::guessColumns(string const & hh) const +InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const { col_type col = 0; - for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) + for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) if (*it == 'c' || *it == 'l' || *it == 'r') ++col; // let's have at least one column, even if we did not recognize its @@ -273,14 +272,14 @@ char InsetMathGrid::halign(col_type col) const } -string InsetMathGrid::halign() const +docstring InsetMathGrid::halign() const { - string res; + docstring res; for (col_type col = 0; col < ncols(); ++col) { - res += string(colinfo_[col].lines_, '|'); + res += docstring(colinfo_[col].lines_, '|'); res += colinfo_[col].align_; } - return res + string(colinfo_[ncols()].lines_, '|'); + return res + docstring(colinfo_[ncols()].lines_, '|'); } @@ -608,12 +607,12 @@ void InsetMathGrid::drawT(TextPainter & pain, int x, int y) const } -string InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const +docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const { - string eol; + docstring eol; if (!rowinfo_[row].crskip_.zero()) - eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']'; + eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']'; // make sure an upcoming '[' does not break anything if (row + 1 < nrows()) { @@ -625,17 +624,17 @@ string InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) cons // only add \\ if necessary if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline)) - return string(); + return docstring(); return (fragile ? "\\protect\\\\" : "\\\\") + eol; } -string InsetMathGrid::eocString(col_type col, col_type lastcol) const +docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const { if (col + 1 == lastcol) - return string(); - return " & "; + return docstring(); + return from_ascii(" & "); } @@ -938,7 +937,7 @@ void InsetMathGrid::normalize(NormalStream & os) const } -void InsetMathGrid::mathmlize(MathMLStream & os) const +void InsetMathGrid::mathmlize(MathStream & os) const { os << MTag("mtable"); for (row_type row = 0; row < nrows(); ++row) { @@ -953,7 +952,7 @@ void InsetMathGrid::mathmlize(MathMLStream & os) const void InsetMathGrid::write(WriteStream & os) const { - string eol; + docstring eol; for (row_type row = 0; row < nrows(); ++row) { os << verboseHLine(rowinfo_[row].lines_); // don't write & and empty cells at end of line @@ -973,7 +972,7 @@ void InsetMathGrid::write(WriteStream & os) const if (!emptyline && row + 1 < nrows()) os << "\n"; } - string const s = verboseHLine(rowinfo_[nrows()].lines_); + docstring const s = verboseHLine(rowinfo_[nrows()].lines_); if (!s.empty()) { if (eol.empty()) { if (os.fragile()) diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index dce7c1e54d..f2fbcceb2e 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -33,7 +33,7 @@ public: /// a dummy cell before a multicolumn cell int dummy_; /// special multi colums alignment - std::string align_; + docstring align_; /// these should be a per-cell property, but ok to have it here /// for single-column grids like paragraphs mutable int glue_; @@ -87,11 +87,11 @@ public: /// sets nrows and ncols to 1 InsetMathGrid(); /// constructor from columns description, creates one row - InsetMathGrid(char valign, std::string const & halign); + InsetMathGrid(char valign, docstring const & halign); /// Note: columns first! InsetMathGrid(col_type m, row_type n); /// - InsetMathGrid(col_type m, row_type n, char valign, std::string const & halign); + InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign); /// Ensures that the dialog is closed. ~InsetMathGrid(); /// @@ -108,13 +108,13 @@ public: /// void drawT(TextPainter & pi, int x, int y) const; /// - void halign(std::string const & align); + void halign(docstring const & align); /// void halign(char c, col_type col); /// char halign(col_type col) const; /// - std::string halign() const; + docstring halign() const; /// void valign(char c); /// @@ -208,7 +208,7 @@ public: /// //void maple(MapleStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// //void octave(OctaveStream &) const; @@ -222,12 +222,12 @@ protected: /// returns y offset of cell compared to inset int cellYOffset(idx_type idx) const; /// returns proper 'end of line' code for LaTeX - virtual std::string eolString(row_type row, bool emptyline, + virtual docstring eolString(row_type row, bool emptyline, bool fragile) const; /// returns proper 'end of column' code for LaTeX - virtual std::string eocString(col_type col, col_type lastcol) const; + virtual docstring eocString(col_type col, col_type lastcol) const; /// extract number of columns from alignment string - col_type guessColumns(std::string const & halign) const; + col_type guessColumns(docstring const & halign) const; /// splits cells and shifts right part to the next cell void splitCell(LCursor & cur); diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index 5b7afee4fc..d57620f534 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -18,7 +18,7 @@ #include "MathExtern.h" #include "MathFactory.h" #include "InsetMathHull.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "InsetMathSpace.h" #include "MathStream.h" @@ -69,11 +69,9 @@ using support::subst; using std::endl; using std::max; -using std::string; using std::ostream; using std::auto_ptr; using std::istringstream; -using std::ostream; using std::ostringstream; using std::pair; using std::swap; @@ -119,7 +117,7 @@ namespace { } // end anon namespace -HullType hullType(std::string const & s) +HullType hullType(docstring const & s) { if (s == "none") return hullNone; if (s == "simple") return hullSimple; @@ -132,28 +130,28 @@ HullType hullType(std::string const & s) if (s == "multline") return hullMultline; if (s == "gather") return hullGather; if (s == "flalign") return hullFlAlign; - lyxerr << "unknown hull type '" << s << "'" << endl; + lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl; return HullType(-1); } -std::string hullName(HullType type) +docstring hullName(HullType type) { switch (type) { - case hullNone: return "none"; - case hullSimple: return "simple"; - case hullEquation: return "equation"; - case hullEqnArray: return "eqnarray"; - case hullAlign: return "align"; - case hullAlignAt: return "alignat"; - case hullXAlignAt: return "xalignat"; - case hullXXAlignAt: return "xxalignat"; - case hullMultline: return "multline"; - case hullGather: return "gather"; - case hullFlAlign: return "flalign"; + case hullNone: return from_ascii("none"); + case hullSimple: return from_ascii("simple"); + case hullEquation: return from_ascii("equation"); + case hullEqnArray: return from_ascii("eqnarray"); + case hullAlign: return from_ascii("align"); + case hullAlignAt: return from_ascii("alignat"); + case hullXAlignAt: return from_ascii("xalignat"); + case hullXXAlignAt: return from_ascii("xxalignat"); + case hullMultline: return from_ascii("multline"); + case hullGather: return from_ascii("gather"); + case hullFlAlign: return from_ascii("flalign"); default: lyxerr << "unknown hull type '" << type << "'" << endl; - return "none"; + return from_ascii("none"); } } @@ -268,9 +266,9 @@ int InsetMathHull::defaultColSpace(col_type col) } -char const * InsetMathHull::standardFont() const +docstring InsetMathHull::standardFont() const { - return type_ == hullNone ? "lyxnochange" : "mathnormal"; + return from_ascii(type_ == hullNone ? "lyxnochange" : "mathnormal"); } @@ -309,7 +307,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const } if (numberedType()) { - FontSetChanger dummy(mi.base, "mathbf"); + FontSetChanger dummy(mi.base, from_ascii("mathbf")); int l = 0; for (row_type row = 0; row < nrows(); ++row) l = max(l, mathed_string_width(mi.base.font, nicelabel(row))); @@ -348,7 +346,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20; for (row_type row = 0; row < nrows(); ++row) { int const yy = y + rowinfo_[row].offset_; - FontSetChanger dummy(pi.base, "mathrm"); + FontSetChanger dummy(pi.base, from_ascii("mathrm")); docstring const nl = nicelabel(row); pi.draw(xx, yy, nl); } @@ -419,14 +417,14 @@ bool InsetMathHull::notifyCursorLeaves(LCursor & cur) } -string InsetMathHull::label(row_type row) const +docstring InsetMathHull::label(row_type row) const { BOOST_ASSERT(row < nrows()); return label_[row]; } -void InsetMathHull::label(row_type row, string const & label) +void InsetMathHull::label(row_type row, docstring const & label) { //lyxerr << "setting label '" << label << "' for row " << row << endl; label_[row] = label; @@ -468,8 +466,7 @@ void InsetMathHull::getLabelList(Buffer const &, vector & labels) con { for (row_type row = 0; row < nrows(); ++row) if (!label_[row].empty() && nonum_[row] != 1) - // FIXME UNICODE - labels.push_back(from_utf8(label_[row])); + labels.push_back(label_[row]); } @@ -617,7 +614,7 @@ void InsetMathHull::addRow(row_type row) if (!rowChangeOK()) return; nonum_.insert(nonum_.begin() + row + 1, !numberedType()); - label_.insert(label_.begin() + row + 1, string()); + label_.insert(label_.begin() + row + 1, docstring()); InsetMathGrid::addRow(row); } @@ -671,7 +668,7 @@ docstring InsetMathHull::nicelabel(row_type row) const if (label_[row].empty()) return from_ascii("(#)"); // FIXME UNICODE - return from_utf8('(' + label_[row] + ')'); + return '(' + label_[row] + ')'; } @@ -824,7 +821,7 @@ void InsetMathHull::mutate(HullType newtype) allnonum = false; // set first non-empty label - string label; + docstring label; for (row_type row = 0; row < nrows(); ++row) { if (!label_[row].empty()) { label = label_[row]; @@ -896,16 +893,16 @@ void InsetMathHull::mutate(HullType newtype) } else { - lyxerr << "mutation from '" << hullName(type_) - << "' to '" << hullName(newtype) + lyxerr << "mutation from '" << to_utf8(hullName(type_)) + << "' to '" << to_utf8(hullName(newtype)) << "' not implemented" << endl; } } -string InsetMathHull::eolString(row_type row, bool emptyline, bool fragile) const +docstring InsetMathHull::eolString(row_type row, bool emptyline, bool fragile) const { - string res; + docstring res; if (numberedType()) { if (!label_[row].empty() && !nonum_[row]) res += "\\label{" + label_[row] + '}'; @@ -932,13 +929,13 @@ void InsetMathHull::normalize(NormalStream & os) const } -void InsetMathHull::mathmlize(MathMLStream & os) const +void InsetMathHull::mathmlize(MathStream & os) const { InsetMathGrid::mathmlize(os); } -void InsetMathHull::infoize(ostream & os) const +void InsetMathHull::infoize(odocstream & os) const { os << "Type: " << hullName(type_); } @@ -959,7 +956,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) iss >> dlang >> extra; if (extra.empty()) extra = from_ascii("noextra"); - string const lang = to_ascii(dlang); + std::string const lang = to_ascii(dlang); #ifdef WITH_WARNINGS #warning temporarily disabled @@ -984,7 +981,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) MathArray ar; if (cur.inMathed() && cur.selection()) { // FIXME UNICODE - asArray(from_utf8(grabAndEraseSelection(cur)), ar); + asArray(grabAndEraseSelection(cur), ar); } else if (pos == cur.cell().size()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; @@ -1092,7 +1089,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_LABEL_INSERT: { recordUndoInset(cur); row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row(); - docstring old_label = from_utf8(label(r)); + docstring old_label = label(r); docstring const default_label = from_ascii( (lyxrc.label_init_length >= 0) ? "eq:" : ""); if (old_label.empty()) @@ -1100,7 +1097,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) InsetCommandParams p("label"); p["name"] = cmd.argument().empty() ? old_label : cmd.argument(); - string const data = InsetCommandMailer::params2string("label", p); + std::string const data = InsetCommandMailer::params2string("label", p); if (cmd.argument().empty()) cur.bv().showInsetDialog("label", data, 0); @@ -1113,19 +1110,19 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_INSET_INSERT: { //lyxerr << "arg: " << to_utf8(cmd.argument()) << endl; - string const name = cmd.getArg(0); + std::string const name = cmd.getArg(0); if (name == "label") { InsetCommandParams p("label"); InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), p); - string str = to_utf8(p["name"]); + docstring str = p["name"]; recordUndoInset(cur); row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row(); str = support::trim(str); if (!str.empty()) numbered(r, true); - string old = label(r); + docstring old = label(r); if (str != old) { - cur.bv().buffer()->changeRefsIfUnique(old, str, + cur.bv().buffer()->changeRefsIfUnique(to_utf8(old), to_utf8(str), InsetBase::REF_CODE); label(r, str); } @@ -1144,7 +1141,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) recordUndoInset(cur); row_type row = cur.row(); col_type col = cur.col(); - mutate(hullType(to_utf8(cmd.argument()))); + mutate(hullType(cmd.argument())); cur.idx() = row * ncols() + col; if (cur.idx() > cur.lastidx()) { cur.idx() = cur.lastidx(); @@ -1202,7 +1199,7 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, return InsetMathGrid::getStatus(cur, cmd, status); case LFUN_TABULAR_FEATURE: { istringstream is(to_utf8(cmd.argument())); - string s; + std::string s; is >> s; if (!rowChangeOK() && (s == "append-row" @@ -1210,7 +1207,7 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, || s == "copy-row")) { status.message(bformat( from_utf8(N_("Can't change number of rows in '%1$s'")), - from_utf8(hullName(type_)))); + hullName(type_))); status.enabled(false); return true; } @@ -1220,7 +1217,7 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, || s == "copy-column")) { status.message(bformat( from_utf8(N_("Can't change number of columns in '%1$s'")), - from_utf8(hullName(type_)))); + hullName(type_))); status.enabled(false); return true; } @@ -1230,14 +1227,14 @@ bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd, (s == "add-hline-above" || s == "add-hline-below")) { status.message(bformat( from_utf8(N_("Can't add horizontal grid lines in '%1$s'")), - from_utf8(hullName(type_)))); + hullName(type_))); status.enabled(false); return true; } if (s == "add-vline-left" || s == "add-vline-right") { status.message(bformat( from_utf8(N_("Can't add vertical grid lines in '%1$s'")), - from_utf8(hullName(type_)))); + hullName(type_))); status.enabled(false); return true; } @@ -1284,14 +1281,14 @@ void InsetMathHull::mutateToText() } -void InsetMathHull::handleFont(LCursor & cur, string const & arg, - string const & font) +void InsetMathHull::handleFont(LCursor & cur, docstring const & arg, + docstring const & font) { // this whole function is a hack and won't work for incremental font // changes... recordUndo(cur); if (cur.inset().asInsetMath()->name() == font) - cur.handleFont(font); + cur.handleFont(to_utf8(font)); else { cur.handleNest(createInsetMath(font)); cur.insert(arg); @@ -1299,12 +1296,12 @@ void InsetMathHull::handleFont(LCursor & cur, string const & arg, } -void InsetMathHull::handleFont2(LCursor & cur, string const & arg) +void InsetMathHull::handleFont2(LCursor & cur, docstring const & arg) { recordUndo(cur); LyXFont font; bool b; - bv_funcs::string2font(arg, font, b); + bv_funcs::string2font(to_utf8(arg), font, b); if (font.color() != LColor::inherit) { MathAtom at = MathAtom(new InsetMathColor(true, font.color())); cur.handleNest(at, 0); @@ -1329,9 +1326,9 @@ void InsetMathHull::revealCodes(LCursor & cur) const { if (!cur.inMathed()) return; - ostringstream os; + odocstringstream os; cur.info(os); - cur.message(from_utf8(os.str())); + cur.message(os.str()); /* // write something to the minibuffer // translate to latex @@ -1455,51 +1452,51 @@ int InsetMathHull::plaintext(Buffer const &, odocstream & os, int InsetMathHull::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - MathMLStream ms(os); + MathStream ms(os); int res = 0; - string name; + docstring name; if (getType() == hullSimple) - name = "inlineequation"; + name = from_ascii("inlineequation"); else - name = "informalequation"; + name = from_ascii("informalequation"); - string bname = name; + docstring bname = name; if (!label(0).empty()) - bname += " id=\"" + sgml::cleanID(buf, runparams, label(0)) + "\""; - ms << MTag(bname.c_str()); + bname += from_ascii(" id='" + sgml::cleanID(buf, runparams, to_utf8(label(0))) + "'"); + ms << MTag(bname); odocstringstream ls; if (runparams.flavor == OutputParams::XML) { - ms << MTag("alt role=\"tex\" "); + ms << MTag(from_ascii("alt role='tex' ")); // Workaround for db2latex: db2latex always includes equations with // \ensuremath{} or \begin{display}\end{display} // so we strip LyX' math environment WriteStream wi(ls, false, false); InsetMathGrid::write(wi); - ms << subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"); - ms << ETag("alt"); - ms << MTag("math"); + ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<")); + ms << ETag(from_ascii("alt")); + ms << MTag(from_ascii("math")); InsetMathGrid::mathmlize(ms); - ms << ETag("math"); + ms << ETag(from_ascii("math")); } else { - ms << MTag("alt role=\"tex\""); + ms << MTag(from_ascii("alt role='tex'")); res = latex(buf, ls, runparams); - ms << subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"); - ms << ETag("alt"); + ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<")); + ms << ETag(from_ascii("alt")); } - ms << ""; + ms << from_ascii("\"/>"); else - ms << "\">"; + ms << from_ascii("\">"); - ms << ETag(name.c_str()); + ms << ETag(name); return ms.line() + res; } diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 4a79fe24b8..41123a4cc8 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -43,9 +43,9 @@ public: /// void drawT(TextPainter &, int x, int y) const; /// - std::string label(row_type row) const; + docstring label(row_type row) const; /// - void label(row_type row, std::string const & label); + void label(row_type row, docstring const & label); /// void numbered(row_type row, bool num); /// @@ -92,11 +92,11 @@ public: /// void write(WriteStream & os) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void normalize(NormalStream &) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void write(Buffer const &, std::ostream & os) const; @@ -131,7 +131,7 @@ protected: bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status) const; /// - std::string eolString(row_type row, bool emptyline, bool fragile) const; + docstring eolString(row_type row, bool emptyline, bool fragile) const; private: virtual std::auto_ptr doClone() const; @@ -166,7 +166,7 @@ private: /// change number of columns, split or combine columns if necessary. void changeCols(col_type); /// - char const * standardFont() const; + docstring standardFont() const; /// consistency check void check() const; /// can this change its number of rows? @@ -179,7 +179,7 @@ private: /// std::vector nonum_; /// - std::vector label_; + std::vector label_; /// boost::scoped_ptr preview_; /// @@ -207,10 +207,10 @@ public: protected: /// - void handleFont(LCursor & cur, std::string const & arg, - std::string const & font); + void handleFont(LCursor & cur, docstring const & arg, + docstring const & font); /// - void handleFont2(LCursor & cur, std::string const & arg); + void handleFont2(LCursor & cur, docstring const & arg); /// bool previewState(BufferView * bv) const; }; diff --git a/src/mathed/InsetMathKern.C b/src/mathed/InsetMathKern.C index 2d5b43bbec..b4ad79d2cc 100644 --- a/src/mathed/InsetMathKern.C +++ b/src/mathed/InsetMathKern.C @@ -11,7 +11,7 @@ #include #include "InsetMathKern.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" #include "dimension.h" @@ -32,8 +32,8 @@ InsetMathKern::InsetMathKern(LyXLength const & w) {} -InsetMathKern::InsetMathKern(string const & s) - : wid_(s) +InsetMathKern::InsetMathKern(docstring const & s) + : wid_(to_utf8(s)) {} @@ -64,13 +64,13 @@ void InsetMathKern::draw(PainterInfo &, int, int) const void InsetMathKern::write(WriteStream & os) const { - os << "\\kern" << wid_.asLatexString() << ' '; + os << "\\kern" << from_utf8(wid_.asLatexString()) << ' '; } void InsetMathKern::normalize(NormalStream & os) const { - os << "[kern " << wid_.asLatexString() << ']'; + os << "[kern " << from_utf8(wid_.asLatexString()) << ']'; } diff --git a/src/mathed/InsetMathKern.h b/src/mathed/InsetMathKern.h index 192b01e6a2..63c20d0008 100644 --- a/src/mathed/InsetMathKern.h +++ b/src/mathed/InsetMathKern.h @@ -29,7 +29,7 @@ public: /// explicit InsetMathKern(LyXLength const & wid); /// - explicit InsetMathKern(std::string const & wid); + explicit InsetMathKern(docstring const & wid); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// diff --git a/src/mathed/InsetMathLefteqn.C b/src/mathed/InsetMathLefteqn.C index 090d513a95..b75c0da0a9 100644 --- a/src/mathed/InsetMathLefteqn.C +++ b/src/mathed/InsetMathLefteqn.C @@ -51,13 +51,13 @@ void InsetMathLefteqn::draw(PainterInfo & pi, int x, int y) const } -string InsetMathLefteqn::name() const +docstring InsetMathLefteqn::name() const { - return "lefteqn"; + return from_ascii("lefteqn"); } -void InsetMathLefteqn::infoize(std::ostream & os) const +void InsetMathLefteqn::infoize(odocstream & os) const { os << "Lefteqn "; } diff --git a/src/mathed/InsetMathLefteqn.h b/src/mathed/InsetMathLefteqn.h index cda3c7030c..cf0d41495d 100644 --- a/src/mathed/InsetMathLefteqn.h +++ b/src/mathed/InsetMathLefteqn.h @@ -25,13 +25,13 @@ public: /// InsetMathLefteqn(); /// - std::string name() const; + docstring name() const; /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathLim.C b/src/mathed/InsetMathLim.C index 68c2150a98..6e30133962 100644 --- a/src/mathed/InsetMathLim.C +++ b/src/mathed/InsetMathLim.C @@ -12,7 +12,7 @@ #include "InsetMathLim.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "debug.h" @@ -74,7 +74,7 @@ void InsetMathLim::mathematica(MathematicaStream & os) const } -void InsetMathLim::mathmlize(MathMLStream & os) const +void InsetMathLim::mathmlize(MathStream & os) const { os << "lim(" << cell(0) << ',' << cell(1) << ',' << cell(2) << ')'; } diff --git a/src/mathed/InsetMathLim.h b/src/mathed/InsetMathLim.h index 631cbfe2e8..bb6edd2ebb 100644 --- a/src/mathed/InsetMathLim.h +++ b/src/mathed/InsetMathLim.h @@ -39,7 +39,7 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void write(WriteStream & os) const; private: diff --git a/src/mathed/InsetMathMacro.C b/src/mathed/InsetMathMacro.C index 17e61fb414..bb0966d8b6 100644 --- a/src/mathed/InsetMathMacro.C +++ b/src/mathed/InsetMathMacro.C @@ -14,7 +14,7 @@ #include "InsetMathMacro.h" #include "MathSupport.h" #include "MathExtern.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "buffer.h" #include "cursor.h" @@ -33,7 +33,7 @@ using std::endl; using std::vector; -MathMacro::MathMacro(string const & name, int numargs) +MathMacro::MathMacro(docstring const & name, int numargs) : InsetMathNest(numargs), name_(name) {} @@ -44,7 +44,7 @@ auto_ptr MathMacro::doClone() const } -string MathMacro::name() const +docstring MathMacro::name() const { return name_; } @@ -62,17 +62,15 @@ void MathMacro::cursorPos(BufferView const & bv, void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const { if (!MacroTable::globalMacros().has(name())) { - string t = "Unknown: " + name(); - vector n(t.begin(), t.end()); - mathed_string_dim(mi.base.font, n, dim); + mathed_string_dim(mi.base.font, "Unknown: " + name(), dim); } else if (editing(mi.base.bv)) { // FIXME UNICODE - asArray(from_utf8(MacroTable::globalMacros().get(name()).def()), tmpl_); + asArray(MacroTable::globalMacros().get(name()).def(), tmpl_); LyXFont font = mi.base.font; - augmentFont(font, "lyxtex"); + augmentFont(font, from_ascii("lyxtex")); tmpl_.metrics(mi, dim); // FIXME UNICODE - dim.wid += mathed_string_width(font, from_utf8(name())) + 10; + dim.wid += mathed_string_width(font, name()) + 10; // FIXME UNICODE int ww = mathed_string_width(font, from_ascii("#1: ")); for (idx_type i = 0; i < nargs(); ++i) { @@ -94,21 +92,18 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const { if (!MacroTable::globalMacros().has(name())) { // FIXME UNICODE - drawStrRed(pi, x, y, from_utf8("Unknown: " + name())); + drawStrRed(pi, x, y, "Unknown: " + name()); } else if (editing(pi.base.bv)) { LyXFont font = pi.base.font; - augmentFont(font, "lyxtex"); + augmentFont(font, from_ascii("lyxtex")); int h = y - dim_.ascent() + 2 + tmpl_.ascent(); - // FIXME UNICODE - docstring dn = from_utf8(name()); - pi.pain.text(x + 3, h, dn, font); - int const w = mathed_string_width(font, dn); + pi.pain.text(x + 3, h, name(), font); + int const w = mathed_string_width(font, name()); tmpl_.draw(pi, x + w + 12, h); h += tmpl_.descent(); Dimension ldim; string t = "#1: "; - vector n(t.begin(), t.end()); - mathed_string_dim(font, n, ldim); + mathed_string_dim(font, name(), ldim); for (idx_type i = 0; i < nargs(); ++i) { MathArray const & c = cell(i); h += max(c.ascent(), ldim.asc) + 5; @@ -136,7 +131,7 @@ void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const void MathMacro::validate(LaTeXFeatures & features) const { if (name() == "binom" || name() == "mathcircumflex") - features.require(name()); + features.require(to_utf8(name())); } @@ -165,7 +160,7 @@ void MathMacro::maple(MapleStream & os) const } -void MathMacro::mathmlize(MathMLStream & os) const +void MathMacro::mathmlize(MathStream & os) const { updateExpansion(); lyx::mathmlize(expanded_, os); @@ -185,13 +180,13 @@ void MathMacro::updateExpansion() const } -void MathMacro::infoize(std::ostream & os) const +void MathMacro::infoize(odocstream & os) const { os << "Macro: " << name(); } -void MathMacro::infoize2(std::ostream & os) const +void MathMacro::infoize2(odocstream & os) const { os << "Macro: " << name(); diff --git a/src/mathed/InsetMathMacro.h b/src/mathed/InsetMathMacro.h index 7b15d3b1aa..24cd74586c 100644 --- a/src/mathed/InsetMathMacro.h +++ b/src/mathed/InsetMathMacro.h @@ -26,7 +26,7 @@ namespace lyx { class MathMacro : public InsetMathNest { public: /// A macro can be built from an existing template - MathMacro(std::string const & name, int numargs); + MathMacro(docstring const & name, int numargs); /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -41,7 +41,7 @@ public: /// InsetBase * editXY(LCursor & cur, int x, int y); /// - std::string name() const; + docstring name() const; /// void setExpansion(MathArray const & exp, MathArray const & args) const; @@ -51,13 +51,13 @@ public: /// void maple(MapleStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; /// - void infoize(std::ostream &) const; + void infoize(odocstream &) const; /// - void infoize2(std::ostream &) const; + void infoize2(odocstream &) const; private: virtual std::auto_ptr doClone() const; @@ -67,7 +67,7 @@ private: void expand() const; /// name of macro - std::string name_; + docstring name_; /// the unexpanded macro defintition mutable MathArray tmpl_; /// the macro substituted with our args diff --git a/src/mathed/InsetMathMakebox.C b/src/mathed/InsetMathMakebox.C index 3cf82d27f7..068d42327a 100644 --- a/src/mathed/InsetMathMakebox.C +++ b/src/mathed/InsetMathMakebox.C @@ -12,7 +12,7 @@ #include "InsetMathMakebox.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "support/std_ostream.h" @@ -36,7 +36,7 @@ auto_ptr InsetMathMakebox::doClone() const void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const { - FontSetChanger dummy(mi.base, "textnormal"); + FontSetChanger dummy(mi.base, from_ascii("textnormal")); w_ = mathed_char_width(mi.base.font, '['); InsetMathNest::metrics(mi); dim = cell(0).dim(); @@ -50,7 +50,7 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const { - FontSetChanger dummy(pi.base, "textnormal"); + FontSetChanger dummy(pi.base, from_ascii("textnormal")); drawMarkers(pi, x, y); drawStrBlack(pi, x, y, from_ascii("[")); @@ -88,7 +88,7 @@ void InsetMathMakebox::normalize(NormalStream & os) const } -void InsetMathMakebox::infoize(std::ostream & os) const +void InsetMathMakebox::infoize(odocstream & os) const { os << "Makebox (width: " << cell(0) << " pos: " << cell(1) << ")"; diff --git a/src/mathed/InsetMathMakebox.h b/src/mathed/InsetMathMakebox.h index fc8750ff1e..859701154f 100644 --- a/src/mathed/InsetMathMakebox.h +++ b/src/mathed/InsetMathMakebox.h @@ -35,7 +35,7 @@ public: /// mode_type currentMode() const { return TEXT_MODE; } /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; /// width of '[' in current font diff --git a/src/mathed/InsetMathMatrix.C b/src/mathed/InsetMathMatrix.C index 9a1f6eca45..3908755745 100644 --- a/src/mathed/InsetMathMatrix.C +++ b/src/mathed/InsetMathMatrix.C @@ -12,7 +12,7 @@ #include "InsetMathMatrix.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" namespace lyx { @@ -91,7 +91,7 @@ void InsetMathMatrix::mathematica(MathematicaStream & os) const } -void InsetMathMatrix::mathmlize(MathMLStream & os) const +void InsetMathMatrix::mathmlize(MathStream & os) const { InsetMathGrid::mathmlize(os); } diff --git a/src/mathed/InsetMathMatrix.h b/src/mathed/InsetMathMatrix.h index 06f8adab27..d0b3c9f39d 100644 --- a/src/mathed/InsetMathMatrix.h +++ b/src/mathed/InsetMathMatrix.h @@ -25,7 +25,7 @@ public: /// explicit InsetMathMatrix(InsetMathGrid const &); /// - explicit InsetMathMatrix(std::string const & str); + explicit InsetMathMatrix(docstring const & str); /// identifies MatrixInsets InsetMathMatrix const * asMatrixInset() const { return this; } @@ -40,7 +40,7 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; private: diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index 84369277db..c1dee95a2d 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -22,7 +22,7 @@ #include "InsetMathDelim.h" #include "MathFactory.h" #include "InsetMathHull.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathMacroArgument.h" //#include "InsetMathMBox.h" #include "MathParser.h" @@ -392,14 +392,21 @@ bool InsetMathNest::notifyCursorLeaves(LCursor & /*cur*/) void InsetMathNest::handleFont - (LCursor & cur, string const & arg, string const & font) + (LCursor & cur, docstring const & arg, char const * const font) +{ + handleFont(cur, arg, from_ascii(font)); +} + + +void InsetMathNest::handleFont + (LCursor & cur, docstring const & arg, docstring const & font) { // this whole function is a hack and won't work for incremental font // changes... recordUndo(cur, Undo::ATOMIC); if (cur.inset().asInsetMath()->name() == font) - cur.handleFont(font); + cur.handleFont(to_utf8(font)); else { cur.handleNest(createInsetMath(font)); cur.insert(arg); @@ -407,12 +414,12 @@ void InsetMathNest::handleFont } -void InsetMathNest::handleFont2(LCursor & cur, string const & arg) +void InsetMathNest::handleFont2(LCursor & cur, docstring const & arg) { recordUndo(cur, Undo::ATOMIC); LyXFont font; bool b; - bv_funcs::string2font(arg, font, b); + bv_funcs::string2font(to_utf8(arg), font, b); if (font.color() != LColor::inherit) { MathAtom at = MathAtom(new InsetMathColor(true, font.color())); cur.handleNest(at, 0); @@ -435,8 +442,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) istringstream is(to_utf8(cmd.argument())); is >> n; docstring const selection = cap::getSelection(cur.buffer(), n); - // FIXME UNICODE - cur.niceInsert(to_utf8(selection)); + cur.niceInsert(selection); cur.clearSelection(); // bug 393 cur.bv().switchKeyMap(); finishUndo(); @@ -675,7 +681,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_SELF_INSERT: if (cmd.argument().size() != 1) { recordUndo(cur); - string const arg = to_utf8(cmd.argument()); + docstring const arg = cmd.argument(); if (!interpretString(cur, arg)) cur.insert(arg); break; @@ -753,60 +759,60 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) // Math fonts case LFUN_FONT_FREE_APPLY: case LFUN_FONT_FREE_UPDATE: - handleFont2(cur, to_utf8(cmd.argument())); + handleFont2(cur, cmd.argument()); break; case LFUN_FONT_BOLD: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "textbf"); + handleFont(cur, cmd.argument(), "textbf"); else - handleFont(cur, to_utf8(cmd.argument()), "mathbf"); + handleFont(cur, cmd.argument(), "mathbf"); break; case LFUN_FONT_SANS: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "textsf"); + handleFont(cur, cmd.argument(), "textsf"); else - handleFont(cur, to_utf8(cmd.argument()), "mathsf"); + handleFont(cur, cmd.argument(), "mathsf"); break; case LFUN_FONT_EMPH: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "emph"); + handleFont(cur, cmd.argument(), "emph"); else - handleFont(cur, to_utf8(cmd.argument()), "mathcal"); + handleFont(cur, cmd.argument(), "mathcal"); break; case LFUN_FONT_ROMAN: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "textrm"); + handleFont(cur, cmd.argument(), "textrm"); else - handleFont(cur, to_utf8(cmd.argument()), "mathrm"); + handleFont(cur, cmd.argument(), "mathrm"); break; case LFUN_FONT_CODE: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "texttt"); + handleFont(cur, cmd.argument(), "texttt"); else - handleFont(cur, to_utf8(cmd.argument()), "mathtt"); + handleFont(cur, cmd.argument(), "mathtt"); break; case LFUN_FONT_FRAK: - handleFont(cur, to_utf8(cmd.argument()), "mathfrak"); + handleFont(cur, cmd.argument(), "mathfrak"); break; case LFUN_FONT_ITAL: if (currentMode() == TEXT_MODE) - handleFont(cur, to_utf8(cmd.argument()), "textit"); + handleFont(cur, cmd.argument(), "textit"); else - handleFont(cur, to_utf8(cmd.argument()), "mathit"); + handleFont(cur, cmd.argument(), "mathit"); break; case LFUN_FONT_NOUN: if (currentMode() == TEXT_MODE) // FIXME: should be "noun" - handleFont(cur, to_utf8(cmd.argument()), "textsc"); + handleFont(cur, cmd.argument(), "textsc"); else - handleFont(cur, to_utf8(cmd.argument()), "mathbb"); + handleFont(cur, cmd.argument(), "mathbb"); break; //case LFUN_FONT_FREE_APPLY: - handleFont(cur, to_utf8(cmd.argument()), "textrm"); + handleFont(cur, cmd.argument(), "textrm"); break; case LFUN_FONT_DEFAULT: - handleFont(cur, to_utf8(cmd.argument()), "textnormal"); + handleFont(cur, cmd.argument(), "textnormal"); break; case LFUN_MATH_MODE: { @@ -815,10 +821,10 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) if (currentMode() == InsetBase::MATH_MODE && cmd.argument() == "on") break; cur.macroModeClose(); - string const save_selection = grabAndEraseSelection(cur); + docstring const save_selection = grabAndEraseSelection(cur); selClearOrDel(cur); //cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv()))); - cur.plainInsert(MathAtom(new InsetMathBox("mbox"))); + cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox")))); cur.posLeft(); cur.pushLeft(*cur.nextInset()); cur.niceInsert(save_selection); @@ -827,7 +833,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) cur.niceInsert(MathAtom(new InsetMathHull("simple"))); cur.message(_("create new math text environment ($...$)")); } else { - handleFont(cur, to_utf8(cmd.argument()), "textrm"); + handleFont(cur, cmd.argument(), "textrm"); cur.message(_("entered math text mode (textrm)")); } #endif @@ -845,9 +851,9 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) recordUndo(cur, Undo::ATOMIC); unsigned int m = 1; unsigned int n = 1; - string v_align; - string h_align; - istringstream is(to_utf8(cmd.argument())); + docstring v_align; + docstring h_align; + idocstringstream is(cmd.argument()); is >> m >> n >> v_align >> h_align; if (m < 1) m = 1; @@ -855,13 +861,13 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) n = 1; v_align += 'c'; cur.niceInsert( - MathAtom(new InsetMathArray("array", m, n, v_align[0], h_align))); + MathAtom(new InsetMathArray(from_ascii("array"), m, n, (char)v_align[0], h_align))); break; } case LFUN_MATH_DELIM: { - string ls; - string rs = support::split(lyx::to_utf8(cmd.argument()), ls, ' '); + docstring ls; + docstring rs = support::split(cmd.argument(), ls, ' '); // Reasonable default values if (ls.empty()) ls = '('; @@ -873,10 +879,10 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_MATH_BIGDELIM: { - string const lname = cmd.getArg(0); - string const ldelim = cmd.getArg(1); - string const rname = cmd.getArg(2); - string const rdelim = cmd.getArg(3); + docstring const lname = from_utf8(cmd.getArg(0)); + docstring const ldelim = from_utf8(cmd.getArg(1)); + docstring const rname = from_utf8(cmd.getArg(2)); + docstring const rdelim = from_utf8(cmd.getArg(3)); latexkeys const * l = in_word_set(lname); bool const have_l = l && l->inset == "big" && InsetMathBig::isBigInsetDelim(ldelim); @@ -887,7 +893,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) // or right delimiter. if (have_l || have_r) { recordUndo(cur, Undo::ATOMIC); - string const selection = grabAndEraseSelection(cur); + docstring const selection = grabAndEraseSelection(cur); selClearOrDel(cur); if (have_l) cur.insert(MathAtom(new InsetMathBig(lname, @@ -905,7 +911,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_SPACE_INSERT: case LFUN_MATH_SPACE: recordUndo(cur, Undo::ATOMIC); - cur.insert(MathAtom(new InsetMathSpace(","))); + cur.insert(MathAtom(new InsetMathSpace(from_ascii(",")))); break; case LFUN_ERT_INSERT: @@ -934,24 +940,24 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) if (cmd.argument() == "^" || cmd.argument() == "_") { interpretChar(cur, cmd.argument()[0]); } else - cur.niceInsert(to_utf8(cmd.argument())); + cur.niceInsert(cmd.argument()); break; } case LFUN_DIALOG_SHOW_NEW_INSET: { - string const & name = to_utf8(cmd.argument()); + docstring const & name = cmd.argument(); string data; if (name == "ref") { RefInset tmp(name); - data = tmp.createDialogStr(name); + data = tmp.createDialogStr(to_utf8(name)); } - cur.bv().showInsetDialog(name, data, 0); + cur.bv().showInsetDialog(to_utf8(name), data, 0); break; } case LFUN_INSET_INSERT: { MathArray ar; - if (createInsetMath_fromDialogStr(to_utf8(cmd.argument()), ar)) { + if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { recordUndo(cur); cur.insert(ar); } else @@ -1163,7 +1169,7 @@ void InsetMathNest::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) bool InsetMathNest::interpretChar(LCursor & cur, char_type c) { //lyxerr << "interpret 2: '" << c << "'" << endl; - string save_selection; + docstring save_selection; if (c == '^' || c == '_') save_selection = grabAndEraseSelection(cur); @@ -1171,7 +1177,7 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) // handle macroMode if (cur.inMacroMode()) { - string name = cur.macroName(); + docstring name = cur.macroName(); /// are we currently typing '#1' or '#2' or...? if (name == "\\#") { @@ -1183,7 +1189,7 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) } if (isalpha(c)) { - cur.activeMacro()->setName(name + to_ascii(docstring(1, c))); + cur.activeMacro()->setName(name + docstring(1, c)); return true; } @@ -1204,10 +1210,10 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) cur.niceInsert(MathAtom(new InsetMathComment)); } else if (c == '#') { BOOST_ASSERT(cur.activeMacro()); - cur.activeMacro()->setName(name + to_ascii(docstring(1, c))); + cur.activeMacro()->setName(name + docstring(1, c)); } else { cur.backspace(); - cur.niceInsert(createInsetMath(to_ascii(docstring(1, c)))); + cur.niceInsert(createInsetMath(docstring(1, c))); } return true; } @@ -1216,16 +1222,16 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) // interpretString(). latexkeys const * l = in_word_set(name.substr(1)); if (name[0] == '\\' && l && l->inset == "big") { - string delim; + docstring delim; switch (c) { case '{': - delim = "\\{"; + delim = from_ascii("\\{"); break; case '}': - delim = "\\}"; + delim = from_ascii("\\}"); break; default: - delim = to_ascii(docstring(1, c)); + delim = docstring(1, c); break; } if (InsetMathBig::isBigInsetDelim(delim)) { @@ -1272,7 +1278,7 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) if (c == '\\') { //lyxerr << "starting with macro" << endl; - cur.insert(MathAtom(new InsetMathUnknown("\\", false))); + cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), false))); return true; } @@ -1320,7 +1326,7 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%' || c == '_' || c == '^') { - cur.niceInsert(createInsetMath(to_ascii(docstring(1, c)))); + cur.niceInsert(createInsetMath(docstring(1, c))); return true; } @@ -1336,14 +1342,14 @@ bool InsetMathNest::interpretChar(LCursor & cur, char_type c) } -bool InsetMathNest::interpretString(LCursor & cur, string const & str) +bool InsetMathNest::interpretString(LCursor & cur, docstring const & str) { // Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if // possible if (!cur.empty() && cur.pos() > 0 && cur.cell()[cur.pos() - 1]->asUnknownInset()) { if (InsetMathBig::isBigInsetDelim(str)) { - string prev = asString(cur.cell()[cur.pos() - 1]); + docstring prev = asString(cur.cell()[cur.pos() - 1]); if (prev[0] == '\\') { prev = prev.substr(1); latexkeys const * l = in_word_set(prev); @@ -1359,8 +1365,8 @@ bool InsetMathNest::interpretString(LCursor & cur, string const & str) } -bool InsetMathNest::script(LCursor & cur, bool up, string const & - save_selection) +bool InsetMathNest::script(LCursor & cur, bool up, + docstring const & save_selection) { // Hack to get \^ and \_ working //lyxerr << "handling script: up: " << up << endl; diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 55ab08f0cb..a01198749a 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -107,22 +107,24 @@ protected: FuncStatus & status) const; /// void handleFont(LCursor & cur, - std::string const & arg, std::string const & font); + docstring const & arg, docstring const & font); + void handleFont(LCursor & cur, + docstring const & arg, char const * const font); /// - void handleFont2(LCursor & cur, std::string const & arg); + void handleFont2(LCursor & cur, docstring const & arg); /// interpret \p c and insert the result at the current position of /// of \p cur. Return whether the cursor should stay in the formula. bool interpretChar(LCursor & cur, char_type c); /// bool script(LCursor & cur, bool, - std::string const & save_selection = std::string()); + docstring const & save_selection = docstring()); public: /// interpret \p str and insert the result at the current position of /// \p cur if it is something known. Return whether \p cur was /// inserted. - bool interpretString(LCursor & cur, std::string const & str); + bool interpretString(LCursor & cur, docstring const & str); private: /// lfun handler diff --git a/src/mathed/InsetMathNumber.C b/src/mathed/InsetMathNumber.C index d619ebca91..9ab909cf08 100644 --- a/src/mathed/InsetMathNumber.C +++ b/src/mathed/InsetMathNumber.C @@ -11,7 +11,7 @@ #include #include "InsetMathNumber.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" @@ -22,7 +22,7 @@ using std::string; using std::auto_ptr; using std::vector; -InsetMathNumber::InsetMathNumber(string const & s) +InsetMathNumber::InsetMathNumber(docstring const & s) : str_(s) {} @@ -35,16 +35,13 @@ auto_ptr InsetMathNumber::doClone() const void InsetMathNumber::metrics(MetricsInfo & mi, Dimension & dim) const { - // FIXME UNICODE - vector n(str_.begin(), str_.end()); - mathed_string_dim(mi.base.font, n, dim); + mathed_string_dim(mi.base.font, str_, dim); } void InsetMathNumber::draw(PainterInfo & pi, int x, int y) const { - // FIXME UNICODE - pi.draw(x, y, from_utf8(str_)); + pi.draw(x, y, str_); } @@ -72,7 +69,7 @@ void InsetMathNumber::octave(OctaveStream & os) const } -void InsetMathNumber::mathmlize(MathMLStream & os) const +void InsetMathNumber::mathmlize(MathStream & os) const { os << " " << str_ << " "; } diff --git a/src/mathed/InsetMathNumber.h b/src/mathed/InsetMathNumber.h index 1580c5078c..d6ccbb0d20 100644 --- a/src/mathed/InsetMathNumber.h +++ b/src/mathed/InsetMathNumber.h @@ -24,13 +24,13 @@ namespace lyx { class InsetMathNumber : public InsetMath { public: /// - explicit InsetMathNumber(std::string const & s); + explicit InsetMathNumber(docstring const & s); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// - std::string str() const { return str_; } + docstring str() const { return str_; } /// InsetMathNumber * asNumberInset() { return this; } @@ -43,14 +43,14 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void write(WriteStream & os) const; private: virtual std::auto_ptr doClone() const; /// the number as string - std::string str_; + docstring str_; }; diff --git a/src/mathed/InsetMathOverset.C b/src/mathed/InsetMathOverset.C index a5a5b529b2..dfca03bd5e 100644 --- a/src/mathed/InsetMathOverset.C +++ b/src/mathed/InsetMathOverset.C @@ -12,7 +12,7 @@ #include "InsetMathOverset.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "cursor.h" #include "LaTeXFeatures.h" diff --git a/src/mathed/InsetMathPar.C b/src/mathed/InsetMathPar.C index fe3513ca9d..3f8be93d00 100644 --- a/src/mathed/InsetMathPar.C +++ b/src/mathed/InsetMathPar.C @@ -12,7 +12,7 @@ #include "InsetMathPar.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "support/std_ostream.h" @@ -50,7 +50,7 @@ void InsetMathPar::write(WriteStream & os) const } -void InsetMathPar::infoize(std::ostream & os) const +void InsetMathPar::infoize(odocstream & os) const { os << "Type: Paragraph "; } diff --git a/src/mathed/InsetMathPar.h b/src/mathed/InsetMathPar.h index b401e60091..6fd28850fd 100644 --- a/src/mathed/InsetMathPar.h +++ b/src/mathed/InsetMathPar.h @@ -31,7 +31,7 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void write(WriteStream & os) const; private: diff --git a/src/mathed/InsetMathPhantom.C b/src/mathed/InsetMathPhantom.C index ba5589f597..75fd7774cd 100644 --- a/src/mathed/InsetMathPhantom.C +++ b/src/mathed/InsetMathPhantom.C @@ -11,7 +11,7 @@ #include #include "InsetMathPhantom.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "LColor.h" @@ -155,7 +155,7 @@ void InsetMathPhantom::normalize(NormalStream & os) const } -void InsetMathPhantom::infoize(std::ostream & os) const +void InsetMathPhantom::infoize(odocstream & os) const { switch (kind_) { case phantom: diff --git a/src/mathed/InsetMathPhantom.h b/src/mathed/InsetMathPhantom.h index e1fbf50e88..dfb7b60f7c 100644 --- a/src/mathed/InsetMathPhantom.h +++ b/src/mathed/InsetMathPhantom.h @@ -36,7 +36,7 @@ public: /// write normalized content void normalize(NormalStream & ns) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: /// virtual std::auto_ptr doClone() const; diff --git a/src/mathed/InsetMathRef.C b/src/mathed/InsetMathRef.C index f709b9bd10..67635a3134 100644 --- a/src/mathed/InsetMathRef.C +++ b/src/mathed/InsetMathRef.C @@ -35,11 +35,11 @@ using std::endl; RefInset::RefInset() - : CommandInset("ref") + : CommandInset(from_ascii("ref")) {} -RefInset::RefInset(string const & data) +RefInset::RefInset(docstring const & data) : CommandInset(data) {} @@ -50,7 +50,7 @@ auto_ptr RefInset::doClone() const } -void RefInset::infoize(std::ostream & os) const +void RefInset::infoize(odocstream & os) const { os << "Ref: " << cell(0); } @@ -62,7 +62,7 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "ref") { MathArray ar; - if (createInsetMath_fromDialogStr(to_utf8(cmd.argument()), ar)) { + if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { *this = *ar[0].nucleus()->asRefInset(); break; } @@ -78,7 +78,7 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3) { - lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl; + lyxerr << "trying to goto ref '" << to_utf8(asString(cell(0))) << "'" << endl; cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0)))); break; } @@ -124,13 +124,13 @@ bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd, docstring const RefInset::screenLabel() const { docstring str; - for (int i = 0; !types[i].latex_name.empty(); ++i) + for (int i = 0; !types[i].latex_name.empty(); ++i) { if (commandname() == types[i].latex_name) { - str = _(types[i].short_gui_name); + str = _(to_utf8(types[i].short_gui_name)); break; } - // FIXME UNICODE - str += from_utf8(asString(cell(0))); + } + str += asString(cell(0)); //if (/* !isLatex && */ !cell(0).empty()) { // str += "||"; @@ -152,7 +152,7 @@ void RefInset::validate(LaTeXFeatures & features) const int RefInset::plaintext(odocstream & os, OutputParams const &) const { // FIXME UNICODE - os << '[' << from_utf8(asString(cell(0))) << ']'; + os << '[' << asString(cell(0)) << ']'; return 0; } @@ -162,7 +162,7 @@ int RefInset::docbook(Buffer const & buf, odocstream & os, OutputParams const & if (cell(1).empty()) { // FIXME UNICODE os << ""; else @@ -170,10 +170,10 @@ int RefInset::docbook(Buffer const & buf, odocstream & os, OutputParams const & } else { // FIXME UNICODE os << "" - << from_ascii(asString(cell(1))) - << ""; + << asString(cell(1)) + << ""; } return 0; @@ -181,13 +181,13 @@ int RefInset::docbook(Buffer const & buf, odocstream & os, OutputParams const & RefInset::ref_type_info RefInset::types[] = { - { "ref", N_("Standard"), N_("Ref: ")}, - { "eqref", N_("Equation"), N_("EqRef: ")}, - { "pageref", N_("Page Number"), N_("Page: ")}, - { "vpageref", N_("Textual Page Number"), N_("TextPage: ")}, - { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")}, - { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")}, - { "", "", "" } + { from_ascii("ref"), from_ascii(N_("Standard")), from_ascii(N_("Ref: "))}, + { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))}, + { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))}, + { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))}, + { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))}, + { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("PrettyRef: "))}, + { from_ascii(""), from_ascii(""), from_ascii("") } }; diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h index c70158252f..b0338f7f21 100644 --- a/src/mathed/InsetMathRef.h +++ b/src/mathed/InsetMathRef.h @@ -25,11 +25,11 @@ public: /// RefInset(); /// - explicit RefInset(std::string const & data); + explicit RefInset(docstring const & data); /// //void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// docstring const screenLabel() const; /// @@ -44,17 +44,17 @@ public: struct ref_type_info { /// - std::string latex_name; + docstring latex_name; /// - std::string gui_name; + docstring gui_name; /// - std::string short_gui_name; + docstring short_gui_name; }; static ref_type_info types[]; /// - static int getType(std::string const & name); + static int getType(docstring const & name); /// - static std::string const & getName(int type); + static docstring const & getName(int type); protected: /// virtual void doDispatch(LCursor & cur, FuncRequest & cmd); diff --git a/src/mathed/InsetMathRoot.C b/src/mathed/InsetMathRoot.C index 45ff2a3c8b..11a9221505 100644 --- a/src/mathed/InsetMathRoot.C +++ b/src/mathed/InsetMathRoot.C @@ -13,7 +13,7 @@ #include "InsetMathRoot.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "cursor.h" #include "LColor.h" @@ -106,7 +106,7 @@ void InsetMathRoot::octave(OctaveStream & os) const } -void InsetMathRoot::mathmlize(MathMLStream & os) const +void InsetMathRoot::mathmlize(MathStream & os) const { os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot"); } diff --git a/src/mathed/InsetMathRoot.h b/src/mathed/InsetMathRoot.h index 6b42504857..ac69d1d933 100644 --- a/src/mathed/InsetMathRoot.h +++ b/src/mathed/InsetMathRoot.h @@ -36,7 +36,7 @@ public: /// void normalize(NormalStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void maple(MapleStream &) const; /// diff --git a/src/mathed/InsetMathScript.C b/src/mathed/InsetMathScript.C index d8b69297de..d6a8eda75a 100644 --- a/src/mathed/InsetMathScript.C +++ b/src/mathed/InsetMathScript.C @@ -12,7 +12,7 @@ #include "InsetMathScript.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "InsetMathSymbol.h" #include "dispatchresult.h" @@ -298,10 +298,10 @@ bool InsetMathScript::hasLimits() const if (nuc().back()->asSymbolInset()) { // \intop is an alias for \int\limits, \ointop == \oint\limits - if (nuc().back()->asSymbolInset()->name().find("intop") != string::npos) + if (nuc().back()->asSymbolInset()->name().find(from_ascii("intop")) != string::npos) return true; // per default \int has limits beside the \int even in displayed formulas - if (nuc().back()->asSymbolInset()->name().find("int") != string::npos) + if (nuc().back()->asSymbolInset()->name().find(from_ascii("int")) != string::npos) return false; } @@ -510,7 +510,7 @@ void InsetMathScript::mathematica(MathematicaStream & os) const } -void InsetMathScript::mathmlize(MathMLStream & os) const +void InsetMathScript::mathmlize(MathStream & os) const { bool d = hasDown() && down().size(); bool u = hasUp() && up().size(); @@ -547,13 +547,13 @@ void InsetMathScript::octave(OctaveStream & os) const } -void InsetMathScript::infoize(std::ostream & os) const +void InsetMathScript::infoize(odocstream & os) const { os << "Scripts"; } -void InsetMathScript::infoize2(std::ostream & os) const +void InsetMathScript::infoize2(odocstream & os) const { if (limits_) os << (limits_ == 1 ? ", Displayed limits" : ", Inlined limits"); diff --git a/src/mathed/InsetMathScript.h b/src/mathed/InsetMathScript.h index 067241773e..adffa97ff7 100644 --- a/src/mathed/InsetMathScript.h +++ b/src/mathed/InsetMathScript.h @@ -61,7 +61,7 @@ public: /// write content as something readable by Mathematica void mathematica(MathematicaStream &) const; /// write content as something resembling MathML - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// write content as something readable by Octave void octave(OctaveStream &) const; @@ -99,9 +99,9 @@ public: /// make sure a script is accessible void ensure(bool up); /// say that we have scripts - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// say whether we have displayed limits - void infoize2(std::ostream & os) const; + void infoize2(odocstream & os) const; protected: virtual void doDispatch(LCursor & cur, FuncRequest & cmd); private: diff --git a/src/mathed/InsetMathSize.C b/src/mathed/InsetMathSize.C index 319244f559..562aa0cd65 100644 --- a/src/mathed/InsetMathSize.C +++ b/src/mathed/InsetMathSize.C @@ -12,7 +12,7 @@ #include "InsetMathSize.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "MathStream.h" @@ -65,7 +65,7 @@ void InsetMathSize::normalize(NormalStream & os) const } -void InsetMathSize::infoize(std::ostream & os) const +void InsetMathSize::infoize(odocstream & os) const { os << "Size: " << key_->name; } diff --git a/src/mathed/InsetMathSize.h b/src/mathed/InsetMathSize.h index d70dea1b2a..5a9767af03 100644 --- a/src/mathed/InsetMathSize.h +++ b/src/mathed/InsetMathSize.h @@ -38,7 +38,7 @@ public: /// void normalize(NormalStream &) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; private: virtual std::auto_ptr doClone() const; /// diff --git a/src/mathed/InsetMathSpace.C b/src/mathed/InsetMathSpace.C index 36b392e4a2..fd0f56997f 100644 --- a/src/mathed/InsetMathSpace.C +++ b/src/mathed/InsetMathSpace.C @@ -12,7 +12,7 @@ #include "InsetMathSpace.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "LaTeXFeatures.h" #include "LColor.h" @@ -40,7 +40,7 @@ InsetMathSpace::InsetMathSpace(int sp) {} -InsetMathSpace::InsetMathSpace(string const & name) +InsetMathSpace::InsetMathSpace(docstring const & name) : space_(1) { for (int i = 0; i < nSpace; ++i) diff --git a/src/mathed/InsetMathSpace.h b/src/mathed/InsetMathSpace.h index e1a8ac4e9d..a3e06d634e 100644 --- a/src/mathed/InsetMathSpace.h +++ b/src/mathed/InsetMathSpace.h @@ -24,7 +24,7 @@ public: /// explicit InsetMathSpace(int sp); /// - explicit InsetMathSpace(std::string const & name); + explicit InsetMathSpace(docstring const & name); /// InsetMathSpace const * asSpaceInset() const { return this; } /// diff --git a/src/mathed/InsetMathSplit.C b/src/mathed/InsetMathSplit.C index 6ebab552a3..00dd9e87ee 100644 --- a/src/mathed/InsetMathSplit.C +++ b/src/mathed/InsetMathSplit.C @@ -12,7 +12,7 @@ #include "InsetMathSplit.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "funcrequest.h" @@ -32,8 +32,8 @@ using std::string; using std::auto_ptr; -InsetMathSplit::InsetMathSplit(string const & name, char valign) - : InsetMathGrid(1, 1, valign, string()), name_(name) +InsetMathSplit::InsetMathSplit(docstring const & name, char valign) + : InsetMathGrid(1, 1, valign, docstring()), name_(name) { } @@ -73,8 +73,7 @@ bool InsetMathSplit::getStatus(LCursor & cur, FuncRequest const & cmd, docstring const & s = cmd.argument(); if (s == "add-vline-left" || s == "add-vline-right") { flag.message(bformat( - from_utf8(N_("Can't add vertical grid lines in '%1$s'")), - from_utf8(name_))); + from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_)); flag.enabled(false); return true; } @@ -102,9 +101,9 @@ void InsetMathSplit::write(WriteStream & ws) const } -void InsetMathSplit::infoize(std::ostream & os) const +void InsetMathSplit::infoize(odocstream & os) const { - string name = name_; + docstring name = name_; name[0] = support::uppercase(name[0]); os << name << ' '; } diff --git a/src/mathed/InsetMathSplit.h b/src/mathed/InsetMathSplit.h index 213bea6bcc..06d17c47ce 100644 --- a/src/mathed/InsetMathSplit.h +++ b/src/mathed/InsetMathSplit.h @@ -21,18 +21,16 @@ namespace lyx { class InsetMathSplit : public InsetMathGrid { public: /// - explicit InsetMathSplit(std::string const & name, char valign = 'c'); - + explicit InsetMathSplit(docstring const & name, char valign = 'c'); /// void draw(PainterInfo & pi, int x, int y) const; - /// bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & flag) const; void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void validate(LaTeXFeatures & features) const; /// @@ -40,12 +38,12 @@ public: /// char defaultColAlign(col_type); private: + /// virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; }; - } // namespace lyx #endif diff --git a/src/mathed/InsetMathSqrt.C b/src/mathed/InsetMathSqrt.C index eb54174a94..82edc46126 100644 --- a/src/mathed/InsetMathSqrt.C +++ b/src/mathed/InsetMathSqrt.C @@ -12,7 +12,7 @@ #include "InsetMathSqrt.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "TextPainter.h" #include "LColor.h" #include "frontends/Painter.h" @@ -106,7 +106,7 @@ void InsetMathSqrt::octave(OctaveStream & os) const } -void InsetMathSqrt::mathmlize(MathMLStream & os) const +void InsetMathSqrt::mathmlize(MathStream & os) const { os << MTag("msqrt") << cell(0) << ETag("msqrt"); } diff --git a/src/mathed/InsetMathSqrt.h b/src/mathed/InsetMathSqrt.h index f3c9db0d16..8e19b367d8 100644 --- a/src/mathed/InsetMathSqrt.h +++ b/src/mathed/InsetMathSqrt.h @@ -44,7 +44,7 @@ public: /// void octave(OctaveStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; private: virtual std::auto_ptr doClone() const; }; diff --git a/src/mathed/InsetMathStackrel.C b/src/mathed/InsetMathStackrel.C index c88fda9b57..197d78df60 100644 --- a/src/mathed/InsetMathStackrel.C +++ b/src/mathed/InsetMathStackrel.C @@ -12,7 +12,7 @@ #include "InsetMathStackrel.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" namespace lyx { diff --git a/src/mathed/InsetMathString.C b/src/mathed/InsetMathString.C index 17df1a8200..78637265d7 100644 --- a/src/mathed/InsetMathString.C +++ b/src/mathed/InsetMathString.C @@ -11,19 +11,18 @@ #include #include "InsetMathString.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" namespace lyx { -using std::string; using std::auto_ptr; using std::vector; -InsetMathString::InsetMathString(string const & s) +InsetMathString::InsetMathString(docstring const & s) : str_(s) {} @@ -36,18 +35,13 @@ auto_ptr InsetMathString::doClone() const void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const { - // FIXME UNICODE - vector n(str_.begin(), str_.end()); - mathed_string_dim(mi.base.font, n, dim); + mathed_string_dim(mi.base.font, str_, dim); } void InsetMathString::draw(PainterInfo & pi, int x, int y) const { - //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl; - // FIXME UNICODE - docstring dstr = from_utf8(str_); - pi.draw(x, y, dstr); + pi.draw(x, y, str_); } @@ -66,7 +60,7 @@ void InsetMathString::maple(MapleStream & os) const // insert '*' between adjacent chars if type is LM_TC_VAR os << str_[0]; - for (string::size_type i = 1; i < str_.size(); ++i) + for (size_t i = 1; i < str_.size(); ++i) os << str_[i]; } @@ -86,12 +80,12 @@ void InsetMathString::octave(OctaveStream & os) const // insert '*' between adjacent chars if type is LM_TC_VAR os << str_[0]; - for (string::size_type i = 1; i < str_.size(); ++i) + for (size_t i = 1; i < str_.size(); ++i) os << str_[i]; } -void InsetMathString::mathmlize(MathMLStream & os) const +void InsetMathString::mathmlize(MathStream & os) const { /* if (code_ == LM_TC_VAR) diff --git a/src/mathed/InsetMathString.h b/src/mathed/InsetMathString.h index 6e8f41bcfd..f0803a8e2b 100644 --- a/src/mathed/InsetMathString.h +++ b/src/mathed/InsetMathString.h @@ -17,7 +17,6 @@ namespace lyx { - /** Some collection of chars with similar properties * mainly for math-extern */ @@ -25,13 +24,13 @@ namespace lyx { class InsetMathString : public InsetMath { public: /// - explicit InsetMathString(std::string const & s); + explicit InsetMathString(docstring const & s); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// - std::string str() const { return str_; } + docstring str() const { return str_; } /// InsetMathString * asStringInset() { return this; } /// @@ -46,16 +45,16 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void write(WriteStream & os) const; private: virtual std::auto_ptr doClone() const; /// the string - std::string str_; + docstring str_; }; - } // namespace lyx + #endif diff --git a/src/mathed/InsetMathSubstack.C b/src/mathed/InsetMathSubstack.C index d12d1cc807..c89bbc143d 100644 --- a/src/mathed/InsetMathSubstack.C +++ b/src/mathed/InsetMathSubstack.C @@ -13,7 +13,7 @@ #include "LaTeXFeatures.h" #include "InsetMathSubstack.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "support/std_ostream.h" #include "funcrequest.h" @@ -81,7 +81,7 @@ bool InsetMathSubstack::getStatus(LCursor & cur, FuncRequest const & cmd, } -void InsetMathSubstack::infoize(std::ostream & os) const +void InsetMathSubstack::infoize(odocstream & os) const { os << "Substack "; } diff --git a/src/mathed/InsetMathSubstack.h b/src/mathed/InsetMathSubstack.h index a82ecd1ecd..c184dc4a97 100644 --- a/src/mathed/InsetMathSubstack.h +++ b/src/mathed/InsetMathSubstack.h @@ -35,7 +35,7 @@ public: bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & flag) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void write(WriteStream & os) const; /// diff --git a/src/mathed/InsetMathSymbol.C b/src/mathed/InsetMathSymbol.C index 7cd0e222b1..1733b45879 100644 --- a/src/mathed/InsetMathSymbol.C +++ b/src/mathed/InsetMathSymbol.C @@ -12,7 +12,7 @@ #include "InsetMathSymbol.h" #include "dimension.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" #include "MathParser.h" @@ -33,12 +33,12 @@ InsetMathSymbol::InsetMathSymbol(latexkeys const * l) InsetMathSymbol::InsetMathSymbol(char const * name) - : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false) + : sym_(in_word_set(from_ascii(name))), h_(0), width_(0), scriptable_(false) {} -InsetMathSymbol::InsetMathSymbol(string const & name) - : sym_(in_word_set(name.c_str())), h_(0), width_(0), scriptable_(false) +InsetMathSymbol::InsetMathSymbol(docstring const & name) + : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false) {} @@ -48,7 +48,7 @@ auto_ptr InsetMathSymbol::doClone() const } -string InsetMathSymbol::name() const +docstring InsetMathSymbol::name() const { return sym_->name; } @@ -62,8 +62,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const // << "'" << std::endl; int const em = mathed_char_width(mi.base.font, 'M'); - FontSetChanger dummy(mi.base, sym_->inset.c_str()); - // FIXME UNICODE + FontSetChanger dummy(mi.base, sym_->inset); mathed_string_dim(mi.base.font, sym_->draw, dim); // correct height for broken cmex and wasy font #if defined(__APPLE__) && defined(__GNUC__) @@ -142,7 +141,7 @@ bool InsetMathSymbol::takesLimits() const void InsetMathSymbol::validate(LaTeXFeatures & features) const { if (!sym_->requires.empty()) - features.require(sym_->requires); + features.require(to_utf8(sym_->requires)); } @@ -184,7 +183,7 @@ void InsetMathSymbol::mathematica(MathematicaStream & os) const } -char const * MathMLtype(string const & s) +char const * MathMLtype(docstring const & s) { if (s == "mathop") return "mo"; @@ -192,7 +191,7 @@ char const * MathMLtype(string const & s) } -void InsetMathSymbol::mathmlize(MathMLStream & os) const +void InsetMathSymbol::mathmlize(MathStream & os) const { char const * type = MathMLtype(sym_->extra); os << '<' << type << "> "; @@ -220,7 +219,7 @@ void InsetMathSymbol::write(WriteStream & os) const } -void InsetMathSymbol::infoize2(std::ostream & os) const +void InsetMathSymbol::infoize2(odocstream & os) const { os << "Symbol: " << name(); } diff --git a/src/mathed/InsetMathSymbol.h b/src/mathed/InsetMathSymbol.h index 3c13afe24c..1231983ae7 100644 --- a/src/mathed/InsetMathSymbol.h +++ b/src/mathed/InsetMathSymbol.h @@ -30,7 +30,7 @@ public: /// explicit InsetMathSymbol(char const * name); /// - explicit InsetMathSymbol(std::string const & name); + explicit InsetMathSymbol(docstring const & name); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -47,7 +47,7 @@ public: /// identifies SymbolInset as such InsetMathSymbol const * asSymbolInset() const { return this; } /// the LaTeX name of the symbol (without the backslash) - std::string name() const; + docstring name() const; /// request "external features" void validate(LaTeXFeatures & features) const; @@ -60,13 +60,13 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; /// void write(WriteStream & os) const; /// - void infoize2(std::ostream & os) const; + void infoize2(odocstream & os) const; private: virtual std::auto_ptr doClone() const; @@ -80,6 +80,6 @@ private: mutable bool scriptable_; }; - } // namespace lyx + #endif diff --git a/src/mathed/InsetMathTFrac.C b/src/mathed/InsetMathTFrac.C index cd6e741044..102c061e2c 100644 --- a/src/mathed/InsetMathTFrac.C +++ b/src/mathed/InsetMathTFrac.C @@ -13,7 +13,7 @@ #include "InsetMathTFrac.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "LaTeXFeatures.h" #include "LColor.h" @@ -63,13 +63,13 @@ void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const } -string InsetMathTFrac::name() const +docstring InsetMathTFrac::name() const { - return "tfrac"; + return from_ascii("tfrac"); } -void InsetMathTFrac::mathmlize(MathMLStream & os) const +void InsetMathTFrac::mathmlize(MathStream & os) const { os << MTag("mtfrac") << cell(0) << cell(1) << ETag("mtfrac"); } diff --git a/src/mathed/InsetMathTFrac.h b/src/mathed/InsetMathTFrac.h index 38e8409498..045a3e35fb 100644 --- a/src/mathed/InsetMathTFrac.h +++ b/src/mathed/InsetMathTFrac.h @@ -28,9 +28,9 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - std::string name() const; + docstring name() const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void validate(LaTeXFeatures & features) const; private: diff --git a/src/mathed/InsetMathTabular.C b/src/mathed/InsetMathTabular.C index e0c5689241..663559d79b 100644 --- a/src/mathed/InsetMathTabular.C +++ b/src/mathed/InsetMathTabular.C @@ -12,7 +12,7 @@ #include "InsetMathTabular.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "support/lstrings.h" @@ -28,19 +28,19 @@ using std::string; using std::auto_ptr; -InsetMathTabular::InsetMathTabular(string const & name, int m, int n) +InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n) : InsetMathGrid(m, n), name_(name) {} -InsetMathTabular::InsetMathTabular(string const & name, int m, int n, - char valign, string const & halign) +InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n, + char valign, docstring const & halign) : InsetMathGrid(m, n, valign, halign), name_(name) {} -InsetMathTabular::InsetMathTabular(string const & name, char valign, - string const & halign) +InsetMathTabular::InsetMathTabular(docstring const & name, char valign, + docstring const & halign) : InsetMathGrid(valign, halign), name_(name) {} @@ -87,9 +87,9 @@ void InsetMathTabular::write(WriteStream & os) const } -void InsetMathTabular::infoize(std::ostream & os) const +void InsetMathTabular::infoize(odocstream & os) const { - string name = name_; + docstring name = name_; name[0] = support::uppercase(name[0]); os << name << ' '; } diff --git a/src/mathed/InsetMathTabular.h b/src/mathed/InsetMathTabular.h index 56486e9c7b..13b4960e50 100644 --- a/src/mathed/InsetMathTabular.h +++ b/src/mathed/InsetMathTabular.h @@ -22,12 +22,12 @@ namespace lyx { class InsetMathTabular : public InsetMathGrid { public: /// - InsetMathTabular(std::string const &, int m, int n); + InsetMathTabular(docstring const &, int m, int n); /// - InsetMathTabular(std::string const &, int m, int n, - char valign, std::string const & halign); + InsetMathTabular(docstring const &, int m, int n, + char valign, docstring const & halign); /// - InsetMathTabular(std::string const &, char valign, std::string const & halign); + InsetMathTabular(docstring const &, char valign, docstring const & halign); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// @@ -40,7 +40,7 @@ public: /// void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void normalize(NormalStream &) const; /// @@ -49,10 +49,9 @@ public: private: virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; }; - - } // namespace lyx + #endif diff --git a/src/mathed/InsetMathUnderset.C b/src/mathed/InsetMathUnderset.C index 3a4913b822..6218b6e72c 100644 --- a/src/mathed/InsetMathUnderset.C +++ b/src/mathed/InsetMathUnderset.C @@ -12,7 +12,7 @@ #include "InsetMathUnderset.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "cursor.h" #include "LaTeXFeatures.h" diff --git a/src/mathed/InsetMathUnknown.C b/src/mathed/InsetMathUnknown.C index 55ed11ae27..007989b2bc 100644 --- a/src/mathed/InsetMathUnknown.C +++ b/src/mathed/InsetMathUnknown.C @@ -13,7 +13,7 @@ #include "InsetMathUnknown.h" #include "MathSupport.h" #include "MathAtom.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" @@ -24,7 +24,7 @@ using std::auto_ptr; using std::vector; -InsetMathUnknown::InsetMathUnknown(string const & nm, bool final, bool black) +InsetMathUnknown::InsetMathUnknown(docstring const & nm, bool final, bool black) : name_(nm), final_(final), black_(black) {} @@ -35,13 +35,13 @@ auto_ptr InsetMathUnknown::doClone() const } -string InsetMathUnknown::name() const +docstring InsetMathUnknown::name() const { return name_; } -void InsetMathUnknown::setName(string const & name) +void InsetMathUnknown::setName(docstring const & name) { name_ = name; } @@ -55,20 +55,17 @@ void InsetMathUnknown::normalize(NormalStream & os) const void InsetMathUnknown::metrics(MetricsInfo & mi, Dimension & dim) const { - // FIXME UNICODE - vector n(name_.begin(), name_.end()); - mathed_string_dim(mi.base.font, n, dim); + mathed_string_dim(mi.base.font, name_, dim); dim_ = dim; } void InsetMathUnknown::draw(PainterInfo & pi, int x, int y) const { - // FIXME UNICODE if (black_) - drawStrBlack(pi, x, y, from_utf8(name_)); + drawStrBlack(pi, x, y, name_); else - drawStrRed(pi, x, y, from_utf8(name_)); + drawStrRed(pi, x, y, name_); setPosCache(pi, x, y); } @@ -97,7 +94,7 @@ void InsetMathUnknown::mathematica(MathematicaStream & os) const } -void InsetMathUnknown::mathmlize(MathMLStream & os) const +void InsetMathUnknown::mathmlize(MathStream & os) const { os << MTag("mi") << name_ << ETag("mi"); } diff --git a/src/mathed/InsetMathUnknown.h b/src/mathed/InsetMathUnknown.h index 106fae98ea..7872e73b36 100644 --- a/src/mathed/InsetMathUnknown.h +++ b/src/mathed/InsetMathUnknown.h @@ -22,16 +22,16 @@ namespace lyx { class InsetMathUnknown : public InsetMathDim { public: /// - explicit InsetMathUnknown(std::string const & name, + explicit InsetMathUnknown(docstring const & name, bool final = true, bool black = false); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// - void setName(std::string const & name); + void setName(docstring const & name); /// - std::string name() const; + docstring name() const; /// identifies UnknownInsets InsetMathUnknown const * asUnknownInset() const { return this; } /// identifies UnknownInsets @@ -44,7 +44,7 @@ public: /// void mathematica(MathematicaStream &) const; /// - void mathmlize(MathMLStream &) const; + void mathmlize(MathStream &) const; /// void octave(OctaveStream &) const; /// @@ -54,7 +54,7 @@ public: private: virtual std::auto_ptr doClone() const; /// - std::string name_; + docstring name_; /// are we finished creating the name? bool final_; /// diff --git a/src/mathed/InsetMathXArrow.C b/src/mathed/InsetMathXArrow.C index 0b2ebc3188..a6ff4e626a 100644 --- a/src/mathed/InsetMathXArrow.C +++ b/src/mathed/InsetMathXArrow.C @@ -12,7 +12,7 @@ #include "InsetMathXArrow.h" #include "MathData.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "MathSupport.h" @@ -25,7 +25,7 @@ using std::string; using std::auto_ptr; -InsetMathXArrow::InsetMathXArrow(string const & name) +InsetMathXArrow::InsetMathXArrow(docstring const & name) : InsetMathFracBase(), name_(name) {} diff --git a/src/mathed/InsetMathXArrow.h b/src/mathed/InsetMathXArrow.h index 59794c3f6a..05bc2740bb 100644 --- a/src/mathed/InsetMathXArrow.h +++ b/src/mathed/InsetMathXArrow.h @@ -22,7 +22,7 @@ namespace lyx { class InsetMathXArrow : public InsetMathFracBase { public: /// - explicit InsetMathXArrow(std::string const & name); + explicit InsetMathXArrow(docstring const & name); /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -39,7 +39,7 @@ private: /// bool upper() const; /// - std::string const name_; + docstring const name_; }; diff --git a/src/mathed/InsetMathXYMatrix.C b/src/mathed/InsetMathXYMatrix.C index 0e39a8fbc9..03dd13b654 100644 --- a/src/mathed/InsetMathXYMatrix.C +++ b/src/mathed/InsetMathXYMatrix.C @@ -11,7 +11,7 @@ #include #include "InsetMathXYMatrix.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathStream.h" #include "LaTeXFeatures.h" @@ -60,7 +60,7 @@ void InsetMathXYMatrix::write(WriteStream & os) const } -void InsetMathXYMatrix::infoize(std::ostream & os) const +void InsetMathXYMatrix::infoize(odocstream & os) const { os << "xymatrix "; InsetMathGrid::infoize(os); diff --git a/src/mathed/InsetMathXYMatrix.h b/src/mathed/InsetMathXYMatrix.h index e9be79c81d..3dfcd9b4ab 100644 --- a/src/mathed/InsetMathXYMatrix.h +++ b/src/mathed/InsetMathXYMatrix.h @@ -37,7 +37,7 @@ public: /// void write(WriteStream & os) const; /// - void infoize(std::ostream & os) const; + void infoize(odocstream & os) const; /// void normalize(NormalStream &) const; /// diff --git a/src/mathed/MathAutoCorrect.C b/src/mathed/MathAutoCorrect.C index 6925086f26..9d419cd12b 100644 --- a/src/mathed/MathAutoCorrect.C +++ b/src/mathed/MathAutoCorrect.C @@ -42,24 +42,24 @@ public: /// Correction() {} /// - bool correct(MathAtom & at, char c) const; + bool correct(MathAtom & at, char_type c) const; /// - bool read(istream & is); + bool read(idocstream & is); /// - void write(ostream & os) const; + void write(odocstream & os) const; private: /// MathAtom from1_; /// - char from2_; + char_type from2_; /// MathAtom to_; }; -bool Correction::read(istream & is) +bool Correction::read(idocstream & is) { - string s1, s2, s3; + docstring s1, s2, s3; is >> s1 >> s2 >> s3; if (!is) return false; @@ -77,14 +77,14 @@ bool Correction::read(istream & is) } -void Correction::write(ostream & os) const +void Correction::write(odocstream & os) const { os << "from: '" << from1_ << "' and '" << from2_ << "' to '" << to_ << '\'' << endl; } -bool Correction::correct(MathAtom & at, char c) const +bool Correction::correct(MathAtom & at, char_type c) const { //lyxerr[Debug::MATHED] // << "trying to correct ar: " << at << " from: '" << from1_ << '\'' << endl; @@ -100,14 +100,14 @@ bool Correction::correct(MathAtom & at, char c) const } -istream & operator>>(istream & is, Correction & corr) +idocstream & operator>>(idocstream & is, Correction & corr) { corr.read(is); return is; } -ostream & operator<<(ostream & os, Correction & corr) +odocstream & operator<<(odocstream & os, Correction & corr) { corr.write(os); return os; @@ -125,14 +125,14 @@ public: /// void insert(const Correction & corr) { data_.push_back(corr); } /// - bool correct(MathAtom & at, char c) const; + bool correct(MathAtom & at, char_type c) const; private: /// vector data_; }; -bool Corrections::correct(MathAtom & at, char c) const +bool Corrections::correct(MathAtom & at, char_type c) const { for (const_iterator it = data_.begin(); it != data_.end(); ++it) if (it->correct(at, c)) @@ -159,7 +159,7 @@ void initAutoCorrect() //lyxerr[Debug::MATHED] << "ignoring line '" << line << '\'' << endl; continue; } - istringstream il(line); + idocstringstream il(from_utf8(line)); //lyxerr[Debug::MATHED] << "line '" << line << '\'' << endl; Correction corr; diff --git a/src/mathed/MathData.C b/src/mathed/MathData.C index a0ecb044fa..41cb2458b4 100644 --- a/src/mathed/MathData.C +++ b/src/mathed/MathData.C @@ -15,7 +15,7 @@ #include "InsetMathScript.h" #include "InsetMathMacro.h" #include "MathMacroTable.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "MathReplace.h" diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 5a2c9067d5..b808dba579 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -165,7 +165,6 @@ std::ostream & operator<<(std::ostream & os, MathArray const & ar); odocstream & operator<<(odocstream & os, MathArray const & ar); - } // namespace lyx #endif diff --git a/src/mathed/MathExtern.C b/src/mathed/MathExtern.C index 187a2ce733..f924d5f385 100644 --- a/src/mathed/MathExtern.C +++ b/src/mathed/MathExtern.C @@ -26,7 +26,7 @@ #include "InsetMathFrac.h" #include "InsetMathLim.h" #include "InsetMathMatrix.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "InsetMathNumber.h" #include "InsetMathScript.h" #include "InsetMathString.h" @@ -51,15 +51,16 @@ using support::subst; using frontend::function_names; -using std::string; using std::endl; using std::find_if; using std::auto_ptr; using std::istringstream; using std::ostream; using std::swap; +using std::string; using std::vector; +static size_t const npos = lyx::docstring::npos; // define a function for tests typedef bool TestItemFunc(MathAtom const &); @@ -152,10 +153,10 @@ MathArray::iterator extractArgument(MathArray & ar, // returns sequence of char with same code starting at it up to end // it might be less, though... -string charSequence +docstring charSequence (MathArray::const_iterator it, MathArray::const_iterator end) { - string s; + docstring s; for (; it != end && (*it)->asCharInset(); ++it) s += (*it)->getChar(); return s; @@ -168,7 +169,7 @@ void extractStrings(MathArray & ar) for (size_t i = 0; i < ar.size(); ++i) { if (!ar[i]->asCharInset()) continue; - string s = charSequence(ar.begin() + i, ar.end()); + docstring s = charSequence(ar.begin() + i, ar.end()); ar[i] = MathAtom(new InsetMathString(s)); ar.erase(i + 1, i + s.size()); } @@ -200,10 +201,10 @@ void extractMatrices(MathArray & ar) // convert this inset somehow to a string -bool extractString(MathAtom const & at, string & str) +bool extractString(MathAtom const & at, docstring & str) { if (at->getChar()) { - str = string(1, at->getChar()); + str = docstring(1, at->getChar()); return true; } if (at->asStringInset()) { @@ -215,7 +216,7 @@ bool extractString(MathAtom const & at, string & str) // is this a known function? -bool isKnownFunction(string const & str) +bool isKnownFunction(docstring const & str) { for (int i = 0; *function_names[i]; ++i) { if (str == function_names[i]) @@ -226,7 +227,7 @@ bool isKnownFunction(string const & str) // extract a function name from this inset -bool extractFunctionName(MathAtom const & at, string & str) +bool extractFunctionName(MathAtom const & at, docstring & str) { if (at->asSymbolInset()) { str = at->asSymbolInset()->name(); @@ -250,7 +251,7 @@ bool extractFunctionName(MathAtom const & at, string & str) // convert this inset somehow to a number bool extractNumber(MathArray const & ar, int & i) { - istringstream is(charSequence(ar.begin(), ar.end())); + idocstringstream is(charSequence(ar.begin(), ar.end())); is >> i; return is; } @@ -258,19 +259,24 @@ bool extractNumber(MathArray const & ar, int & i) bool extractNumber(MathArray const & ar, double & d) { - istringstream is(charSequence(ar.begin(), ar.end())); + idocstringstream is(charSequence(ar.begin(), ar.end())); is >> d; return is; } -bool testString(MathAtom const & at, string const & str) +bool testString(MathAtom const & at, docstring const & str) { - string s; + docstring s; return extractString(at, s) && str == s; } +bool testString(MathAtom const & at, char const * const str) +{ + return testString(at, from_ascii(str)); +} + // search end of nested sequence MathArray::iterator endNestSearch( MathArray::iterator it, @@ -389,7 +395,7 @@ void extractExps(MathArray & ar) continue; // create a proper exp-inset as replacement - ar[i] = MathAtom(new InsetMathExFunc("exp", sup->cell(1))); + ar[i] = MathAtom(new InsetMathExFunc(from_ascii("exp"), sup->cell(1))); ar.erase(i + 1); } //lyxerr << "\nExps to: " << ar << endl; @@ -408,7 +414,7 @@ void extractDets(MathArray & ar) continue; if (!del->isAbs()) continue; - *it = MathAtom(new InsetMathExFunc("det", del->cell(0))); + *it = MathAtom(new InsetMathExFunc(from_ascii("det"), del->cell(0))); } //lyxerr << "\ndet to: " << ar << endl; } @@ -418,17 +424,17 @@ void extractDets(MathArray & ar) // search numbers // -bool isDigitOrSimilar(char c) +bool isDigitOrSimilar(char_type c) { return ('0' <= c && c <= '9') || c == '.'; } // returns sequence of digits -string digitSequence +docstring digitSequence (MathArray::const_iterator it, MathArray::const_iterator end) { - string s; + docstring s; for (; it != end && (*it)->asCharInset(); ++it) { if (!isDigitOrSimilar((*it)->getChar())) break; @@ -447,7 +453,7 @@ void extractNumbers(MathArray & ar) if (!isDigitOrSimilar(ar[i]->asCharInset()->getChar())) continue; - string s = digitSequence(ar.begin() + i, ar.end()); + docstring s = digitSequence(ar.begin() + i, ar.end()); ar[i] = MathAtom(new InsetMathNumber(s)); ar.erase(i + 1, i + s.size()); @@ -475,7 +481,7 @@ bool testCloseParen(MathAtom const & at) MathAtom replaceParenDelims(const MathArray & ar) { - return MathAtom(new InsetMathDelim("(", ")", ar)); + return MathAtom(new InsetMathDelim(from_ascii("("), from_ascii(")"), ar)); } @@ -493,7 +499,7 @@ bool testCloseBracket(MathAtom const & at) MathAtom replaceBracketDelims(const MathArray & ar) { - return MathAtom(new InsetMathDelim("[", "]", ar)); + return MathAtom(new InsetMathDelim(from_ascii("["), from_ascii("]"), ar)); } @@ -526,7 +532,7 @@ void extractFunctions(MathArray & ar) MathArray::iterator it = ar.begin() + i; MathArray::iterator jt = it + 1; - string name; + docstring name; // is it a function? // it certainly is if it is well known... if (!extractFunctionName(*it, name)) { @@ -573,15 +579,21 @@ void extractFunctions(MathArray & ar) // search integrals // -bool testSymbol(MathAtom const & at, string const & name) +bool testSymbol(MathAtom const & at, docstring const & name) { return at->asSymbolInset() && at->asSymbolInset()->name() == name; } +bool testSymbol(MathAtom const & at, char const * const name) +{ + return at->asSymbolInset() && at->asSymbolInset()->name() == from_ascii(name); +} + + bool testIntSymbol(MathAtom const & at) { - return testSymbol(at, "int"); + return testSymbol(at, from_ascii("int")); } @@ -627,7 +639,7 @@ void extractIntegrals(MathArray & ar) continue; // core ist part from behind the scripts to the 'd' - auto_ptr p(new InsetMathExInt("int")); + auto_ptr p(new InsetMathExInt(from_ascii("int"))); // handle scripts if available if (!testIntSymbol(*it)) { @@ -679,7 +691,7 @@ bool testEqualSign(MathAtom const & at) bool testSumSymbol(MathAtom const & p) { - return testSymbol(p, "sum"); + return testSymbol(p, from_ascii("sum")); } @@ -710,7 +722,7 @@ void extractSums(MathArray & ar) continue; // create a proper inset as replacement - auto_ptr p(new InsetMathExInt("sum")); + auto_ptr p(new InsetMathExInt(from_ascii("sum"))); // collect lower bound and summation index InsetMathScript const * sub = ar[i]->asScriptInset(); @@ -985,7 +997,7 @@ void mathematica(MathArray const & dat, MathematicaStream & os) } -void mathmlize(MathArray const & dat, MathMLStream & os) +void mathmlize(MathArray const & dat, MathStream & os) { MathArray ar = dat; extractStructure(ar); @@ -1006,21 +1018,22 @@ void mathmlize(MathArray const & dat, MathMLStream & os) namespace { - string captureOutput(string const & cmd, string const & data) + std::string captureOutput(std::string const & cmd, std::string const & data) { - string command = "echo '" + data + "' | " + cmd; + std::string command = "echo '" + data + "' | " + cmd; lyxerr << "calling: " << command << endl; cmd_ret const ret = runCommand(command); return ret.second; } - string::size_type get_matching_brace(string const & str, string::size_type i) + size_t get_matching_brace(std::string const & str, size_t i) { int count = 1; - string::size_type n = str.size(); + size_t n = str.size(); while (i < n) { i = str.find_first_of("{}", i+1); - if (i == string::npos) return i; + if (i == npos) + return i; if (str[i] == '{') ++count; else @@ -1028,15 +1041,16 @@ namespace { if (count == 0) return i; } - return string::npos; + return npos; } - string::size_type get_matching_brace_back(string const & str, string::size_type i) + size_t get_matching_brace_back(std::string const & str, size_t i) { int count = 1; while (i > 0) { i = str.find_last_of("{}", i-1); - if (i == string::npos) return i; + if (i == npos) + return i; if (str[i] == '}') ++count; else @@ -1044,7 +1058,7 @@ namespace { if (count == 0) return i; } - return string::npos; + return npos; } MathArray pipeThroughMaxima(docstring const &, MathArray const & ar) @@ -1052,11 +1066,10 @@ namespace { odocstringstream os; MaximaStream ms(os); ms << ar; - // FIXME UNICODE Is utf8 encoding correct? - string expr = to_utf8(os.str()); - string const header = "simpsum:true;"; + docstring expr = os.str(); + docstring const header = from_ascii("simpsum:true;"); - string out; + std::string out; for (int i = 0; i < 100; ++i) { // at most 100 attempts // try to fix missing '*' the hard way // @@ -1066,53 +1079,52 @@ namespace { // 2x; // ^ // - lyxerr << "checking expr: '" << expr << "'" << endl; - string full = header + "tex(" + expr + ");"; - out = captureOutput("maxima", full); + lyxerr << "checking expr: '" << to_utf8(expr) << "'" << endl; + docstring full = header + "tex(" + expr + ");"; + out = captureOutput("maxima", to_utf8(full)); // leave loop if expression syntax is probably ok - if (out.find("Incorrect syntax") == string::npos) + if (out.find("Incorrect syntax") == npos) break; // search line with "Incorrect syntax" istringstream is(out); - string line; + std::string line; while (is) { getline(is, line); - if (line.find("Incorrect syntax") != string::npos) + if (line.find("Incorrect syntax") != npos) break; } // 2nd next line is the one with caret getline(is, line); getline(is, line); - string::size_type pos = line.find('^'); + size_t pos = line.find('^'); lyxerr << "found caret at pos: '" << pos << "'" << endl; - if (pos == string::npos || pos < 4) + if (pos == npos || pos < 4) break; // caret position not found pos -= 4; // skip the "tex(" part if (expr[pos] == '*') break; // two '*' in a row are definitely bad - expr.insert(pos, "*"); + expr.insert(pos, from_ascii("*")); } - vector tmp = getVectorFromString(out, "$$"); + vector tmp = getVectorFromString(out, "$$"); if (tmp.size() < 2) return MathArray(); - out = subst(tmp[1],"\\>", ""); + out = subst(tmp[1], "\\>", std::string()); lyxerr << "out: '" << out << "'" << endl; // Ugly code that tries to make the result prettier - - string::size_type i = out.find("\\mathchoice"); - while (i != string::npos) { - string::size_type j = get_matching_brace(out, i + 12); - string::size_type k = get_matching_brace(out, j + 1); + size_t i = out.find("\\mathchoice"); + while (i != npos) { + size_t j = get_matching_brace(out, i + 12); + size_t k = get_matching_brace(out, j + 1); k = get_matching_brace(out, k + 1); k = get_matching_brace(out, k + 1); - string mid = out.substr(i + 13,j - i - 13); - if (mid.find("\\over") != string::npos) + std::string mid = out.substr(i + 13, j - i - 13); + if (mid.find("\\over") != npos) mid = '{' + mid + '}'; out = out.substr(0,i) + mid @@ -1123,11 +1135,13 @@ namespace { } i = out.find("\\over"); - while (i != string::npos) { - string::size_type j = get_matching_brace_back(out, i - 1); - if (j == string::npos || j == 0) break; - string::size_type k = get_matching_brace(out, i + 5); - if (k == string::npos || k + 1 == out.size()) break; + while (i != npos) { + size_t j = get_matching_brace_back(out, i - 1); + if (j == npos || j == 0) + break; + size_t k = get_matching_brace(out, i + 5); + if (k == npos || k + 1 == out.size()) + break; out = out.substr(0,j - 1) + "\\frac" + out.substr(j,i - j) @@ -1137,14 +1151,14 @@ namespace { i = out.find("\\over", i + 4); } MathArray res; - mathed_parse_cell(res, out); + mathed_parse_cell(res, from_utf8(out)); return res; } MathArray pipeThroughMaple(docstring const & extra, MathArray const & ar) { - string header = "readlib(latex):\n"; + std::string header = "readlib(latex):\n"; // remove the \\it for variable names //"#`latex/csname_font` := `\\it `:" @@ -1172,12 +1186,11 @@ namespace { //"#`latex/latex/symbol` " // " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): "; - string trailer = "quit;"; + std::string trailer = "quit;"; odocstringstream os; MapleStream ms(os); ms << ar; - // FIXME UNICODE Is utf8 encoding correct? - string expr = to_utf8(os.str()); + std::string expr = to_utf8(os.str()); lyxerr << "ar: '" << ar << "'\n" << "ms: '" << expr << "'" << endl; @@ -1199,7 +1212,7 @@ namespace { if (line.find("on line") != 0) break; // error message not identified getline(is, line); - string::size_type pos = line.find('^'); + size_t pos = line.find('^'); if (pos == string::npos || pos < 15) break; // caret position not found pos -= 15; // skip the "on line ..." part @@ -1216,7 +1229,7 @@ namespace { // MathArray res; - mathed_parse_cell(res, out); + mathed_parse_cell(res, from_utf8(out)); return res; } @@ -1226,7 +1239,6 @@ namespace { odocstringstream os; OctaveStream vs(os); vs << ar; - // FIXME UNICODE Is utf8 encoding correct? string expr = to_utf8(os.str()); string out; @@ -1260,7 +1272,7 @@ namespace { // found line with error, next line is the one with caret getline(is, line); - string::size_type pos = line.find('^'); + size_t pos = line.find('^'); lyxerr << "caret line: '" << line << "'" << endl; lyxerr << "found caret at pos: '" << pos << "'" << endl; if (pos == string::npos || pos < 4) @@ -1278,13 +1290,13 @@ namespace { out = out.substr(6); // parse output as matrix or single number - MathAtom at(new InsetMathArray("array", out)); + MathAtom at(new InsetMathArray(from_ascii("array"), from_utf8(out))); InsetMathArray const * mat = at->asArrayInset(); MathArray res; if (mat->ncols() == 1 && mat->nrows() == 1) res.append(mat->cell(0)); else { - res.push_back(MathAtom(new InsetMathDelim("(", ")"))); + res.push_back(MathAtom(new InsetMathDelim(from_ascii("("), from_ascii(")")))); res.back().nucleus()->cell(0).push_back(at); } return res; @@ -1323,11 +1335,11 @@ namespace { bool roman, bool translate) { string const macro = "\\" + macroName + "{"; - string::size_type const len = macro.length(); - string::size_type i = out.find(macro); + size_t const len = macro.length(); + size_t i = out.find(macro); - while (i != string::npos) { - string::size_type const j = get_matching_brace(out, i + len); + while (i != npos) { + size_t const j = get_matching_brace(out, i + len); string const name = out.substr(i + len, j - i - len); out = out.substr(0, i) + (roman ? "\\mathrm{" : "") @@ -1354,8 +1366,8 @@ namespace { out = captureOutput("math", full); lyxerr << "out: '" << out << "'" << endl; - string::size_type pos1 = out.find("Out[1]//TeXForm= "); - string::size_type pos2 = out.find("In[2]:="); + size_t pos1 = out.find("Out[1]//TeXForm= "); + size_t pos2 = out.find("In[2]:="); if (pos1 == string::npos || pos2 == string::npos) return MathArray(); @@ -1370,7 +1382,7 @@ namespace { prettifyMathematicaOutput(out, "Mvariable", false, false); MathArray res; - mathed_parse_cell(res, out); + mathed_parse_cell(res, from_utf8(out)); return res; } @@ -1411,7 +1423,7 @@ MathArray pipeThroughExtern(string const & lang, docstring const & extra, // run external sript string out = captureOutput(file, data); MathArray res; - mathed_parse_cell(res, out); + mathed_parse_cell(res, from_utf8(out)); return res; } diff --git a/src/mathed/MathExtern.h b/src/mathed/MathExtern.h index 9a7c4cb9bf..20fe9849eb 100644 --- a/src/mathed/MathExtern.h +++ b/src/mathed/MathExtern.h @@ -13,16 +13,15 @@ #define MATH_EXTERN_H #include "support/docstring.h" - +#include namespace lyx { - class NormalStream; class MapleStream; class MaximaStream; class MathematicaStream; -class MathMLStream; +class MathStream; class OctaveStream; class WriteStream; class MathArray; @@ -32,14 +31,14 @@ void normalize(MathArray const &, NormalStream &); void maple(MathArray const &, MapleStream &); void maxima(MathArray const &, MaximaStream &); void mathematica(MathArray const &, MathematicaStream &); -void mathmlize(MathArray const &, MathMLStream &); +void mathmlize(MathArray const &, MathStream &); void octave(MathArray const &, OctaveStream &); bool extractNumber(MathArray const & ar, int & i); bool extractNumber(MathArray const & ar, double & i); -MathArray pipeThroughExtern(std::string const & lang, docstring const & extra, - MathArray const & ar); +MathArray pipeThroughExtern(std::string const & language, + docstring const & extra, MathArray const & ar); } // namespace lyx diff --git a/src/mathed/MathFactory.C b/src/mathed/MathFactory.C index c411b84cc2..ac18853eb0 100644 --- a/src/mathed/MathFactory.C +++ b/src/mathed/MathFactory.C @@ -82,12 +82,12 @@ bool has_math_fonts; namespace { // file scope -typedef std::map WordList; +typedef std::map WordList; WordList theWordList; -bool math_font_available(string & name) +bool math_font_available(docstring & name) { LyXFont f; augmentFont(f, name); @@ -98,12 +98,12 @@ bool math_font_available(string & name) // can we fake it? if (name == "eufrak") { - name = "lyxfakefrak"; + name = from_ascii("lyxfakefrak"); return true; } lyxerr[Debug::MATHED] - << "font " << name << " not available and I can't fake it" + << "font " << to_utf8(name) << " not available and I can't fake it" << endl; return false; } @@ -133,7 +133,8 @@ void initSymbols() string tmp; is >> tmp; is >> tmp; - skip = !math_font_available(tmp); + docstring t = from_utf8(tmp); + skip = !math_font_available(t); continue; } else if (line.size() >= 4 && line.substr(0, 4) == "else") { skip = !skip; @@ -146,13 +147,13 @@ void initSymbols() // special case of pre-defined macros if (line.size() > 8 && line.substr(0, 5) == "\\def\\") { //lyxerr << "macro definition: '" << line << '\'' << endl; - MacroTable::globalMacros().insert(line); + MacroTable::globalMacros().insert(from_utf8(line)); continue; } - istringstream is(line); + idocstringstream is(from_utf8(line)); latexkeys tmp; - is >> tmp.name >> tmp.inset; + is >> tmp.name >> tmp.inset; if (isFontName(tmp.inset)) is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname; else @@ -160,7 +161,7 @@ void initSymbols() if (!is) { lyxerr[Debug::MATHED] << "skipping line '" << line << '\'' << endl; lyxerr[Debug::MATHED] - << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << endl; + << to_utf8(tmp.name) << ' ' << to_utf8(tmp.inset) << ' ' << to_utf8(tmp.extra) << endl; continue; } @@ -170,60 +171,55 @@ void initSymbols() // store requirements as long as we can if (tmp.inset == "msa" || tmp.inset == "msb") - tmp.requires = "amssymb"; + tmp.requires = from_ascii("amssymb"); // See http://bugzilla.lyx.org/show_bug.cgi?id=1942 // else if (tmp.inset == "wasy") // tmp.requires = "wasysym"; // symbol font is not available sometimes - string symbol_font = "lyxsymbol"; + docstring symbol_font = from_ascii("lyxsymbol"); if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra == "special") { - lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << endl; - // FIXME UNICODE - vector n(tmp.name.begin(), tmp.name.end()); - tmp.draw = n; + lyxerr[Debug::MATHED] << "symbol abuse for " << to_utf8(tmp.name) << endl; + tmp.draw = tmp.name; } else if (math_font_available(tmp.inset)) { - lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << endl; + lyxerr[Debug::MATHED] << "symbol available for " << to_utf8(tmp.name) << endl; tmp.draw.push_back(char_type(charid)); } else if (fallbackid && math_font_available(symbol_font)) { if (tmp.inset == "cmex") - tmp.inset = "lyxsymbol"; + tmp.inset = from_ascii("lyxsymbol"); else - tmp.inset = "lyxboldsymbol"; - lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << endl; + tmp.inset = from_ascii("lyxboldsymbol"); + lyxerr[Debug::MATHED] << "symbol fallback for " << to_utf8(tmp.name) << endl; tmp.draw.push_back(char_type(fallbackid)); } else { - lyxerr[Debug::MATHED] << "faking " << tmp.name << endl; - vector n(tmp.name.begin(), - tmp.name.end()); - - tmp.draw = n; - tmp.inset = "lyxtex"; + lyxerr[Debug::MATHED] << "faking " << to_utf8(tmp.name) << endl; + tmp.draw = tmp.name; + tmp.inset = from_ascii("lyxtex"); } } else { // it's a proper inset - lyxerr[Debug::MATHED] << "inset " << tmp.inset - << " used for " << tmp.name + lyxerr[Debug::MATHED] << "inset " << to_utf8(tmp.inset) + << " used for " << to_utf8(tmp.name) << endl; } if (theWordList.find(tmp.name) != theWordList.end()) lyxerr[Debug::MATHED] - << "readSymbols: inset " << tmp.name + << "readSymbols: inset " << to_utf8(tmp.name) << " already exists." << endl; else theWordList[tmp.name] = tmp; lyxerr[Debug::MATHED] - << "read symbol '" << tmp.name - << " inset: " << tmp.inset + << "read symbol '" << to_utf8(tmp.name) + << " inset: " << to_utf8(tmp.inset) << " draw: " << int(tmp.draw.empty() ? 0 : tmp.draw[0]) - << " extra: " << tmp.extra + << " extra: " << to_utf8(tmp.extra) << '\'' << endl; } - string tmp = "cmm"; - string tmp2 = "cmsy"; + docstring tmp = from_ascii("cmm"); + docstring tmp2 = from_ascii("cmsy"); has_math_fonts = math_font_available(tmp) && math_font_available(tmp2); } @@ -242,19 +238,25 @@ void initMath() } -latexkeys const * in_word_set(string const & str) +latexkeys const * in_word_set(docstring const & str) { WordList::iterator it = theWordList.find(str); return it != theWordList.end() ? &(it->second) : 0; } -MathAtom createInsetMath(string const & s) +MathAtom createInsetMath(char const * const s) +{ + return createInsetMath(from_utf8(s)); +} + + +MathAtom createInsetMath(docstring const & s) { //lyxerr << "creating inset with name: '" << s << '\'' << endl; latexkeys const * l = in_word_set(s); if (l) { - string const & inset = l->inset; + docstring const & inset = l->inset; //lyxerr << " found inset: '" << inset << '\'' << endl; if (inset == "ref") return MathAtom(new RefInset(l->name)); @@ -371,19 +373,19 @@ MathAtom createInsetMath(string const & s) } -bool createInsetMath_fromDialogStr(string const & str, MathArray & ar) +bool createInsetMath_fromDialogStr(docstring const & str, MathArray & ar) { // An example str: // "ref LatexCommand \\ref{sec:Title}\n\\end_inset\n\n"; - string name; - string body = split(str, name, ' '); + docstring name; + docstring body = split(str, name, ' '); if (name != "ref" ) return false; // body comes with a head "LatexCommand " and a // tail "\nend_inset\n\n". Strip them off. - string trimmed; + docstring trimmed; body = split(body, trimmed, ' '); split(body, trimmed, '\n'); diff --git a/src/mathed/MathFactory.h b/src/mathed/MathFactory.h index 728d9a66e5..89e17e9f8c 100644 --- a/src/mathed/MathFactory.h +++ b/src/mathed/MathFactory.h @@ -12,22 +12,23 @@ #ifndef MATH_FACTORY_H #define MATH_FACTORY_H +#include "support/docstring.h" #include - namespace lyx { class MathAtom; class MathArray; -MathAtom createInsetMath(std::string const &); +MathAtom createInsetMath(docstring const &); +MathAtom createInsetMath(char const * const); /** Fills ar with the contents of str. * str is created by the frontend dialog's and returned to the LyX core. * The function returns true if successful. */ -bool createInsetMath_fromDialogStr(std::string const &, MathArray &); +bool createInsetMath_fromDialogStr(docstring const &, MathArray &); } // namespace lyx diff --git a/src/mathed/MathGridInfo.h b/src/mathed/MathGridInfo.h index f1e99719b3..1c20e8d472 100644 --- a/src/mathed/MathGridInfo.h +++ b/src/mathed/MathGridInfo.h @@ -23,8 +23,8 @@ class ColInfo public: ColInfo() : align('c'), rightline(0), leftline(false) {} char align; // column alignment - std::string width; // column width - std::string special; // special column alignment + docstring width; // column width + docstring special; // special column alignment int rightline; // a line on the right? bool leftline; }; @@ -47,7 +47,7 @@ public: topline(false), bottomline(false) {} - std::string content; // cell content + docstring content; // cell content int multi; // multicolumn flag char align; // cell alignment bool leftline; // do we have a line on the left? diff --git a/src/mathed/MathMLStream.C b/src/mathed/MathMLStream.C deleted file mode 100644 index 4958ad37b5..0000000000 --- a/src/mathed/MathMLStream.C +++ /dev/null @@ -1,385 +0,0 @@ -/** - * \file MathMLStream.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author André Pönitz - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "MathMLStream.h" -#include "InsetMath.h" -#include "MathData.h" -#include "MathExtern.h" -#include "support/lyxalgo.h" - - -namespace { - -bool isAlpha(char c) -{ - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); -} - -} - - -namespace lyx { - -using std::strlen; - - -WriteStream::WriteStream(odocstream & os, bool fragile, bool latex) - : os_(os), fragile_(fragile), firstitem_(false), latex_(latex), - pendingspace_(false), line_(0) -{} - - -WriteStream::WriteStream(odocstream & os) - : os_(os), fragile_(false), firstitem_(false), latex_(false), - pendingspace_(false), line_(0) -{} - - -WriteStream::~WriteStream() -{ - if (pendingspace_) - os_ << ' '; -} - - -void WriteStream::addlines(unsigned int n) -{ - line_ += n; -} - - -void WriteStream::pendingSpace(bool how) -{ - pendingspace_ = how; -} - - -WriteStream & operator<<(WriteStream & ws, MathAtom const & at) -{ - at->write(ws); - return ws; -} - - -WriteStream & operator<<(WriteStream & ws, MathArray const & ar) -{ - write(ar, ws); - return ws; -} - - -WriteStream & operator<<(WriteStream & ws, char const * s) -{ - if (ws.pendingSpace() && strlen(s) > 0) { - if (isAlpha(s[0])) - ws.os() << ' '; - ws.pendingSpace(false); - } - ws.os() << s; - ws.addlines(int(count(s, s + strlen(s), '\n'))); - return ws; -} - - -WriteStream & operator<<(WriteStream & ws, char c) -{ - if (ws.pendingSpace()) { - if (isAlpha(c)) - ws.os() << ' '; - ws.pendingSpace(false); - } - ws.os() << c; - if (c == '\n') - ws.addlines(1); - return ws; -} - - -WriteStream & operator<<(WriteStream & ws, int i) -{ - ws.os() << i; - return ws; -} - - -WriteStream & operator<<(WriteStream & ws, unsigned int i) -{ - ws.os() << i; - return ws; -} - - -////////////////////////////////////////////////////////////////////// - - -MathMLStream::MathMLStream(odocstream & os) - : os_(os), tab_(0), line_(0), lastchar_(0) -{} - - -MathMLStream & operator<<(MathMLStream & ms, MathAtom const & at) -{ - at->mathmlize(ms); - return ms; -} - - -MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar) -{ - mathmlize(ar, ms); - return ms; -} - - -MathMLStream & operator<<(MathMLStream & ms, docstring const & s) -{ - ms.os() << s; - return ms; -} - -MathMLStream & operator<<(MathMLStream & ms, char const * s) -{ - ms.os() << s; - return ms; -} - - -MathMLStream & operator<<(MathMLStream & ms, char c) -{ - ms.os() << c; - return ms; -} - - -MathMLStream & operator<<(MathMLStream & ms, MTag const & t) -{ - ++ms.tab(); - ms.cr(); - ms.os() << '<' << t.tag_ << '>'; - return ms; -} - - -MathMLStream & operator<<(MathMLStream & ms, ETag const & t) -{ - ms.cr(); - if (ms.tab() > 0) - --ms.tab(); - ms.os() << "'; - return ms; -} - - -void MathMLStream::cr() -{ - os() << '\n'; - for (int i = 0; i < tab(); ++i) - os() << ' '; -} - - -////////////////////////////////////////////////////////////////////// - - -MapleStream & operator<<(MapleStream & ms, MathAtom const & at) -{ - at->maple(ms); - return ms; -} - - -MapleStream & operator<<(MapleStream & ms, MathArray const & ar) -{ - maple(ar, ms); - return ms; -} - - -MapleStream & operator<<(MapleStream & ms, char const * s) -{ - ms.os() << s; - return ms; -} - - -MapleStream & operator<<(MapleStream & ms, char c) -{ - ms.os() << c; - return ms; -} - - -MapleStream & operator<<(MapleStream & ms, int i) -{ - ms.os() << i; - return ms; -} - - -////////////////////////////////////////////////////////////////////// - - -MaximaStream & operator<<(MaximaStream & ms, MathAtom const & at) -{ - at->maxima(ms); - return ms; -} - - -MaximaStream & operator<<(MaximaStream & ms, MathArray const & ar) -{ - maxima(ar, ms); - return ms; -} - - -MaximaStream & operator<<(MaximaStream & ms, char const * s) -{ - ms.os() << s; - return ms; -} - - -MaximaStream & operator<<(MaximaStream & ms, char c) -{ - ms.os() << c; - return ms; -} - - -MaximaStream & operator<<(MaximaStream & ms, int i) -{ - ms.os() << i; - return ms; -} - - -////////////////////////////////////////////////////////////////////// - - -MathematicaStream & operator<<(MathematicaStream & ms, MathAtom const & at) -{ - at->mathematica(ms); - return ms; -} - - -MathematicaStream & operator<<(MathematicaStream & ms, MathArray const & ar) -{ - mathematica(ar, ms); - return ms; -} - - -MathematicaStream & operator<<(MathematicaStream & ms, char const * s) -{ - ms.os() << s; - return ms; -} - - -MathematicaStream & operator<<(MathematicaStream & ms, char c) -{ - ms.os() << c; - return ms; -} - - -MathematicaStream & operator<<(MathematicaStream & ms, int i) -{ - ms.os() << i; - return ms; -} - - - -////////////////////////////////////////////////////////////////////// - - -OctaveStream & operator<<(OctaveStream & ns, MathAtom const & at) -{ - at->octave(ns); - return ns; -} - - -OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar) -{ - octave(ar, ns); - return ns; -} - - -OctaveStream & operator<<(OctaveStream & ns, char const * s) -{ - ns.os() << s; - return ns; -} - - -OctaveStream & operator<<(OctaveStream & ns, char c) -{ - ns.os() << c; - return ns; -} - - -OctaveStream & operator<<(OctaveStream & ns, int i) -{ - ns.os() << i; - return ns; -} - - -////////////////////////////////////////////////////////////////////// - - -NormalStream & operator<<(NormalStream & ns, MathAtom const & at) -{ - at->normalize(ns); - return ns; -} - - -NormalStream & operator<<(NormalStream & ns, MathArray const & ar) -{ - normalize(ar, ns); - return ns; -} - - -NormalStream & operator<<(NormalStream & ns, char const * s) -{ - ns.os() << s; - return ns; -} - - -NormalStream & operator<<(NormalStream & ns, char c) -{ - ns.os() << c; - return ns; -} - - -NormalStream & operator<<(NormalStream & ns, int i) -{ - ns.os() << i; - return ns; -} - - - -////////////////////////////////////////////////////////////////////// - - -} // namespace lyx diff --git a/src/mathed/MathMLStream.h b/src/mathed/MathMLStream.h deleted file mode 100644 index 555ff7dbef..0000000000 --- a/src/mathed/MathMLStream.h +++ /dev/null @@ -1,298 +0,0 @@ -// -*- C++ -*- -/** - * \file MathMLStream.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author André Pönitz - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef MATH_MATHMLSTREAM_H -#define MATH_MATHMLSTREAM_H - - -// Please keep all four streams in one file until the interface has -// settled. - - -#include "metricsinfo.h" -#include "support/docstream.h" - -#include "support/docstream.h" - - -namespace lyx { - -class MathArray; -class InsetMath; -class MathAtom; - -// -// LaTeX/LyX -// - -class WriteStream { -public: - /// - WriteStream(odocstream & os, bool fragile, bool latex); - /// - explicit WriteStream(odocstream & os); - /// - ~WriteStream(); - /// - int line() const { return line_; } - /// - bool fragile() const { return fragile_; } - /// - bool latex() const { return latex_; } - /// - odocstream & os() { return os_; } - /// - bool & firstitem() { return firstitem_; } - /// - void addlines(unsigned int); - /// writes space if next thing is isalpha() - void pendingSpace(bool how); - /// writes space if next thing is isalpha() - bool pendingSpace() const { return pendingspace_; } -private: - /// - odocstream & os_; - /// do we have to write \\protect sometimes - bool fragile_; - /// are we at the beginning of an MathArray? - bool firstitem_; - /// are we writing to .tex? - int latex_; - /// do we have a space pending? - bool pendingspace_; - /// - int line_; -}; - -/// -WriteStream & operator<<(WriteStream &, MathAtom const &); -/// -WriteStream & operator<<(WriteStream &, MathArray const &); -/// -WriteStream & operator<<(WriteStream &, char const *); -/// -WriteStream & operator<<(WriteStream &, char); -/// -WriteStream & operator<<(WriteStream &, int); -/// -WriteStream & operator<<(WriteStream &, unsigned int); - - - -// -// MathML -// - -class MTag { -public: - /// - MTag(char const * const tag) : tag_(tag) {} - /// - char const * const tag_; -}; - -class ETag { -public: - /// - ETag(char const * const tag) : tag_(tag) {} - /// - char const * const tag_; -}; - -class MathMLStream { -public: - /// - explicit MathMLStream(odocstream & os); - /// - void cr(); - /// - odocstream & os() { return os_; } - /// - int line() const { return line_; } - /// - int & tab() { return tab_; } - /// - friend MathMLStream & operator<<(MathMLStream &, char const *); - /// - friend MathMLStream & operator<<(MathMLStream &, docstring const &); -private: - /// - odocstream & os_; - /// - int tab_; - /// - int line_; - /// - char lastchar_; -}; - -/// -MathMLStream & operator<<(MathMLStream &, MathAtom const &); -/// -MathMLStream & operator<<(MathMLStream &, MathArray const &); -/// -MathMLStream & operator<<(MathMLStream &, char const *); -/// -MathMLStream & operator<<(MathMLStream &, char); -/// -MathMLStream & operator<<(MathMLStream &, MTag const &); -/// -MathMLStream & operator<<(MathMLStream &, ETag const &); - - - -// -// Debugging -// - -class NormalStream { -public: - /// - explicit NormalStream(odocstream & os) : os_(os) {} - /// - odocstream & os() { return os_; } -private: - /// - odocstream & os_; -}; - -/// -NormalStream & operator<<(NormalStream &, MathAtom const &); -/// -NormalStream & operator<<(NormalStream &, MathArray const &); -/// -NormalStream & operator<<(NormalStream &, char const *); -/// -NormalStream & operator<<(NormalStream &, char); -/// -NormalStream & operator<<(NormalStream &, int); - - -// -// Maple -// - - -class MapleStream { -public: - /// - explicit MapleStream(odocstream & os) : os_(os) {} - /// - odocstream & os() { return os_; } -private: - /// - odocstream & os_; -}; - - -/// -MapleStream & operator<<(MapleStream &, MathAtom const &); -/// -MapleStream & operator<<(MapleStream &, MathArray const &); -/// -MapleStream & operator<<(MapleStream &, char const *); -/// -MapleStream & operator<<(MapleStream &, char); -/// -MapleStream & operator<<(MapleStream &, int); - - -// -// Maxima -// - - -class MaximaStream { -public: - /// - explicit MaximaStream(odocstream & os) : os_(os) {} - /// - odocstream & os() { return os_; } -private: - /// - odocstream & os_; -}; - - -/// -MaximaStream & operator<<(MaximaStream &, MathAtom const &); -/// -MaximaStream & operator<<(MaximaStream &, MathArray const &); -/// -MaximaStream & operator<<(MaximaStream &, char const *); -/// -MaximaStream & operator<<(MaximaStream &, char); -/// -MaximaStream & operator<<(MaximaStream &, int); - - -// -// Mathematica -// - - -class MathematicaStream { -public: - /// - explicit MathematicaStream(odocstream & os) : os_(os) {} - /// - odocstream & os() { return os_; } -private: - /// - odocstream & os_; -}; - - -/// -MathematicaStream & operator<<(MathematicaStream &, MathAtom const &); -/// -MathematicaStream & operator<<(MathematicaStream &, MathArray const &); -/// -MathematicaStream & operator<<(MathematicaStream &, char const *); -/// -MathematicaStream & operator<<(MathematicaStream &, char); -/// -MathematicaStream & operator<<(MathematicaStream &, int); - - -// -// Octave -// - - -class OctaveStream { -public: - /// - explicit OctaveStream(odocstream & os) : os_(os) {} - /// - odocstream & os() { return os_; } -private: - /// - odocstream & os_; -}; - -/// -OctaveStream & operator<<(OctaveStream &, MathAtom const &); -/// -OctaveStream & operator<<(OctaveStream &, MathArray const &); -/// -OctaveStream & operator<<(OctaveStream &, char const *); -/// -OctaveStream & operator<<(OctaveStream &, char); -/// -OctaveStream & operator<<(OctaveStream &, int); - - - - -} // namespace lyx - -#endif diff --git a/src/mathed/MathMacroArgument.C b/src/mathed/MathMacroArgument.C index e48defe98e..d73877c85a 100644 --- a/src/mathed/MathMacroArgument.C +++ b/src/mathed/MathMacroArgument.C @@ -13,7 +13,7 @@ #include "MathMacroArgument.h" #include "InsetMathMacro.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathSupport.h" #include "debug.h" @@ -33,8 +33,9 @@ MathMacroArgument::MathMacroArgument(size_t n) lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: " << n << endl; } + str_.resize(3); str_[0] = '#'; - str_[1] = static_cast('0' + n); + str_[1] = static_cast('0' + n); str_[2] = '\0'; } @@ -53,16 +54,14 @@ void MathMacroArgument::write(WriteStream & os) const void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const { - vector n(str_, str_ + 3); - mathed_string_dim(mi.base.font, n, dim_); + mathed_string_dim(mi.base.font, str_, dim_); dim = dim_; } void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const { - // FIXME UNICODE - drawStrRed(pi, x, y, from_utf8(str_)); + drawStrRed(pi, x, y, str_); setPosCache(pi, x, y); } diff --git a/src/mathed/MathMacroArgument.h b/src/mathed/MathMacroArgument.h index 360b0e3ef7..32729a6df7 100644 --- a/src/mathed/MathMacroArgument.h +++ b/src/mathed/MathMacroArgument.h @@ -43,7 +43,7 @@ private: /// A number between 1 and 9 std::size_t number_; /// - char str_[3]; + docstring str_; }; diff --git a/src/mathed/MathMacroTable.C b/src/mathed/MathMacroTable.C index 97ee7cabec..d7e2c0aa17 100644 --- a/src/mathed/MathMacroTable.C +++ b/src/mathed/MathMacroTable.C @@ -40,7 +40,7 @@ MacroData::MacroData() {} -MacroData::MacroData(string const & def, int numargs, string const & disp) +MacroData::MacroData(docstring const & def, int numargs, docstring const & disp) : def_(def), numargs_(numargs), disp_(disp) {} @@ -49,7 +49,7 @@ void MacroData::expand(vector const & args, MathArray & to) const { InsetMathSqrt inset; // Hack. Any inset with a cell would do. // FIXME UNICODE - asArray(from_utf8(disp_.empty() ? def_ : disp_), inset.cell(0)); + asArray(disp_.empty() ? def_ : disp_, inset.cell(0)); //lyxerr << "MathData::expand: args: " << args << endl; //lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl; for (DocIterator it = doc_iterator_begin(inset); it; it.forwardChar()) { @@ -86,13 +86,13 @@ MacroTable & MacroTable::globalMacros() //} -bool MacroTable::has(string const & name) const +bool MacroTable::has(docstring const & name) const { return find(name) != end(); } -MacroData const & MacroTable::get(string const & name) const +MacroData const & MacroTable::get(docstring const & name) const { const_iterator it = find(name); BOOST_ASSERT(it != end()); @@ -100,17 +100,17 @@ MacroData const & MacroTable::get(string const & name) const } -void MacroTable::insert(string const & name, MacroData const & data) +void MacroTable::insert(docstring const & name, MacroData const & data) { //lyxerr << "MacroTable::insert: " << name << endl; operator[](name) = data; } -void MacroTable::insert(string const & def) +void MacroTable::insert(docstring const & def) { //lyxerr << "MacroTable::insert, def: " << def << endl; - istringstream is(def); + std::istringstream is(to_utf8(def)); MathMacroTemplate mac(is); insert(mac.name(), mac.asMacroData()); } @@ -120,9 +120,9 @@ void MacroTable::dump() { lyxerr << "\n------------------------------------------" << endl; for (const_iterator it = begin(); it != end(); ++it) - lyxerr << it->first - << " [" << it->second.def() << "] : " - << " [" << it->second.disp() << "] : " + lyxerr << to_utf8(it->first) + << " [" << to_utf8(it->second.def()) << "] : " + << " [" << to_utf8(it->second.disp()) << "] : " << endl; lyxerr << "------------------------------------------" << endl; } diff --git a/src/mathed/MathMacroTable.h b/src/mathed/MathMacroTable.h index acb4ad8bc4..cf8719583a 100644 --- a/src/mathed/MathMacroTable.h +++ b/src/mathed/MathMacroTable.h @@ -16,23 +16,23 @@ #include #include +#include "support/docstring.h" namespace lyx { class MathArray; - /// class MacroData { public: /// MacroData(); /// - MacroData(std::string const & def, int nargs, std::string const & disp); + MacroData(docstring const & def, int nargs, docstring const & disp); /// - std::string def() const { return def_; } + docstring def() const { return def_; } /// - std::string disp() const { return disp_; } + docstring disp() const { return disp_; } /// int numargs() const { return numargs_; } /// replace #1,#2,... by given MathAtom 0,1,.. @@ -40,11 +40,11 @@ public: private: /// - std::string def_; + docstring def_; /// int numargs_; /// - std::string disp_; + docstring disp_; }; @@ -52,17 +52,17 @@ private: // either because they implement a feature of standard LaTeX or some // hack to display certain contents nicely. -class MacroTable : public std::map +class MacroTable : public std::map { public: /// Parse full "\def..." or "\newcommand..." or ... - void insert(std::string const & definition); + void insert(docstring const & definition); /// Insert pre-digested macro definition - void insert(std::string const & name, MacroData const & data); + void insert(docstring const & name, MacroData const & data); /// Do we have a macro by that name? - bool has(std::string const & name) const; + bool has(docstring const & name) const; /// - MacroData const & get(std::string const & name) const; + MacroData const & get(docstring const & name) const; /// void dump(); diff --git a/src/mathed/MathMacroTemplate.C b/src/mathed/MathMacroTemplate.C index 5748e1e252..d07ae26f76 100644 --- a/src/mathed/MathMacroTemplate.C +++ b/src/mathed/MathMacroTemplate.C @@ -11,7 +11,7 @@ #include #include "MathMacroTemplate.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "MathSupport.h" @@ -31,22 +31,21 @@ namespace lyx { using support::bformat; -using std::string; using std::auto_ptr; using std::ostream; using std::endl; MathMacroTemplate::MathMacroTemplate() - : InsetMathNest(2), numargs_(0), name_(), type_("newcommand") + : InsetMathNest(2), numargs_(0), name_(), type_(from_ascii("newcommand")) { initMath(); } -MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs, - string const & type, MathArray const & ar1, MathArray const & ar2) - : InsetMathNest(2), numargs_(numargs), name_(nm), type_(type) +MathMacroTemplate::MathMacroTemplate(docstring const & name, int numargs, + docstring const & type, MathArray const & ar1, MathArray const & ar2) + : InsetMathNest(2), numargs_(numargs), name_(name), type_(type) { initMath(); @@ -98,7 +97,7 @@ void MathMacroTemplate::numargs(int numargs) } -string MathMacroTemplate::name() const +docstring MathMacroTemplate::name() const { return name_; } @@ -109,7 +108,7 @@ docstring MathMacroTemplate::prefix() const // FIXME UNICODE // delete the conversion when bformat() will return a docstring. // delete the conversion when bformat() takes a docstring arg. - return bformat(_(" Macro: %1$s: "), from_utf8(name_)); + return bformat(_(" Macro: %1$s: "), name_); } @@ -174,7 +173,7 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const void MathMacroTemplate::read(Buffer const &, LyXLex & lex) { MathArray ar; - mathed_parse_cell(ar, lex.getStream()); + mathed_parse_cell(ar, lex.getDocString()); if (ar.size() != 1 || !ar[0]->asMacroTemplate()) { lyxerr << "cannot read macro from '" << ar << "'" << endl; return; diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index 8a945e1255..cc07d4e10f 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -28,8 +28,8 @@ public: /// MathMacroTemplate(); /// - MathMacroTemplate(std::string const & name, int nargs, - std::string const & type, + MathMacroTemplate(docstring const & name, int nargs, + docstring const & type, MathArray const & = MathArray(), MathArray const & = MathArray()); /// @@ -49,7 +49,7 @@ public: /// void numargs(int); /// - std::string name() const; + docstring name() const; /// MacroData asMacroData() const; /// @@ -71,9 +71,9 @@ private: /// int numargs_; /// - std::string name_; + docstring name_; /// newcommand or renewcommand or def - std::string type_; + docstring type_; }; diff --git a/src/mathed/MathParser.C b/src/mathed/MathParser.C index c47f14da81..a43a8dba27 100644 --- a/src/mathed/MathParser.C +++ b/src/mathed/MathParser.C @@ -88,7 +88,7 @@ using std::vector; namespace { -InsetMath::mode_type asMode(InsetMath::mode_type oldmode, string const & str) +InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str) { //lyxerr << "handling mode: '" << str << "'" << endl; if (str == "mathmode") @@ -99,9 +99,9 @@ InsetMath::mode_type asMode(InsetMath::mode_type oldmode, string const & str) } -bool stared(string const & s) +bool stared(docstring const & s) { - string::size_type const n = s.size(); + size_t const n = s.size(); return n && s[n - 1] == '*'; } @@ -112,7 +112,7 @@ bool stared(string const & s) * environments like "equation" that have a fixed number of rows. */ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow, - string const & vskip) + docstring const & vskip) { ++cellrow; if (cellrow == grid.nrows()) { @@ -128,12 +128,12 @@ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow, --cellrow; lyxerr << "ignoring extra row"; if (!vskip.empty()) - lyxerr << " with extra space " << vskip; + lyxerr << " with extra space " << to_utf8(vskip); lyxerr << '.' << endl; return false; } } - grid.vcrskip(LyXLength(vskip), cellrow - 1); + grid.vcrskip(LyXLength(to_utf8(vskip)), cellrow - 1); return true; } @@ -248,26 +248,26 @@ public: /// Token() : cs_(), char_(0), cat_(catIgnore) {} /// - Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {} + Token(char_type c, CatCode cat) : cs_(), char_(c), cat_(cat) {} /// - Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {} + Token(docstring const & cs) : cs_(cs), char_(0), cat_(catIgnore) {} /// - string const & cs() const { return cs_; } + docstring const & cs() const { return cs_; } /// CatCode cat() const { return cat_; } /// - char character() const { return char_; } + char_type character() const { return char_; } /// - string asString() const { return cs_.size() ? cs_ : string(1, char_); } + docstring asString() const { return cs_.size() ? cs_ : docstring(1, char_); } /// - string asInput() const { return cs_.size() ? '\\' + cs_ : string(1, char_); } + docstring asInput() const { return cs_.size() ? '\\' + cs_ : docstring(1, char_); } private: /// - string cs_; + docstring cs_; /// - char char_; + char_type char_; /// CatCode cat_; }; @@ -312,17 +312,18 @@ private: /// void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered); /// get arg delimited by 'left' and 'right' - string getArg(char left, char right); + docstring getArg(char_type left, char_type right); /// - char getChar(); + char_type getChar(); /// void error(string const & msg); + void error(docstring const & msg) { error(to_utf8(msg)); } /// dump contents to screen void dump() const; /// void tokenize(istream & is); /// - void tokenize(string const & s); + void tokenize(docstring const & s); /// void skipSpaceTokens(istream & is, char c); /// @@ -338,13 +339,13 @@ private: /// skips spaces if any void skipSpaces(); /// - void lex(string const & s); + void lex(docstring const & s); /// bool good() const; /// - string parse_verbatim_item(); + docstring parse_verbatim_item(); /// - string parse_verbatim_option(); + docstring parse_verbatim_option(); /// int lineno_; @@ -353,7 +354,7 @@ private: /// unsigned pos_; /// Stack of active environments - vector environments_; + vector environments_; }; @@ -425,7 +426,7 @@ bool Parser::good() const } -char Parser::getChar() +char_type Parser::getChar() { if (!good()) error("The input stream is not well..."); @@ -433,12 +434,12 @@ char Parser::getChar() } -string Parser::getArg(char left, char right) +docstring Parser::getArg(char_type left, char_type right) { skipSpaces(); - string result; - char c = getChar(); + docstring result; + char_type c = getChar(); if (c != left) putback(); @@ -465,7 +466,7 @@ void Parser::tokenize(istream & is) { // eat everything up to the next \end_inset or end of stream // and store it in s for further tokenization - string s; + docstring s; char c; while (is.get(c)) { s += c; @@ -483,9 +484,9 @@ void Parser::tokenize(istream & is) } -void Parser::tokenize(string const & buffer) +void Parser::tokenize(docstring const & buffer) { - istringstream is(buffer, ios::in | ios::binary); + istringstream is(to_utf8(buffer), ios::in | ios::binary); char c; while (is.get(c)) { @@ -518,7 +519,7 @@ void Parser::tokenize(string const & buffer) if (!is) { error("unexpected end of input"); } else { - string s(1, c); + docstring s(1, c); if (catcode(c) == catLetter) { // collect letters while (is.get(c) && catcode(c) == catLetter) @@ -593,10 +594,10 @@ bool Parser::parse(MathAtom & at) } -string Parser::parse_verbatim_option() +docstring Parser::parse_verbatim_option() { skipSpaces(); - string res; + docstring res; if (nextToken().character() == '[') { Token t = getToken(); for (Token t = getToken(); t.character() != ']' && good(); t = getToken()) { @@ -611,10 +612,10 @@ string Parser::parse_verbatim_option() } -string Parser::parse_verbatim_item() +docstring Parser::parse_verbatim_item() { skipSpaces(); - string res; + docstring res; if (nextToken().cat() == catBegin) { Token t = getToken(); for (Token t = getToken(); t.cat() != catEnd && good(); t = getToken()) { @@ -835,7 +836,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, cell->push_back(MathAtom(new InsetMathChar(t.character()))); else if (t.cat() == catComment) { - string s; + docstring s; while (good()) { Token const & t = getToken(); if (t.cat() == catNewline) @@ -859,15 +860,15 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, t.cs() == "newcommand" || t.cs() == "renewcommand") { - string const type = t.cs(); - string name; + docstring const type = t.cs(); + docstring name; int nargs = 0; if (t.cs() == "def") { // get name name = getToken().cs(); // read parameter - string pars; + docstring pars; while (good() && nextToken().cat() != catBegin) { pars += getToken().cs(); ++nargs; @@ -889,7 +890,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, return; } - string const arg = getArg('[', ']'); + docstring const arg = getArg('[', ']'); if (!arg.empty()) nargs = convert(arg); @@ -933,7 +934,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "end") { if (flags & FLAG_END) { // eat environment name - string const name = getArg('{', '}'); + docstring const name = getArg('{', '}'); if (environments_.empty()) error("'found \\end{" + name + "}' without matching '\\begin{" + @@ -1068,12 +1069,12 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, // \| and \Vert are equivalent, and InsetMathDelim // can't handle \| // FIXME: fix this in InsetMathDelim itself! - string const l = tl.cs() == "|" ? "Vert" : tl.asString(); + docstring const l = tl.cs() == "|" ? from_ascii("Vert") : tl.asString(); MathArray ar; parse(ar, FLAG_RIGHT, mode); skipSpaces(); Token const & tr = getToken(); - string const r = tr.cs() == "|" ? "Vert" : tr.asString(); + docstring const r = tr.cs() == "|" ? from_ascii("Vert") : tr.asString(); cell->push_back(MathAtom(new InsetMathDelim(l, r, ar))); } @@ -1086,20 +1087,20 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "begin") { - string const name = getArg('{', '}'); + docstring const name = getArg('{', '}'); environments_.push_back(name); if (name == "array" || name == "subarray") { - string const valign = parse_verbatim_option() + 'c'; - string const halign = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathArray(name, valign[0], halign))); + docstring const valign = parse_verbatim_option() + 'c'; + docstring const halign = parse_verbatim_item(); + cell->push_back(MathAtom(new InsetMathArray(name, (char)valign[0], halign))); parse2(cell->back(), FLAG_END, mode, false); } else if (name == "tabular") { - string const valign = parse_verbatim_option() + 'c'; - string const halign = parse_verbatim_item(); - cell->push_back(MathAtom(new InsetMathTabular(name, valign[0], halign))); + docstring const valign = parse_verbatim_option() + 'c'; + docstring const halign = parse_verbatim_item(); + cell->push_back(MathAtom(new InsetMathTabular(name, (char)valign[0], halign))); parse2(cell->back(), FLAG_END, InsetMath::TEXT_MODE, false); } @@ -1109,10 +1110,10 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (name == "alignedat") { - string const valign = parse_verbatim_option() + 'c'; + docstring const valign = parse_verbatim_option() + 'c'; // ignore this for a while getArg('{', '}'); - cell->push_back(MathAtom(new InsetMathSplit(name, valign[0]))); + cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0]))); parse2(cell->back(), FLAG_END, mode, false); } @@ -1178,8 +1179,8 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, cell->push_back(createInsetMath(name)); parse2(cell->back(), FLAG_END, mode, false); } else if (l->inset == "split") { - string const valign = parse_verbatim_option() + 'c'; - cell->push_back(MathAtom(new InsetMathSplit(name, valign[0]))); + docstring const valign = parse_verbatim_option() + 'c'; + cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0]))); parse2(cell->back(), FLAG_END, mode, false); } else { dump(); @@ -1205,7 +1206,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, #ifdef WITH_WARNINGS #warning A hack... #endif - string s; + docstring s; while (true) { Token const & t = getToken(); if (!good()) { @@ -1213,7 +1214,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, break; } s += t.character(); - if (isValidLength(s)) + if (isValidLength(to_utf8(s))) break; } cell->push_back(MathAtom(new InsetMathKern(s))); @@ -1221,10 +1222,9 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "label") { // FIXME: This is swallowed in inline formulas - string label = parse_verbatim_item(); + docstring label = parse_verbatim_item(); MathArray ar; - // FIXME UNICODE - asArray(from_utf8(label), ar); + asArray(label, ar); if (grid.asHullInset()) { grid.asHullInset()->label(cellrow, label); } else { @@ -1243,14 +1243,14 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "color") { - string const color = parse_verbatim_item(); + docstring const color = parse_verbatim_item(); cell->push_back(MathAtom(new InsetMathColor(true, color))); parse(cell->back().nucleus()->cell(0), flags, mode); return; } else if (t.cs() == "textcolor") { - string const color = parse_verbatim_item(); + docstring const color = parse_verbatim_item(); cell->push_back(MathAtom(new InsetMathColor(false, color))); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE); } @@ -1318,7 +1318,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, if (l) { if (l->inset == "big") { skipSpaces(); - string const delim = getToken().asInput(); + docstring const delim = getToken().asInput(); if (InsetMathBig::isBigInsetDelim(delim)) cell->push_back(MathAtom( new InsetMathBig(t.cs(), delim))); @@ -1400,9 +1400,9 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } // anonymous namespace -void mathed_parse_cell(MathArray & ar, string const & str) +void mathed_parse_cell(MathArray & ar, docstring const & str) { - istringstream is(str); + istringstream is(to_utf8(str)); mathed_parse_cell(ar, is); } diff --git a/src/mathed/MathParser.h b/src/mathed/MathParser.h index 30b274133e..1e4b7b7392 100644 --- a/src/mathed/MathParser.h +++ b/src/mathed/MathParser.h @@ -14,6 +14,7 @@ #define MATH_PARSER_H #include "support/types.h" +#include "support/docstring.h" #include #include @@ -31,34 +32,34 @@ class LyXLex; class latexkeys { public: /// name of the macro or primitive - std::string name; + docstring name; /// name of a inset that handles that macro - std::string inset; - /// position of the ting in a font - std::vector draw; + docstring inset; + /// position of the thing in a font + docstring draw; /// operator/..., fontname e - std::string extra; + docstring extra; /// how is this called as XML entity? - std::string xmlname; + docstring xmlname; /// required LaTeXFeatures - std::string requires; + docstring requires; }; /// check whether this is a well-known (La)TeX macro or primitive -latexkeys const * in_word_set(std::string const & str); +latexkeys const * in_word_set(docstring const & str); /// parse formula from a string -bool mathed_parse_normal(MathAtom &, std::string const &); +bool mathed_parse_normal(MathAtom &, docstring const &); /// ... a stream bool mathed_parse_normal(MathAtom &, std::istream &); /// ... the LyX lexxer bool mathed_parse_normal(MathAtom &, LyXLex &); /// ... the LyX lexxer -void mathed_parse_normal(InsetMathGrid &, std::string const &); +void mathed_parse_normal(InsetMathGrid &, docstring const &); /// parse a single cell from a string -void mathed_parse_cell(MathArray & ar, std::string const &); +void mathed_parse_cell(MathArray & ar, docstring const &); /// ... a stream void mathed_parse_cell(MathArray & ar, std::istream &); diff --git a/src/mathed/MathStream.C b/src/mathed/MathStream.C index f5fb77a42b..a1bdc8efe9 100644 --- a/src/mathed/MathStream.C +++ b/src/mathed/MathStream.C @@ -10,65 +10,459 @@ #include +#include "InsetMath.h" +#include "MathData.h" +#include "MathExtern.h" #include "MathStream.h" -#include "MathMLStream.h" + +#include "support/lyxalgo.h" + + +namespace { + +bool isAlpha(char c) +{ + return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); +} + +} namespace lyx { -using std::string; +using std::strlen; + -WriteStream & operator<<(WriteStream & ws, string const & s) + +////////////////////////////////////////////////////////////////////// + + +NormalStream & operator<<(NormalStream & ns, MathAtom const & at) { - ws << s.c_str(); - return ws; + at->normalize(ns); + return ns; } -NormalStream & operator<<(NormalStream & ns, string const & s) +NormalStream & operator<<(NormalStream & ns, MathArray const & ar) +{ + normalize(ar, ns); + return ns; +} + + +NormalStream & operator<<(NormalStream & ns, docstring const & s) +{ + ns.os() << s; + return ns; +} + + +NormalStream & operator<<(NormalStream & ns, const std::string & s) { - // FIXME UNICODE ns.os() << from_utf8(s); return ns; } -MapleStream & operator<<(MapleStream & ms, string const & s) +NormalStream & operator<<(NormalStream & ns, char const * s) +{ + ns.os() << s; + return ns; +} + + +NormalStream & operator<<(NormalStream & ns, char c) +{ + ns.os() << c; + return ns; +} + + +NormalStream & operator<<(NormalStream & ns, int i) +{ + ns.os() << i; + return ns; +} + + + +///////////////////////////////////////////////////////////////// + + +WriteStream & operator<<(WriteStream & ws, docstring const & s) +{ + ws.os() << s; + return ws; +} + + +WriteStream::WriteStream(odocstream & os, bool fragile, bool latex) + : os_(os), fragile_(fragile), firstitem_(false), latex_(latex), + pendingspace_(false), line_(0) +{} + + +WriteStream::WriteStream(odocstream & os) + : os_(os), fragile_(false), firstitem_(false), latex_(false), + pendingspace_(false), line_(0) +{} + + +WriteStream::~WriteStream() +{ + if (pendingspace_) + os_ << ' '; +} + + +void WriteStream::addlines(unsigned int n) +{ + line_ += n; +} + + +void WriteStream::pendingSpace(bool how) +{ + pendingspace_ = how; +} + + +WriteStream & operator<<(WriteStream & ws, MathAtom const & at) +{ + at->write(ws); + return ws; +} + + +WriteStream & operator<<(WriteStream & ws, MathArray const & ar) +{ + write(ar, ws); + return ws; +} + + +WriteStream & operator<<(WriteStream & ws, char const * s) +{ + if (ws.pendingSpace() && strlen(s) > 0) { + if (isAlpha(s[0])) + ws.os() << ' '; + ws.pendingSpace(false); + } + ws.os() << s; + ws.addlines(int(count(s, s + strlen(s), '\n'))); + return ws; +} + + +WriteStream & operator<<(WriteStream & ws, char c) +{ + if (ws.pendingSpace()) { + if (isAlpha(c)) + ws.os() << ' '; + ws.pendingSpace(false); + } + ws.os() << c; + if (c == '\n') + ws.addlines(1); + return ws; +} + + +WriteStream & operator<<(WriteStream & ws, int i) +{ + ws.os() << i; + return ws; +} + + +WriteStream & operator<<(WriteStream & ws, unsigned int i) +{ + ws.os() << i; + return ws; +} + + +////////////////////////////////////////////////////////////////////// + + +MathStream::MathStream(odocstream & os) + : os_(os), tab_(0), line_(0), lastchar_(0) +{} + + +MathStream & operator<<(MathStream & ms, MathAtom const & at) +{ + at->mathmlize(ms); + return ms; +} + + +MathStream & operator<<(MathStream & ms, MathArray const & ar) { - // FIXME UNICODE - ms.os() << from_utf8(s); + mathmlize(ar, ms); return ms; } -MaximaStream & operator<<(MaximaStream & ms, string const & s) +MathStream & operator<<(MathStream & ms, char const * s) +{ + ms.os() << s; + return ms; +} + + +MathStream & operator<<(MathStream & ms, char c) +{ + ms.os() << c; + return ms; +} + + +MathStream & operator<<(MathStream & ms, MTag const & t) +{ + ++ms.tab(); + ms.cr(); + ms.os() << '<' << t.tag_ << '>'; + return ms; +} + + +MathStream & operator<<(MathStream & ms, ETag const & t) +{ + ms.cr(); + if (ms.tab() > 0) + --ms.tab(); + ms.os() << "'; + return ms; +} + + +void MathStream::cr() +{ + os() << '\n'; + for (int i = 0; i < tab(); ++i) + os() << ' '; +} + + +MathStream & operator<<(MathStream & ms, docstring const & s) +{ + ms.os() << s; + return ms; +} + +////////////////////////////////////////////////////////////////////// + + +MapleStream & operator<<(MapleStream & ms, MathAtom const & at) { - // FIXME UNICODE - ms.os() << from_utf8(s); + at->maple(ms); return ms; } -MathematicaStream & operator<<(MathematicaStream & ms, string const & s) +MapleStream & operator<<(MapleStream & ms, MathArray const & ar) { - // FIXME UNICODE - ms.os() << from_utf8(s); + maple(ar, ms); return ms; } -MathMLStream & operator<<(MathMLStream & ms, string const & s) +MapleStream & operator<<(MapleStream & ms, char const * s) { - // FIXME UNICODE - ms.os() << from_utf8(s); + ms.os() << s; return ms; } -OctaveStream & operator<<(OctaveStream & os, string const & s) +MapleStream & operator<<(MapleStream & ms, char c) +{ + ms.os() << c; + return ms; +} + + +MapleStream & operator<<(MapleStream & ms, int i) +{ + ms.os() << i; + return ms; +} + + +MapleStream & operator<<(MapleStream & ms, char_type c) +{ + ms.os().put(c); + return ms; +} + + +MapleStream & operator<<(MapleStream & ms, docstring const & s) +{ + ms.os() << s; + return ms; +} + + +////////////////////////////////////////////////////////////////////// + + +MaximaStream & operator<<(MaximaStream & ms, MathAtom const & at) +{ + at->maxima(ms); + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, MathArray const & ar) +{ + maxima(ar, ms); + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, char const * s) +{ + ms.os() << s; + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, char c) +{ + ms.os() << c; + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, int i) +{ + ms.os() << i; + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, docstring const & s) +{ + ms.os() << s; + return ms; +} + + +MaximaStream & operator<<(MaximaStream & ms, char_type c) +{ + ms.os().put(c); + return ms; +} + + +////////////////////////////////////////////////////////////////////// + + +MathematicaStream & operator<<(MathematicaStream & ms, MathAtom const & at) +{ + at->mathematica(ms); + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, MathArray const & ar) +{ + mathematica(ar, ms); + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, char const * s) +{ + ms.os() << s; + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, char c) +{ + ms.os() << c; + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, int i) +{ + ms.os() << i; + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, docstring const & s) +{ + ms.os() << s; + return ms; +} + + +MathematicaStream & operator<<(MathematicaStream & ms, char_type c) +{ + ms.os().put(c); + return ms; +} + + +////////////////////////////////////////////////////////////////////// + + +OctaveStream & operator<<(OctaveStream & ns, MathAtom const & at) +{ + at->octave(ns); + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar) +{ + octave(ar, ns); + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, char const * s) +{ + ns.os() << s; + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, char c) +{ + ns.os() << c; + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, int i) +{ + ns.os() << i; + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, docstring const & s) +{ + ns.os() << s; + return ns; +} + + +OctaveStream & operator<<(OctaveStream & ns, char_type c) +{ + ns.os().put(c); + return ns; +} + + +OctaveStream & operator<<(OctaveStream & os, std::string const & s) { - // FIXME UNICODE os.os() << from_utf8(s); return os; } diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 63fb37d7b8..9088db2991 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -9,33 +9,307 @@ * Full author contact details are available in file CREDITS. */ -#ifndef MATH_STREAMSTR_H -#define MATH_STREAMSTR_H +#ifndef MATH_MATHMLSTREAM_H +#define MATH_MATHMLSTREAM_H -#include + +// Please keep all four streams in one file until the interface has +// settled. + + +#include "metricsinfo.h" +#include "support/docstream.h" +#include "support/docstring.h" namespace lyx { -class WriteStream; -class NormalStream; -class MapleStream; -class MaximaStream; -class MathematicaStream; -class MathMLStream; -class OctaveStream; +class MathArray; +class InsetMath; +class MathAtom; + +// +// LaTeX/LyX +// + +class WriteStream { +public: + /// + WriteStream(odocstream & os, bool fragile, bool latex); + /// + explicit WriteStream(odocstream & os); + /// + ~WriteStream(); + /// + int line() const { return line_; } + /// + bool fragile() const { return fragile_; } + /// + bool latex() const { return latex_; } + /// + odocstream & os() { return os_; } + /// + bool & firstitem() { return firstitem_; } + /// + void addlines(unsigned int); + /// writes space if next thing is isalpha() + void pendingSpace(bool how); + /// writes space if next thing is isalpha() + bool pendingSpace() const { return pendingspace_; } +private: + /// + odocstream & os_; + /// do we have to write \\protect sometimes + bool fragile_; + /// are we at the beginning of an MathArray? + bool firstitem_; + /// are we writing to .tex? + int latex_; + /// do we have a space pending? + bool pendingspace_; + /// + int line_; +}; + +/// +WriteStream & operator<<(WriteStream &, MathAtom const &); +/// +WriteStream & operator<<(WriteStream &, MathArray const &); +/// +WriteStream & operator<<(WriteStream &, docstring const &); +/// +WriteStream & operator<<(WriteStream &, char const * const); +/// +WriteStream & operator<<(WriteStream &, char); +/// +WriteStream & operator<<(WriteStream &, int); +/// +WriteStream & operator<<(WriteStream &, unsigned int); + + + +// +// MathML +// + +class MTag { +public: + /// + MTag(docstring const tag) : tag_(tag) {} + /// + MTag(char const * const tag) : tag_(from_ascii(tag)) {} + /// + docstring const tag_; +}; + +class ETag { +public: + /// + ETag(docstring const tag) : tag_(tag) {} + /// + ETag(char const * const tag) : tag_(from_ascii(tag)) {} + /// + docstring const tag_; +}; + +class MathStream { +public: + /// + explicit MathStream(odocstream & os); + /// + void cr(); + /// + odocstream & os() { return os_; } + /// + int line() const { return line_; } + /// + int & tab() { return tab_; } + /// + friend MathStream & operator<<(MathStream &, char const *); +private: + /// + odocstream & os_; + /// + int tab_; + /// + int line_; + /// + char lastchar_; +}; + +/// +MathStream & operator<<(MathStream &, MathAtom const &); +/// +MathStream & operator<<(MathStream &, MathArray const &); +/// +MathStream & operator<<(MathStream &, docstring const &); +/// +MathStream & operator<<(MathStream &, char const *); +/// +MathStream & operator<<(MathStream &, char); +/// +MathStream & operator<<(MathStream &, MTag const &); +/// +MathStream & operator<<(MathStream &, ETag const &); + + // -// writing strings directly +// Debugging // -WriteStream & operator<<(WriteStream & ws, std::string const & s); -NormalStream & operator<<(NormalStream & ns, std::string const & s); -MapleStream & operator<<(MapleStream & ms, std::string const & s); -MaximaStream & operator<<(MaximaStream & ms, std::string const & s); -MathematicaStream & operator<<(MathematicaStream & ms, std::string const & s); -MathMLStream & operator<<(MathMLStream & ms, std::string const & s); -OctaveStream & operator<<(OctaveStream & os, std::string const & s); +class NormalStream { +public: + /// + explicit NormalStream(odocstream & os) : os_(os) {} + /// + odocstream & os() { return os_; } +private: + /// + odocstream & os_; +}; + +/// +NormalStream & operator<<(NormalStream &, MathAtom const &); +/// +NormalStream & operator<<(NormalStream &, MathArray const &); +/// +NormalStream & operator<<(NormalStream &, docstring const &); +/// +NormalStream & operator<<(NormalStream &, char const *); +/// +NormalStream & operator<<(NormalStream &, char); +/// +NormalStream & operator<<(NormalStream &, int); + + +// +// Maple +// + + +class MapleStream { +public: + /// + explicit MapleStream(odocstream & os) : os_(os) {} + /// + odocstream & os() { return os_; } +private: + /// + odocstream & os_; +}; + + +/// +MapleStream & operator<<(MapleStream &, MathAtom const &); +/// +MapleStream & operator<<(MapleStream &, MathArray const &); +/// +MapleStream & operator<<(MapleStream &, docstring const &); +/// +MapleStream & operator<<(MapleStream &, char_type); +/// +MapleStream & operator<<(MapleStream &, char const *); +/// +MapleStream & operator<<(MapleStream &, char); +/// +MapleStream & operator<<(MapleStream &, int); + + +// +// Maxima +// + + +class MaximaStream { +public: + /// + explicit MaximaStream(odocstream & os) : os_(os) {} + /// + odocstream & os() { return os_; } +private: + /// + odocstream & os_; +}; + + +/// +MaximaStream & operator<<(MaximaStream &, MathAtom const &); +/// +MaximaStream & operator<<(MaximaStream &, MathArray const &); +/// +MaximaStream & operator<<(MaximaStream &, docstring const &); +/// +MaximaStream & operator<<(MaximaStream &, char_type); +/// +MaximaStream & operator<<(MaximaStream &, char const *); +/// +MaximaStream & operator<<(MaximaStream &, char); +/// +MaximaStream & operator<<(MaximaStream &, int); + + +// +// Mathematica +// + + +class MathematicaStream { +public: + /// + explicit MathematicaStream(odocstream & os) : os_(os) {} + /// + odocstream & os() { return os_; } +private: + /// + odocstream & os_; +}; + + +/// +MathematicaStream & operator<<(MathematicaStream &, MathAtom const &); +/// +MathematicaStream & operator<<(MathematicaStream &, MathArray const &); +/// +MathematicaStream & operator<<(MathematicaStream &, docstring const &); +/// +MathematicaStream & operator<<(MathematicaStream &, char const *); +/// +MathematicaStream & operator<<(MathematicaStream &, char); +/// +MathematicaStream & operator<<(MathematicaStream &, int); + + +// +// Octave +// + + +class OctaveStream { +public: + /// + explicit OctaveStream(odocstream & os) : os_(os) {} + /// + odocstream & os() { return os_; } +private: + /// + odocstream & os_; +}; + +/// +OctaveStream & operator<<(OctaveStream &, MathAtom const &); +/// +OctaveStream & operator<<(OctaveStream &, MathArray const &); +/// +OctaveStream & operator<<(OctaveStream &, docstring const &); +/// +OctaveStream & operator<<(OctaveStream &, char_type); +/// +OctaveStream & operator<<(OctaveStream &, char const *); +/// +OctaveStream & operator<<(OctaveStream &, char); +/// +OctaveStream & operator<<(OctaveStream &, int); } // namespace lyx diff --git a/src/mathed/MathSupport.C b/src/mathed/MathSupport.C index f03d4597eb..8ae02b1240 100644 --- a/src/mathed/MathSupport.C +++ b/src/mathed/MathSupport.C @@ -14,7 +14,7 @@ #include "MathSupport.h" #include "MathData.h" #include "InsetMath.h" -#include "MathMLStream.h" +#include "MathStream.h" #include "MathParser.h" #include "debug.h" @@ -32,7 +32,6 @@ namespace lyx { using frontend::Painter; -using std::string; using std::max; using std::endl; using std::vector; @@ -339,7 +338,7 @@ named_deco_struct deco_table[] = { }; -std::map deco_list; +std::map deco_list; // sort the table on startup class init_deco_table { @@ -350,7 +349,7 @@ public: deco_struct d; d.data = p->data; d.angle = p->angle; - deco_list[p->name]= d; + deco_list[from_ascii(p->name)] = d; } } }; @@ -358,10 +357,10 @@ public: static init_deco_table dummy; -deco_struct const * search_deco(string const & name) +deco_struct const * search_deco(docstring const & name) { - std::map::const_iterator p = deco_list.find(name); - return (p == deco_list.end()) ? 0 : &(p->second); + std::map::const_iterator p = deco_list.find(name); + return p == deco_list.end() ? 0 : &(p->second); } @@ -384,13 +383,13 @@ int mathed_char_width(LyXFont const & font, char_type c) void mathed_string_dim(LyXFont const & font, - vector const & s, + docstring const & s, Dimension & dim) { frontend::FontMetrics const & fm = theFontMetrics(font); dim.asc = 0; dim.des = 0; - for (vector::const_iterator it = s.begin(); + for (docstring::const_iterator it = s.begin(); it != s.end(); ++it) { dim.asc = max(dim.asc, fm.ascent(*it)); @@ -407,7 +406,7 @@ int mathed_string_width(LyXFont const & font, docstring const & s) void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h, - string const & name) + docstring const & name) { if (name == ".") { pi.pain.line(x + w/2, y, x + w/2, y + h, @@ -418,7 +417,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h, deco_struct const * mds = search_deco(name); if (!mds) { lyxerr << "Deco was not found. Programming error?" << endl; - lyxerr << "name: '" << name << "'" << endl; + lyxerr << "name: '" << to_utf8(name) << "'" << endl; return; } @@ -501,7 +500,7 @@ void math_font_max_dim(LyXFont const & font, int & asc, int & des) struct fontinfo { - string cmd_; + std::string cmd_; LyXFont::FONT_FAMILY family_; LyXFont::FONT_SERIES series_; LyXFont::FONT_SHAPE shape_; @@ -601,10 +600,11 @@ fontinfo fontinfos[] = { }; -fontinfo * lookupFont(string const & name) +fontinfo * lookupFont(docstring const & name0) { //lyxerr << "searching font '" << name << "'" << endl; int const n = sizeof(fontinfos) / sizeof(fontinfo); + std::string name = to_utf8(name0); for (int i = 0; i < n; ++i) if (fontinfos[i].cmd_ == name) { //lyxerr << "found '" << i << "'" << endl; @@ -614,7 +614,7 @@ fontinfo * lookupFont(string const & name) } -fontinfo * searchFont(string const & name) +fontinfo * searchFont(docstring const & name) { fontinfo * f = lookupFont(name); return f ? f : fontinfos; @@ -623,13 +623,13 @@ fontinfo * searchFont(string const & name) } -bool isFontName(string const & name) +bool isFontName(docstring const & name) { return lookupFont(name); } -LyXFont getFont(string const & name) +LyXFont getFont(docstring const & name) { LyXFont font; augmentFont(font, name); @@ -637,7 +637,7 @@ LyXFont getFont(string const & name) } -void fakeFont(string const & orig, string const & fake) +void fakeFont(docstring const & orig, docstring const & fake) { fontinfo * forig = searchFont(orig); fontinfo * ffake = searchFont(fake); @@ -647,22 +647,22 @@ void fakeFont(string const & orig, string const & fake) forig->shape_ = ffake->shape_; forig->color_ = ffake->color_; } else { - lyxerr << "Can't fake font '" << orig << "' with '" - << fake << "'" << endl; + lyxerr << "Can't fake font '" << to_utf8(orig) << "' with '" + << to_utf8(fake) << "'" << endl; } } -void augmentFont(LyXFont & font, string const & name) +void augmentFont(LyXFont & font, docstring const & name) { static bool initialized = false; if (!initialized) { initialized = true; // fake fonts if necessary - if (!theFontLoader().available(getFont("mathfrak"))) - fakeFont("mathfrak", "lyxfakefrak"); - if (!theFontLoader().available(getFont("mathcal"))) - fakeFont("mathcal", "lyxfakecal"); + if (!theFontLoader().available(getFont(from_ascii("mathfrak")))) + fakeFont(from_ascii("mathfrak"), from_ascii("lyxfakefrak")); + if (!theFontLoader().available(getFont(from_ascii("mathcal")))) + fakeFont(from_ascii("mathcal"), from_ascii("lyxfakecal")); } fontinfo * info = searchFont(name); if (info->family_ != inh_family) @@ -676,39 +676,36 @@ void augmentFont(LyXFont & font, string const & name) } -string asString(MathArray const & ar) +docstring asString(MathArray const & ar) { odocstringstream os; WriteStream ws(os); ws << ar; - // FIXME UNICODE - return to_utf8(os.str()); + return os.str(); } void asArray(docstring const & str, MathArray & ar) { - mathed_parse_cell(ar, to_utf8(str)); + mathed_parse_cell(ar, str); } -string asString(InsetMath const & inset) +docstring asString(InsetMath const & inset) { odocstringstream os; WriteStream ws(os); inset.write(ws); - // FIXME UNICODE - return to_utf8(os.str()); + return os.str(); } -string asString(MathAtom const & at) +docstring asString(MathAtom const & at) { odocstringstream os; WriteStream ws(os); at->write(ws); - // FIXME UNICODE - return to_utf8(os.str()); + return os.str(); } diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index ad2d1fe117..a1396e2338 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -32,10 +32,10 @@ void mathed_char_dim(LyXFont const &, char_type c, Dimension & dim); int mathed_char_width(LyXFont const &, char_type c); void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h, - std::string const & name); + docstring const & name); void mathed_string_dim(LyXFont const & font, - std::vector const & s, + docstring const & s, Dimension & dim); int mathed_string_width(LyXFont const &, docstring const & s); @@ -45,19 +45,18 @@ void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & s); void math_font_max_dim(LyXFont const &, int & asc, int & desc); -void augmentFont(LyXFont & f, std::string const & cmd); +void augmentFont(LyXFont & f, docstring const & cmd); -bool isFontName(std::string const & name); +bool isFontName(docstring const & name); // converts single cell to string -std::string asString(MathArray const & ar); +docstring asString(MathArray const & ar); // converts single inset to string -std::string asString(InsetMath const &); -std::string asString(MathAtom const &); +docstring asString(InsetMath const &); +docstring asString(MathAtom const &); // converts string to single cell void asArray(docstring const & str, MathArray & ar); - } // namespace lyx #endif diff --git a/src/metricsinfo.C b/src/metricsinfo.C index ccd72404c3..9544e68883 100644 --- a/src/metricsinfo.C +++ b/src/metricsinfo.C @@ -163,6 +163,18 @@ FontSetChanger::FontSetChanger(MetricsBase & mb, char const * name) LyXFont::FONT_SIZE oldsize = save_.font.size(); mb.fontname = name; mb.font = LyXFont(); + augmentFont(mb.font, from_ascii(name)); + mb.font.setSize(oldsize); +} + + +FontSetChanger::FontSetChanger(MetricsBase & mb, docstring const & name) + : Changer(mb) +{ + save_ = mb; + LyXFont::FONT_SIZE oldsize = save_.font.size(); + mb.fontname = to_utf8(name); + mb.font = LyXFont(); augmentFont(mb.font, name); mb.font.setSize(oldsize); } diff --git a/src/metricsinfo.h b/src/metricsinfo.h index 5c6e81c1c9..840944548e 100644 --- a/src/metricsinfo.h +++ b/src/metricsinfo.h @@ -14,6 +14,7 @@ #include "lyxfont.h" #include "support/docstring.h" +#include class BufferView; @@ -140,7 +141,8 @@ protected: class FontChanger : public Changer { public: /// - FontChanger(LyXFont & orig, char const * font); + FontChanger(LyXFont & orig, docstring const & font); + FontChanger(MetricsBase & mb, char const * const font); /// ~FontChanger(); }; @@ -150,7 +152,8 @@ public: class FontSetChanger : public Changer { public: /// - FontSetChanger(MetricsBase & mb, char const * font); + FontSetChanger(MetricsBase & mb, docstring const & font); + FontSetChanger(MetricsBase & mb, char const * const font); /// ~FontSetChanger(); }; diff --git a/src/paragraph.C b/src/paragraph.C index 1bd903930a..23d7d11404 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -247,7 +247,7 @@ int Paragraph::erase(pos_type start, pos_type end, bool trackChanges) } -void Paragraph::insert(pos_type start, string const & str, +void Paragraph::insert(pos_type start, docstring const & str, LyXFont const & font, Change const & change) { for (size_t i = 0, n = str.size(); i != n ; ++i) @@ -655,8 +655,8 @@ void Paragraph::setBeginOfBody() pos_type end = size(); if (i < end && !isNewline(i)) { ++i; - char previous_char = 0; - char temp = 0; + char_type previous_char = 0; + char_type temp = 0; if (i < end) { previous_char = text_[i]; if (!isNewline(i)) { diff --git a/src/paragraph.h b/src/paragraph.h index 6afb9fa106..7bb6e96ea0 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -286,7 +286,7 @@ public: LyXFont_size highestFontInRange(pos_type startpos, pos_type endpos, LyXFont_size def_size) const; /// - void insert(pos_type pos, std::string const & str, + void insert(pos_type pos, docstring const & str, LyXFont const & font, Change const & change); /// void insertChar(pos_type pos, value_type c, bool trackChanges); diff --git a/src/rowpainter.C b/src/rowpainter.C index 899e86d0fc..4f0fecfa22 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -767,10 +767,10 @@ size_type calculateRowSignature(Row const & row, Paragraph const & par, { boost::crc_32_type crc; for (pos_type i = row.pos(); i < row.endpos(); ++i) { - const unsigned char b[] = { par.getChar(i) }; + char_type const b[] = { par.getChar(i) }; crc.process_bytes(b, 1); } - const unsigned char b[] = { x, y, row.width() }; + char_type const b[] = { x, y, row.width() }; crc.process_bytes(b, 3); return crc.checksum(); } diff --git a/src/sgml.h b/src/sgml.h index 055f8638d5..8c60e24bc8 100644 --- a/src/sgml.h +++ b/src/sgml.h @@ -59,7 +59,7 @@ void closeTag(odocstream & os, std::string const & name); /// Close tag void closeTag(odocstream & os, Paragraph const & par); - +} // namespace sgml } // namespace lyx -} + #endif // SGML_H diff --git a/src/support/docstring.h b/src/support/docstring.h index db2ba9974f..629d77e21f 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -72,7 +72,7 @@ lyx::docstring & operator+=(lyx::docstring & l, char r); #if SIZEOF_WCHAR_T != 4 && defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn. -namespace std { +namespace std {$ template void char_traits::assign(char_type & c1, char_type const & c2) diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 6d5f796ea8..a844f2214b 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -558,19 +558,26 @@ string const rtrim(string const & a, char const * p) string const ltrim(string const & a, char const * p) { BOOST_ASSERT(p); - if (a.empty() || !*p) return a; - string::size_type l = a.find_first_not_of(p); - if (l == string::npos) return string(); - return a.substr(l, string::npos); } +docstring const ltrim(docstring const & a, char const * p) +{ + BOOST_ASSERT(p); + if (a.empty() || !*p) + return a; + size_t l = a.find_first_not_of(from_ascii(p)); + if (l == docstring::npos) + return docstring(); + return a.substr(l, docstring::npos); +} + namespace { template inline diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 0f10743b03..74622aeacd 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -100,14 +100,22 @@ bool suffixIs(std::string const &, char); bool suffixIs(std::string const &, std::string const &); /// -template -bool contains(std::string const & a, B b) +inline bool contains(std::string const & a, std::string const & b) { return a.find(b) != std::string::npos; } -template -bool contains(docstring const & a, B b) +inline bool contains(docstring const & a, docstring const & b) +{ + return a.find(b) != docstring::npos; +} + +inline bool contains(std::string const & a, char b) +{ + return a.find(b) != std::string::npos; +} + +inline bool contains(docstring const & a, char_type b) { return a.find(b) != docstring::npos; } @@ -173,13 +181,15 @@ std::string const trim(std::string const & a, char const * p = " "); \endcode */ std::string const rtrim(std::string const & a, char const * p = " "); +docstring const rtrim(docstring const & a, char const * p = " "); /** Trims characters off the beginning of a string. \code - ltrim("ababcdef", "ab") = "cdef" + ("ababcdef", "ab") = "cdef" \endcode */ std::string const ltrim(std::string const & a, char const * p = " "); +docstring const ltrim(docstring const & a, char const * p = " "); /** Splits the string by the first delim. Splits the string by the first appearance of delim. diff --git a/src/text.C b/src/text.C index e0bd609b05..8d1b5187ac 100644 --- a/src/text.C +++ b/src/text.C @@ -2448,13 +2448,11 @@ string LyXText::getPossibleLabel(LCursor & cur) const // for captions, we want the abbreviation of the float type if (layout->labeltype == LABEL_SENSITIVE) { // Search for the first float or wrap inset in the iterator - size_t i = cur.depth(); - while (i > 0) { - --i; + for (int i = cur.depth(); --i >= 0; ) { InsetBase * const in = &cur[i].inset(); if (in->lyxCode() == InsetBase::FLOAT_CODE || in->lyxCode() == InsetBase::WRAP_CODE) { - name = in->getInsetName(); + name = to_utf8(in->getInsetName()); break; } } diff --git a/src/text3.C b/src/text3.C index d0e57a3e38..4dc9fb87e5 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1209,7 +1209,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) int const nargs = s1.empty() ? 0 : convert(s1); string const s2 = token(s, ' ', 2); string const type = s2.empty() ? "newcommand" : s2; - cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, type)); + cur.insert(new MathMacroTemplate(from_utf8(token(s, ' ', 0)), nargs, from_utf8(type))); //cur.nextInset()->edit(cur, true); } break; diff --git a/src/undo.C b/src/undo.C index 915e3e9a99..fa377c3e54 100644 --- a/src/undo.C +++ b/src/undo.C @@ -96,7 +96,7 @@ void doRecordUndo(Undo::undo_kind kind, // fill in the real data to be saved if (cell.inMathed()) { // simply use the whole cell - undo.array = asString(cell.cell()); + undo.array = to_utf8(asString(cell.cell())); } else { // some more effort needed here as 'the whole cell' of the // main LyXText _is_ the whole document. -- 2.39.5