From: Georg Baum Date: Wed, 11 Oct 2006 19:40:50 +0000 (+0000) Subject: Introduce wide streams. This fixes the remaining problems of plain text X-Git-Tag: 1.6.10~12412 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=34b7650cbbe6a9ed2de812e75771451b8c8fe983;p=lyx.git Introduce wide streams. This fixes the remaining problems of plain text export (e.g. the ToC) and the navigate menu. * src/insets/insetbase.h (InsetBase::plaintext): output to a docstream (InsetBase::textString): ditto * src/mathed/TextPainter.h (TextPainter::show): ditto * src/support/docstream.[Ch] New file and string streams for docstring. The file streams convert to UTF8 on the fly. * many more files: Adjust to the changes above git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15301 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 1cdaee1103..fc4ca8fb46 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -96,6 +96,7 @@ src_support_header_files = Split(''' copied_ptr.h cow_ptr.h debugstream.h + docstream.h docstring.h environment.h filefilterlist.h @@ -134,6 +135,7 @@ src_support_files = Split(''' chdir.C convert.C copy.C + docstream.C docstring.C environment.C filefilterlist.C diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 20c3f85bd8..2a5b52b9fb 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -48,6 +48,7 @@ #include +using lyx::docstring; using lyx::pos_type; using lyx::pit_type; using lyx::textclass_type; @@ -456,9 +457,9 @@ void switchBetweenClasses(textclass_type c1, textclass_type c2, } -std::vector const availableSelections(Buffer const & buffer) +std::vector const availableSelections(Buffer const & buffer) { - vector selList; + vector selList; CutStack::const_iterator cit = theCuts.begin(); CutStack::const_iterator end = theCuts.end(); @@ -466,13 +467,14 @@ std::vector const availableSelections(Buffer const & buffer) // we do not use cit-> here because gcc 2.9x does not // like it (JMarc) ParagraphList const & pars = (*cit).first; - string asciiSel; + docstring asciiSel; ParagraphList::const_iterator pit = pars.begin(); ParagraphList::const_iterator pend = pars.end(); for (; pit != pend; ++pit) { asciiSel += pit->asString(buffer, false); if (asciiSel.size() > 25) { - asciiSel.replace(22, string::npos, "..."); + asciiSel.replace(22, docstring::npos, + lyx::from_ascii("...")); break; } } @@ -614,11 +616,11 @@ void copySelection(LCursor & cur) } -std::string getSelection(Buffer const & buf, size_t sel_index) +docstring getSelection(Buffer const & buf, size_t sel_index) { return sel_index < theCuts.size() ? theCuts[sel_index].first.back().asString(buf, false) - : string(); + : docstring(); } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 10e5a80c3d..0b09ca8df2 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -16,9 +16,8 @@ #include "ParagraphList_fwd.h" -#include "support/types.h" +#include "support/docstring.h" -#include #include class Buffer; @@ -32,11 +31,11 @@ namespace lyx { namespace cap { /// -std::vector const availableSelections(Buffer const & buffer); +std::vector const availableSelections(Buffer const & buffer); /// lyx::size_type numberOfSelections(); /// -std::string getSelection(Buffer const & buffer, size_t sel_index); +lyx::docstring getSelection(Buffer const & buffer, size_t sel_index); /// void cutSelection(LCursor & cur, bool doclear, bool realcut); diff --git a/src/MenuBackend.C b/src/MenuBackend.C index c099129f15..9bf73f7008 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -417,9 +417,9 @@ public: } }; -string const limit_string_length(string const & str) +docstring const limit_string_length(docstring const & str) { - string::size_type const max_item_length = 45; + docstring::size_type const max_item_length = 45; if (str.size() > max_item_length) return str.substr(0, max_item_length - 3) + "..."; @@ -436,7 +436,7 @@ void expandLastfiles(Menu & tomenu) int ii = 1; for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) { - docstring const label = convert(ii) + lyx::from_ascii(". ") + docstring const label = convert(ii) + ". " + makeDisplayPath((*lfit), 30) + char_type('|') + convert(ii); tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit)))); @@ -461,7 +461,7 @@ void expandDocuments(Menu & tomenu) for (; docit != end; ++docit, ++ii) { docstring label = makeDisplayPath(*docit, 20); if (ii < 10) - label = convert(ii) + lyx::from_ascii(". ") + label + char_type('|') + convert(ii); + label = convert(ii) + ". " + label + char_type('|') + convert(ii); tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BUFFER_SWITCH, *docit))); } } @@ -512,7 +512,7 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf) label = _("Plain Text as Lines"); else if ((*fit)->name() == "textparagraph") label = _("Plain Text as Paragraphs"); - label += lyx::from_ascii("..."); + label += "..."; break; case MenuItem::ViewFormats: case MenuItem::ExportFormats: @@ -623,7 +623,7 @@ void expandToc2(Menu & tomenu, if (to - from <= max_number_of_items) { for (lyx::toc::Toc::size_type i = from; i < to; ++i) { docstring label(4 * max(0, toc_list[i].depth() - depth), char_type(' ')); - label += lyx::from_utf8(limit_string_length(toc_list[i].str())); + label += limit_string_length(toc_list[i].str()); if (toc_list[i].depth() == depth && shortcut_count < 9) { if (label.find(convert(shortcut_count + 1)) != docstring::npos) @@ -641,12 +641,12 @@ void expandToc2(Menu & tomenu, ++new_pos; docstring label(4 * max(0, toc_list[pos].depth() - depth), ' '); - label += lyx::from_utf8(limit_string_length(toc_list[pos].str())); + label += limit_string_length(toc_list[pos].str()); if (toc_list[pos].depth() == depth && shortcut_count < 9) { if (label.find(convert(shortcut_count + 1)) != docstring::npos) label += char_type('|') + convert(++shortcut_count); - } + } if (new_pos == pos + 1) { tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(toc_list[pos].action()))); @@ -691,7 +691,7 @@ void expandToc(Menu & tomenu, Buffer const * buf) lyx::toc::Toc::const_iterator ccit = cit->second.begin(); lyx::toc::Toc::const_iterator eend = cit->second.end(); for (; ccit != eend; ++ccit) { - docstring const label = lyx::from_utf8(limit_string_length(ccit->str())); + docstring const label = limit_string_length(ccit->str()); menu->add(MenuItem(MenuItem::Command, label, FuncRequest(ccit->action()))); @@ -719,14 +719,14 @@ void expandPasteRecent(Menu & tomenu, Buffer const * buf) if (!buf) return; - vector const sel = + vector const sel = lyx::cap::availableSelections(*buf); - vector::const_iterator cit = sel.begin(); - vector::const_iterator end = sel.end(); + vector::const_iterator cit = sel.begin(); + vector::const_iterator end = sel.end(); for (unsigned int index = 0; cit != end; ++cit, ++index) { - tomenu.add(MenuItem(MenuItem::Command, lyx::from_utf8(*cit), + tomenu.add(MenuItem(MenuItem::Command, *cit, FuncRequest(LFUN_PASTE, convert(index)))); } } @@ -745,7 +745,7 @@ void expandBranches(Menu & tomenu, Buffer const * buf) for (int ii = 1; cit != end; ++cit, ++ii) { docstring label = lyx::from_utf8(cit->getBranch()); if (ii < 10) - label = convert(ii) + lyx::from_ascii(". ") + label + char_type('|') + convert(ii); + label = convert(ii) + ". " + label + char_type('|') + convert(ii); tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BRANCH_INSERT, cit->getBranch()))); diff --git a/src/TocBackend.C b/src/TocBackend.C index ad885cdf80..d7eb1250b8 100644 --- a/src/TocBackend.C +++ b/src/TocBackend.C @@ -33,6 +33,8 @@ #include +using lyx::docstring; + using std::vector; using std::max; using std::ostream; @@ -46,7 +48,7 @@ namespace lyx { // TocBackend::Item implementation TocBackend::Item::Item(ParConstIterator const & par_it, int d, - std::string const & s) + docstring const & s) : par_it_(par_it), depth_(d), str_(s) { /* @@ -96,15 +98,15 @@ int const TocBackend::Item::depth() const } -std::string const & TocBackend::Item::str() const +docstring const & TocBackend::Item::str() const { return str_; } -string const TocBackend::Item::asString() const +docstring const TocBackend::Item::asString() const { - return string(4 * depth_, ' ') + str_; + return docstring(4 * depth_, ' ') + str_; } @@ -163,7 +165,7 @@ void TocBackend::update() for (; pit != end; ++pit) { // the string that goes to the toc (could be the optarg) - string tocstring; + docstring tocstring; // For each paragraph, traverse its insets and look for // FLOAT_CODE or WRAP_CODE @@ -184,8 +186,9 @@ void TocBackend::update() break; Paragraph const & par = *static_cast(it->inset)->paragraphs().begin(); if (!pit->getLabelstring().empty()) - tocstring = pit->getLabelstring() - + ' '; + // FIXME UNICODE + tocstring = lyx::from_utf8( + pit->getLabelstring() + ' '); tocstring += par.asString(*buffer_, false); break; } @@ -245,7 +248,7 @@ TocBackend::TocIterator const TocBackend::item(std::string const & type, ParCons } -void TocBackend::asciiTocList(string const & type, ostream & os) const +void TocBackend::asciiTocList(string const & type, lyx::odocstream & os) const { TocList::const_iterator cit = tocs_.find(type); if (cit != tocs_.end()) { diff --git a/src/TocBackend.h b/src/TocBackend.h index 1c7308dc4e..a2643e82ad 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -51,7 +51,7 @@ public: Item( ParConstIterator const & par_it = ParConstIterator(), int d = -1, - std::string const & s = std::string()); + lyx::docstring const & s = lyx::docstring()); /// ~Item() {} /// @@ -61,9 +61,9 @@ public: /// int const depth() const; /// - std::string const & str() const; + lyx::docstring const & str() const; /// - std::string const asString() const; + lyx::docstring const asString() const; /// set cursor in LyXView to this Item void goTo(LyXView & lv_) const; /// the action corresponding to the goTo above @@ -77,7 +77,7 @@ public: int depth_; /// Full item string - std::string str_; + lyx::docstring str_; }; /// @@ -109,7 +109,7 @@ public: /// Return the first Toc Item before the cursor TocIterator const item(std::string const & type, ParConstIterator const &); - void asciiTocList(std::string const & type, std::ostream & os) const; + void asciiTocList(std::string const & type, lyx::odocstream & os) const; private: /// diff --git a/src/cursor.C b/src/cursor.C index fb66b06f54..a2990d05be 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -1129,10 +1129,10 @@ docstring LCursor::selectionAsString(bool label) const size_t const endpos = selEnd().pos(); if (startpit == endpit) - return lyx::from_utf8(pars[startpit].asString(buffer, startpos, endpos, label)); + return pars[startpit].asString(buffer, startpos, endpos, label); // First paragraph in selection - string result = pars[startpit]. + docstring result = pars[startpit]. asString(buffer, startpos, pars[startpit].size(), label) + "\n\n"; // The paragraphs in between (if any) @@ -1144,7 +1144,7 @@ docstring LCursor::selectionAsString(bool label) const // Last paragraph in selection result += pars[endpit].asString(buffer, 0, endpos, label); - return lyx::from_utf8(result); + return result; } if (inMathed()) diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 9598c5fbe1..5199a14f0f 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -347,7 +347,7 @@ void LyXView::updateWindowTitle() if (view()->buffer()) { string const cur_title = buffer()->fileName(); if (!cur_title.empty()) { - maximize_title += lyx::from_ascii(": ") + makeDisplayPath(cur_title, 30); + maximize_title += ": " + makeDisplayPath(cur_title, 30); minimize_title = lyx::from_utf8(onlyFilename(cur_title)); if (!buffer()->isClean()) { maximize_title += _(" (changed)"); diff --git a/src/frontends/gtk/GToc.C b/src/frontends/gtk/GToc.C index 417ddb186b..5486c748c3 100644 --- a/src/frontends/gtk/GToc.C +++ b/src/frontends/gtk/GToc.C @@ -157,7 +157,7 @@ void GToc::updateContents() for (int rowindex = 0; cit != end; ++cit, ++rowindex) { Gtk::ListStore::iterator row = tocstore_->append(); - (*row)[listCol_] = cit->asString(); + (*row)[listCol_] = lyx::to_utf8(cit->asString()); (*row)[listColIndex_] = rowindex; } changing_views_ = false; diff --git a/src/frontends/qt3/QToc.C b/src/frontends/qt3/QToc.C index 0d35533166..d189a4c0db 100644 --- a/src/frontends/qt3/QToc.C +++ b/src/frontends/qt3/QToc.C @@ -154,7 +154,7 @@ void QToc::updateToc(int newdepth) lyxerr[Debug::GUI] << "Table of contents\n" - << "Added item " << iter->str() + << "Added item " << lyx::to_utf8(iter->str()) << " at depth " << iter->depth() << ", previous sibling \"" << (last ? fromqstr(last->text(0)) : "0") @@ -193,8 +193,10 @@ bool QToc::canOutline() } -void QToc::select(string const & text) +void QToc::select(string const & t) { + // FIXME UNICODE + docstring const text = lyx::from_utf8(t); toc::Toc::const_iterator iter = toclist.begin(); for (; iter != toclist.end(); ++iter) { @@ -204,7 +206,7 @@ void QToc::select(string const & text) if (iter == toclist.end()) { lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry: " - << text << endl; + << t << endl; return; } diff --git a/src/frontends/qt3/QToc.h b/src/frontends/qt3/QToc.h index 769bc9a766..0d828d2549 100644 --- a/src/frontends/qt3/QToc.h +++ b/src/frontends/qt3/QToc.h @@ -69,7 +69,7 @@ private: int depth_; /// Store selected item's string - std::string text_; + lyx::docstring text_; /// Store ToC list type std::string type_; diff --git a/src/frontends/qt4/QToc.C b/src/frontends/qt4/QToc.C index 4d3b332ced..57965fb538 100644 --- a/src/frontends/qt4/QToc.C +++ b/src/frontends/qt4/QToc.C @@ -99,7 +99,7 @@ void QToc::goTo(QModelIndex const & index) TocIterator const it = toc_models_[type_]->tocIterator(index); lyxerr[Debug::GUI] - << "QToc::goTo " << it->str() + << "QToc::goTo " << lyx::to_utf8(it->str()) << endl; it->goTo(kernel().lyxview()); diff --git a/src/frontends/qt4/TocModel.C b/src/frontends/qt4/TocModel.C index 72fce8f1a6..570631cf2a 100644 --- a/src/frontends/qt4/TocModel.C +++ b/src/frontends/qt4/TocModel.C @@ -101,7 +101,7 @@ void TocModel::populate(TocBackend::Toc const & toc) lyxerr[Debug::GUI] << "Toc: at depth " << iter->depth() - << ", added item " << iter->str() + << ", added item " << lyx::to_utf8(iter->str()) << endl; populate(iter, end, top_level_item); diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 9551300a6f..7cef1778c8 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -221,7 +221,7 @@ bool InsetBase::idxUpDown(LCursor &, bool) const int InsetBase::plaintext(Buffer const &, - std::ostream &, OutputParams const &) const + lyx::odocstream &, OutputParams const &) const { return 0; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 62ec6a5025..08232c3e4b 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -12,10 +12,9 @@ #ifndef INSETBASE_H #define INSETBASE_H -#include "support/docstring.h" +#include "support/docstream.h" #include -#include #include class Buffer; @@ -186,14 +185,14 @@ public: /// describe content if cursor behind virtual void infoize2(std::ostream &) const {} - /// plain ascii output - virtual int plaintext(Buffer const &, std::ostream & os, + /// plain text output in ucs4 encoding + virtual int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// docbook output virtual int docbook(Buffer const &, std::ostream & os, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream &, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const { return 0; }; /** This enum indicates by which means the inset can be modified: diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index f81d02e456..e40cf50808 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -114,18 +114,23 @@ void InsetBibitem::read(Buffer const &, LyXLex & lex) } -string const InsetBibitem::getBibLabel() const +docstring const InsetBibitem::getBibLabel() const { - return getOptions().empty() ? convert(counter) : getOptions(); + // FIXME UNICODE + return getOptions().empty() ? + convert(counter) : + lyx::from_utf8(getOptions()); } -string const InsetBibitem::getScreenLabel(Buffer const &) const +docstring const InsetBibitem::getScreenLabel(Buffer const &) const { - return getContents() + " [" + getBibLabel() + ']'; + // FIXME UNICODE + return lyx::from_utf8(getContents()) + " [" + getBibLabel() + ']'; } -int InsetBibitem::plaintext(Buffer const &, ostream & os, + +int InsetBibitem::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << '[' << getCounter() << "] "; @@ -134,7 +139,7 @@ int InsetBibitem::plaintext(Buffer const &, ostream & os, // ale070405 -string const bibitemWidest(Buffer const & buffer) +docstring const bibitemWidest(Buffer const & buffer) { int w = 0; // Does look like a hack? It is! (but will change at 0.13) @@ -149,11 +154,10 @@ string const bibitemWidest(Buffer const & buffer) for (; it != end; ++it) { if (it->bibitem()) { - string const label = it->bibitem()->getBibLabel(); - docstring const dlab(label.begin(), label.end()); + docstring const label = it->bibitem()->getBibLabel(); int const wx = - fm.width(dlab); + fm.width(label); if (wx > w) { w = wx; bitem = it->bibitem(); @@ -164,5 +168,5 @@ string const bibitemWidest(Buffer const & buffer) if (bitem && !bitem->getBibLabel().empty()) return bitem->getBibLabel(); - return "99"; + return lyx::from_ascii("99"); } diff --git a/src/insets/insetbibitem.h b/src/insets/insetbibitem.h index 250b8f3c08..d98ae8f8a2 100644 --- a/src/insets/insetbibitem.h +++ b/src/insets/insetbibitem.h @@ -31,7 +31,7 @@ public: /// void read(Buffer const &, LyXLex & lex); /// - virtual std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -43,9 +43,9 @@ public: /// int getCounter() const { return counter; } /// - std::string const getBibLabel() const; + lyx::docstring const getBibLabel() const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; protected: /// @@ -61,6 +61,6 @@ private: /// Return the widest label in the Bibliography. -std::string const bibitemWidest(Buffer const &); +lyx::docstring const bibitemWidest(Buffer const &); #endif // INSET_BIBITEM_H diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 7f5e2dc84c..13e0cc7824 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -36,6 +36,7 @@ #include #include +using lyx::docstring; using lyx::support::absolutePath; using lyx::support::ascii_lowercase; using lyx::support::changeExtension; @@ -102,10 +103,9 @@ void InsetBibtex::doDispatch(LCursor & cur, FuncRequest & cmd) } -string const InsetBibtex::getScreenLabel(Buffer const &) const +docstring const InsetBibtex::getScreenLabel(Buffer const &) const { - // FIXME UNICODE - return lyx::to_utf8(_("BibTeX Generated Bibliography")); + return _("BibTeX Generated Bibliography"); } diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 4daf8f589f..09ba9816f8 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -23,7 +23,7 @@ public: /// InsetBibtex(InsetCommandParams const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index e570d456b8..c87311d5e0 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -381,7 +381,7 @@ int InsetBox::docbook(Buffer const & buf, std::ostream & os, } -int InsetBox::plaintext(Buffer const & buf, std::ostream & os, +int InsetBox::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { BoxType const btype = boxtranslator().find(params_.type); diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h index 577878c752..c3ff251896 100644 --- a/src/insets/insetbox.h +++ b/src/insets/insetbox.h @@ -88,7 +88,7 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 0948e52f08..fd3932db64 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -236,7 +236,7 @@ int InsetBranch::docbook(Buffer const & buf, std::ostream & os, } -int InsetBranch::plaintext(Buffer const & buf, std::ostream & os, +int InsetBranch::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { return isBranchSelected(buf) ? diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index 490e02b73a..65e2310fb6 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -59,7 +59,7 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const & runparams) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 3b8818faaa..0638430c70 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -191,7 +191,7 @@ int InsetCaption::latex(Buffer const & buf, ostream & os, } -int InsetCaption::plaintext(Buffer const & /*buf*/,ostream & /*os*/, +int InsetCaption::plaintext(Buffer const & /*buf*/, lyx::odocstream & /*os*/, OutputParams const & /*runparams*/) const { // FIXME: Implement me! diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 19e564be2c..3b57d832c8 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -51,7 +51,7 @@ public: virtual int latex(Buffer const & buf, std::ostream & os, OutputParams const &) const; /// - int plaintext(Buffer const & buf, std::ostream & os, + int plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const; /// int docbook(Buffer const & buf, std::ostream & os, diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index d509beb1ea..88039d9898 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -306,14 +306,14 @@ int InsetCharStyle::docbook(Buffer const & buf, ostream & os, } -int InsetCharStyle::plaintext(Buffer const & buf, ostream & os, +int InsetCharStyle::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { return InsetText::plaintext(buf, os, runparams); } -int InsetCharStyle::textString(Buffer const & buf, ostream & os, +int InsetCharStyle::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetcharstyle.h b/src/insets/insetcharstyle.h index 23b27a3e3c..92583eea9f 100644 --- a/src/insets/insetcharstyle.h +++ b/src/insets/insetcharstyle.h @@ -77,10 +77,10 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 7cf1151a5a..1d8a16cf4b 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -30,6 +30,7 @@ #include #include +using lyx::docstring; using lyx::support::ascii_lowercase; using lyx::support::contains; using lyx::support::getStringFromVector; @@ -305,7 +306,7 @@ InsetCitation::InsetCitation(InsetCommandParams const & p) {} -string const InsetCitation::generateLabel(Buffer const & buffer) const +docstring const InsetCitation::generateLabel(Buffer const & buffer) const { string const before = getSecOptions(); string const after = getOptions(); @@ -322,11 +323,12 @@ string const InsetCitation::generateLabel(Buffer const & buffer) const label = getBasicLabel(getContents(), after); } - return label; + // FIXME UNICODE + return lyx::from_utf8(label); } -string const InsetCitation::getScreenLabel(Buffer const & buffer) const +docstring const InsetCitation::getScreenLabel(Buffer const & buffer) const { biblio::CiteEngine const engine = biblio::getEngine(buffer); if (cache.params == params() && cache.engine == engine) @@ -336,11 +338,11 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const string const before = getSecOptions(); string const after = getOptions(); - string const glabel = generateLabel(buffer); + docstring const glabel = generateLabel(buffer); unsigned int const maxLabelChars = 45; - string label = glabel; + docstring label = glabel; if (label.size() > maxLabelChars) { label.erase(maxLabelChars-3); label += "..."; @@ -355,7 +357,8 @@ string const InsetCitation::getScreenLabel(Buffer const & buffer) const } -int InsetCitation::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const +int InsetCitation::plaintext(Buffer const & buffer, lyx::odocstream & os, + OutputParams const &) const { if (cache.params == params() && cache.engine == biblio::getEngine(buffer)) @@ -395,7 +398,7 @@ int InsetCitation::docbook(Buffer const &, ostream & os, OutputParams const &) c } -int InsetCitation::textString(Buffer const & buf, ostream & os, +int InsetCitation::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index c5bc0d207c..b66947db36 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -25,13 +25,13 @@ public: /// InsetCitation(InsetCommandParams const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// InsetBase::Code lyxCode() const { return InsetBase::CITE_CODE; } /// - int plaintext(Buffer const &, std::ostream &, OutputParams const &) const; + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int latex(Buffer const &, std::ostream &, OutputParams const &) const; @@ -39,7 +39,7 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// void validate(LaTeXFeatures &) const; @@ -53,7 +53,7 @@ private: } /// This function does the donkey work of creating the pretty label - std::string const generateLabel(Buffer const &) const; + lyx::docstring const generateLabel(Buffer const &) const; class Cache { public: @@ -64,9 +64,9 @@ private: /// InsetCommandParams params; /// - std::string generated_label; + lyx::docstring generated_label; /// - std::string screen_label; + lyx::docstring screen_label; }; /// mutable Cache cache; diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 272a9c1af8..59c9c0a7fa 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -78,7 +78,7 @@ int InsetCommand::latex(Buffer const &, ostream & os, } -int InsetCommand::plaintext(Buffer const &, ostream &, +int InsetCommand::plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const { return 0; diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index beb0c6a556..42edb946da 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -50,7 +50,7 @@ public: virtual int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// virtual int docbook(Buffer const &, std::ostream &, @@ -107,7 +107,7 @@ protected: /// void setParams(InsetCommandParams const &); /// This should provide the text for the button - virtual std::string const getScreenLabel(Buffer const &) const = 0; + virtual lyx::docstring const getScreenLabel(Buffer const &) const = 0; private: /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index f6a9342204..32358d130d 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -170,7 +170,7 @@ int InsetERT::latex(Buffer const &, ostream & os, } -int InsetERT::plaintext(Buffer const &, ostream &, +int InsetERT::plaintext(Buffer const &, lyx::odocstream &, OutputParams const & /*runparams*/) const { return 0; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index bcfe861512..801f4e4a44 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -52,7 +52,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index f597932fd7..59f4c6322d 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -49,6 +49,7 @@ namespace support = lyx::support; namespace external = lyx::external; namespace graphics = lyx::graphics; +using lyx::docstring; using std::endl; using std::string; using std::auto_ptr; @@ -569,16 +570,18 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams) } -string const getScreenLabel(InsetExternalParams const & params, +docstring const getScreenLabel(InsetExternalParams const & params, Buffer const & buffer) { external::Template const * const ptr = external::getTemplatePtr(params); if (!ptr) // FIXME UNICODE - return lyx::to_utf8(support::bformat(_("External template %1$s is not installed"), - lyx::from_utf8(params.templatename()))); - return external::doSubstitution(params, buffer, ptr->guiName, false); + return support::bformat((_("External template %1$s is not installed")), + lyx::from_utf8(params.templatename())); + // FIXME UNICODE + return lyx::from_utf8(external::doSubstitution(params, buffer, + ptr->guiName, false)); } void add_preview_and_start_loading(RenderMonitoredPreview &, @@ -715,12 +718,16 @@ int InsetExternal::latex(Buffer const & buf, ostream & os, } -int InsetExternal::plaintext(Buffer const & buf, ostream & os, +int InsetExternal::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { - return external::writeExternal(params_, "Ascii", buf, os, + std::ostringstream oss; + int const retval = external::writeExternal(params_, "Ascii", buf, oss, *(runparams.exportdata), false, runparams.inComment); + // FIXME UNICODE + os << lyx::from_utf8(oss.str()); + return retval; } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 7937b0c0f6..7ad563a070 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -126,7 +126,7 @@ public: virtual int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - virtual int plaintext(Buffer const &, std::ostream &, + virtual int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// virtual int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index b0edf66b88..6e617210a4 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -384,10 +384,10 @@ void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const for (; pit != end; ++pit) { if (pit->layout()->labeltype == LABEL_SENSITIVE) { string const type = params_.type; - string const str = - convert(toclist[type].size() + 1) + docstring const str = + convert(toclist[type].size() + 1) + ". " + pit->asString(buf, false); - lyx::toc::TocItem const item(pit, 0 , str); + lyx::toc::TocItem const item(pit, 0, str); toclist[type].push_back(item); } } diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index a16280888f..d7e538c18e 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -27,6 +27,7 @@ #include "support/lstrings.h" +using lyx::docstring; using lyx::support::bformat; using std::endl; @@ -46,16 +47,14 @@ InsetFloatList::InsetFloatList(string const & type) } -string const InsetFloatList::getScreenLabel(Buffer const & buf) const +docstring const InsetFloatList::getScreenLabel(Buffer const & buf) const { FloatList const & floats = buf.params().getLyXTextClass().floats(); FloatList::const_iterator it = floats[getCmdName()]; if (it != floats.end()) - // FIXME UNICODE - return lyx::to_utf8(buf.B_(it->second.listName())); + return buf.B_(it->second.listName()); else - // FIXME UNICODE - return lyx::to_utf8(_("ERROR: Nonexistent float type!")); + return _("ERROR: Nonexistent float type!"); } @@ -128,7 +127,8 @@ int InsetFloatList::latex(Buffer const & buf, ostream & os, } -int InsetFloatList::plaintext(Buffer const & buffer, ostream & os, OutputParams const &) const +int InsetFloatList::plaintext(Buffer const & buffer, lyx::odocstream & os, + OutputParams const &) const { os << getScreenLabel(buffer) << "\n\n"; diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index ffb0622552..301d14c8a0 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -24,7 +24,7 @@ public: /// InsetFloatList(std::string const & type); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -42,7 +42,7 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const &) const { return 0; } /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams) const; /// void validate(LaTeXFeatures & features) const; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 6620a9451a..cceb22e3fa 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -804,7 +804,7 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os, } -int InsetGraphics::plaintext(Buffer const &, ostream & os, +int InsetGraphics::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { // No graphics in ascii output. Possible to use gifscii to convert @@ -813,8 +813,10 @@ int InsetGraphics::plaintext(Buffer const &, ostream & os, // 2. Read ascii output file and add it to the output stream. // at least we send the filename // FIXME UNICODE - os << '<' << lyx::to_utf8(bformat(_("Graphics file: %1$s"), - lyx::from_utf8(params().filename.absFilename()))) << ">\n"; + // FIXME: We have no idea what the encoding of the filename is + os << '<' << bformat(_("Graphics file: %1$s"), + lyx::from_utf8(params().filename.absFilename())) + << ">\n"; return 0; } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 23d8eaa96b..effe8489e0 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -46,7 +46,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insethfill.C b/src/insets/insethfill.C index 21f9e79e70..03d7abb2fa 100644 --- a/src/insets/insethfill.C +++ b/src/insets/insethfill.C @@ -14,6 +14,8 @@ #include "support/std_ostream.h" +using lyx::docstring; + using std::ostream; @@ -37,9 +39,9 @@ void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const } -std::string const InsetHFill::getScreenLabel(Buffer const &) const +docstring const InsetHFill::getScreenLabel(Buffer const &) const { - return getContents(); + return lyx::from_ascii(getContents()); } @@ -51,7 +53,7 @@ int InsetHFill::latex(Buffer const &, ostream & os, } -int InsetHFill::plaintext(Buffer const &, ostream & os, +int InsetHFill::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << '\t'; diff --git a/src/insets/insethfill.h b/src/insets/insethfill.h index 2aaff52408..cd66169d10 100644 --- a/src/insets/insethfill.h +++ b/src/insets/insethfill.h @@ -22,14 +22,14 @@ public: /// void metrics(MetricsInfo &, Dimension &) const; /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// InsetBase::Code lyxCode() const { return InsetBase::HFILL_CODE; } /// int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 47198006c2..a1a4da035d 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -39,10 +39,10 @@ #include "insets/render_preview.h" -#include "support/lyxalgo.h" #include "support/filename.h" #include "support/filetools.h" #include "support/lstrings.h" // contains +#include "support/lyxalgo.h" #include "support/lyxlib.h" #include "support/convert.h" @@ -275,7 +275,7 @@ void InsetInclude::read(LyXLex & lex) } -string const InsetInclude::getScreenLabel(Buffer const &) const +docstring const InsetInclude::getScreenLabel(Buffer const &) const { docstring temp; @@ -294,15 +294,15 @@ string const InsetInclude::getScreenLabel(Buffer const &) const break; } - temp += lyx::from_ascii(": "); + temp += ": "; if (params_.getContents().empty()) - temp += lyx::from_ascii("???"); + temp += "???"; else + // FIXME: We don't know the encoding of the filename temp += lyx::from_ascii(onlyFilename(params_.getContents())); - // FIXME UNICODE - return lyx::to_utf8(temp); + return temp; } @@ -468,12 +468,13 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, } -int InsetInclude::plaintext(Buffer const & buffer, ostream & os, +int InsetInclude::plaintext(Buffer const & buffer, lyx::odocstream & os, OutputParams const &) const { if (isVerbatim(params_)) { - string const str = - getFileContents(includedFilename(buffer, params_)); + // FIXME: We don't know the encoding of the file + docstring const str = lyx::from_utf8( + getFileContents(includedFilename(buffer, params_))); os << str; // Return how many newlines we issued. return int(lyx::count(str.begin(), str.end(), '\n')); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 06b944b8cb..c1e7649dd3 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -78,7 +78,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, @@ -106,7 +106,7 @@ private: /// set the parameters void set(InsetCommandParams const & params, Buffer const &); /// get the text displayed on the button - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// void write(std::ostream &) const; /// diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index f067231148..e9c0e6ac23 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -20,6 +20,8 @@ #include "support/std_ostream.h" +using lyx::docstring; + using std::string; using std::ostream; @@ -34,10 +36,9 @@ InsetIndex::InsetIndex(InsetCommandParams const & p) // {} -string const InsetIndex::getScreenLabel(Buffer const &) const +docstring const InsetIndex::getScreenLabel(Buffer const &) const { - // FIXME UNICODE - return lyx::to_utf8(_("Idx")); + return _("Idx"); } @@ -67,10 +68,9 @@ InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p) // {} -string const InsetPrintIndex::getScreenLabel(Buffer const &) const +docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const { - // FIXME UNICODE - return lyx::to_utf8(_("Index")); + return _("Index"); } diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 8dc585a157..1a6c22cced 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -24,7 +24,7 @@ public: /// InsetIndex(InsetCommandParams const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -52,7 +52,7 @@ public: /// bool display() const { return true; } /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; private: virtual std::auto_ptr doClone() const { return std::auto_ptr(new InsetPrintIndex(params())); diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index b176327ca2..675bb0ace5 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -26,6 +26,7 @@ #include "support/lyxalgo.h" #include "support/std_ostream.h" +using lyx::docstring; using lyx::support::escape; using std::string; @@ -50,9 +51,10 @@ void InsetLabel::getLabelList(Buffer const &, std::vector & list) const } -string const InsetLabel::getScreenLabel(Buffer const &) const +docstring const InsetLabel::getScreenLabel(Buffer const &) const { - return getContents(); + // FIXME UNICODE + return lyx::from_utf8(getContents()); } @@ -89,10 +91,11 @@ int InsetLabel::latex(Buffer const &, ostream & os, } -int InsetLabel::plaintext(Buffer const &, ostream & os, +int InsetLabel::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { - os << '<' << getContents() << '>'; + // FIXME UNICODE + os << '<' << lyx::from_utf8(getContents()) << '>'; return 0; } diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 112fed3222..d4ba049a31 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -19,7 +19,7 @@ public: /// InsetLabel(InsetCommandParams const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -30,7 +30,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 429bfbea58..901fa926fb 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -579,10 +579,10 @@ int InsetLatexAccent::latex(Buffer const &, ostream & os, } -int InsetLatexAccent::plaintext(Buffer const &, ostream & os, +int InsetLatexAccent::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { - os << contents; + os << lyx::from_ascii(contents); return 0; } @@ -595,7 +595,7 @@ int InsetLatexAccent::docbook(Buffer const &, ostream & os, } -int InsetLatexAccent::textString(Buffer const & buf, ostream & os, +int InsetLatexAccent::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 9d270e1bcf..4e3fd9cc06 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -46,13 +46,13 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// bool directWrite() const; diff --git a/src/insets/insetline.C b/src/insets/insetline.C index f65d1ab70c..8a83f7c17c 100644 --- a/src/insets/insetline.C +++ b/src/insets/insetline.C @@ -63,7 +63,7 @@ int InsetLine::latex(Buffer const &, ostream & os, } -int InsetLine::plaintext(Buffer const &, ostream & os, +int InsetLine::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << "-------------------------------------------"; diff --git a/src/insets/insetline.h b/src/insets/insetline.h index 75f1475981..1297b6fcc2 100644 --- a/src/insets/insetline.h +++ b/src/insets/insetline.h @@ -29,7 +29,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index 7b09eae190..0079488fe5 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -57,7 +57,7 @@ int InsetNewline::latex(Buffer const &, ostream &, } -int InsetNewline::plaintext(Buffer const &, ostream & os, +int InsetNewline::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << '\n'; diff --git a/src/insets/insetnewline.h b/src/insets/insetnewline.h index 5122bbe4d9..b8e2da897a 100644 --- a/src/insets/insetnewline.h +++ b/src/insets/insetnewline.h @@ -29,7 +29,7 @@ public: virtual int latex(Buffer const &, std::ostream &, OutputParams const &) const; - virtual int plaintext(Buffer const &, std::ostream &, + virtual int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; virtual int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index a87d77f127..33916d7cae 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -322,7 +322,7 @@ int InsetNote::docbook(Buffer const & buf, std::ostream & os, } -int InsetNote::plaintext(Buffer const & buf, std::ostream & os, +int InsetNote::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 02e7ba0afb..4fe09a452e 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -63,7 +63,7 @@ public: int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/insetoptarg.C b/src/insets/insetoptarg.C index 1c4950feb7..7eb44dafc4 100644 --- a/src/insets/insetoptarg.C +++ b/src/insets/insetoptarg.C @@ -79,7 +79,7 @@ int InsetOptArg::docbook(Buffer const &, ostream &, } -int InsetOptArg::plaintext(Buffer const &, ostream &, +int InsetOptArg::plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const { return 0; diff --git a/src/insets/insetoptarg.h b/src/insets/insetoptarg.h index 9676c335f0..0454519740 100644 --- a/src/insets/insetoptarg.h +++ b/src/insets/insetoptarg.h @@ -37,7 +37,7 @@ public: OutputParams const &) const; /// Standard plain text output -- short-circuited - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// Outputting the optional parameter of a LaTeX command diff --git a/src/insets/insetpagebreak.C b/src/insets/insetpagebreak.C index 96d27662de..9c55d83d88 100644 --- a/src/insets/insetpagebreak.C +++ b/src/insets/insetpagebreak.C @@ -83,7 +83,7 @@ int InsetPagebreak::latex(Buffer const &, ostream & os, } -int InsetPagebreak::plaintext(Buffer const &, ostream & os, +int InsetPagebreak::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << '\n'; diff --git a/src/insets/insetpagebreak.h b/src/insets/insetpagebreak.h index 95b0ec5bf5..8ee273ec06 100644 --- a/src/insets/insetpagebreak.h +++ b/src/insets/insetpagebreak.h @@ -29,7 +29,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index de8ec48032..378a6e34ce 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -301,7 +301,7 @@ int InsetQuotes::latex(Buffer const &, ostream & os, } -int InsetQuotes::plaintext(Buffer const &, ostream & os, +int InsetQuotes::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << '"'; @@ -327,7 +327,7 @@ int InsetQuotes::docbook(Buffer const &, ostream & os, } -int InsetQuotes::textString(Buffer const & buf, ostream & os, +int InsetQuotes::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 116005f3b5..0d51ecfb55 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -87,14 +87,14 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 11a24ffe0a..4d1d4fc1ef 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -24,6 +24,7 @@ #include "support/lstrings.h" +using lyx::docstring; using lyx::support::escape; using std::string; @@ -62,21 +63,22 @@ void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd) } -string const InsetRef::getScreenLabel(Buffer const &) const +docstring const InsetRef::getScreenLabel(Buffer const &) const { - string temp; + docstring temp; for (int i = 0; !types[i].latex_name.empty(); ++i) { if (getCmdName() == types[i].latex_name) { - // FIXME UNIOCDE - temp = lyx::to_utf8(_(types[i].short_gui_name)); + temp = _(types[i].short_gui_name); break; } } - temp += getContents(); + // FIXME UNIOCDE + temp += lyx::from_utf8(getContents()); if (!isLatex && !getOptions().empty()) { temp += "||"; - temp += getOptions(); + // FIXME UNIOCDE + temp += lyx::from_utf8(getOptions()); } return temp; } @@ -95,10 +97,11 @@ int InsetRef::latex(Buffer const &, ostream & os, } -int InsetRef::plaintext(Buffer const &, ostream & os, +int InsetRef::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { - os << '[' << getContents() << ']'; + // FIXME UNIOCDE + os << '[' << lyx::from_utf8(getContents()) << ']'; return 0; } @@ -119,7 +122,7 @@ int InsetRef::docbook(Buffer const & buf, ostream & os, } -int InsetRef::textString(Buffer const & buf, ostream & os, +int InsetRef::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 1909a2e264..35550dde37 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -36,7 +36,7 @@ public: InsetRef(InsetCommandParams const &, Buffer const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -47,13 +47,13 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// void validate(LaTeXFeatures & features) const; diff --git a/src/insets/insetspace.C b/src/insets/insetspace.C index 8ececce4e5..bd7faede4a 100644 --- a/src/insets/insetspace.C +++ b/src/insets/insetspace.C @@ -195,7 +195,7 @@ int InsetSpace::latex(Buffer const &, ostream & os, } -int InsetSpace::plaintext(Buffer const &, ostream & os, +int InsetSpace::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { switch (kind_) { @@ -235,7 +235,7 @@ int InsetSpace::docbook(Buffer const &, ostream & os, } -int InsetSpace::textString(Buffer const & buf, ostream & os, +int InsetSpace::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetspace.h b/src/insets/insetspace.h index 76ec3c95c1..4d84e7c0c0 100644 --- a/src/insets/insetspace.h +++ b/src/insets/insetspace.h @@ -64,13 +64,13 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// InsetBase::Code lyxCode() const { return InsetBase::SPACE_CODE; } diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index b2c01b68a8..386fca533a 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -188,7 +188,7 @@ int InsetSpecialChar::latex(Buffer const &, ostream & os, } -int InsetSpecialChar::plaintext(Buffer const &, ostream & os, +int InsetSpecialChar::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { switch (kind_) { @@ -230,7 +230,7 @@ int InsetSpecialChar::docbook(Buffer const &, ostream & os, } -int InsetSpecialChar::textString(Buffer const & buf, ostream & os, +int InsetSpecialChar::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 8923bbdc2f..3606f9633f 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -56,13 +56,13 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// InsetBase::Code lyxCode() const { return InsetBase::SPECIALCHAR_CODE; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 39fc6c32f1..451b009898 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1060,7 +1060,7 @@ int InsetTabular::latex(Buffer const & buf, ostream & os, } -int InsetTabular::plaintext(Buffer const & buf, ostream & os, +int InsetTabular::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { int const dp = runparams.linelen ? runparams.depth : 0; @@ -1788,10 +1788,10 @@ bool InsetTabular::copySelection(LCursor & cur) paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0), true, true); - ostringstream os; + lyx::odocstringstream os; OutputParams const runparams; paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t'); - theClipboard().put(lyx::from_utf8(os.str())); + theClipboard().put(os.str()); // mark tabular stack dirty // FIXME: this is a workaround for bug 1919. Should be removed for 1.5, // when we (hopefully) have a one-for-all paste mechanism. diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 0532d31ad3..7feb753958 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -87,7 +87,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 7519d91470..f104bd6312 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -268,18 +268,18 @@ int InsetText::latex(Buffer const & buf, ostream & os, } -int InsetText::plaintext(Buffer const & buf, ostream & os, +int InsetText::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) const { ParagraphList::const_iterator beg = paragraphs().begin(); ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator it = beg; bool ref_printed = false; - std::ostringstream oss; + lyx::odocstringstream oss; for (; it != end; ++it) asciiParagraph(buf, *it, oss, runparams, ref_printed); - string const str = oss.str(); + docstring const str = oss.str(); os << str; // Return how many newlines we issued. return int(lyx::count(str.begin(), str.end(), '\n')); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 95c282a558..23f054e93b 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -64,7 +64,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index ea06bf37e8..c08da017e2 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -20,6 +20,8 @@ #include "support/std_ostream.h" +using lyx::docstring; + using std::string; using std::ostream; @@ -36,12 +38,11 @@ std::auto_ptr InsetTOC::doClone() const } -string const InsetTOC::getScreenLabel(Buffer const &) const +docstring const InsetTOC::getScreenLabel(Buffer const &) const { - // FIXME UNICODE if (getCmdName() == "tableofcontents") - return lyx::to_utf8(_("Table of Contents")); - return lyx::to_utf8(_("Unknown toc list")); + return _("Table of Contents"); + return _("Unknown toc list"); } @@ -53,7 +54,7 @@ InsetBase::Code InsetTOC::lyxCode() const } -int InsetTOC::plaintext(Buffer const & buffer, ostream & os, +int InsetTOC::plaintext(Buffer const & buffer, lyx::odocstream & os, OutputParams const &) const { os << getScreenLabel(buffer) << "\n\n"; diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 6f321f4624..126f10ef81 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -21,7 +21,7 @@ public: /// explicit InsetTOC(InsetCommandParams const &); /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -29,7 +29,7 @@ public: /// bool display() const { return true; } /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index b6f5e82d78..ffceee1cf9 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -22,6 +22,7 @@ #include "support/std_ostream.h" +using lyx::docstring; using lyx::support::subst; using std::string; @@ -33,14 +34,10 @@ InsetUrl::InsetUrl(InsetCommandParams const & p) {} -string const InsetUrl::getScreenLabel(Buffer const &) const +docstring const InsetUrl::getScreenLabel(Buffer const &) const { - string temp; - // FIXME UNICODE - if (getCmdName() == "url") - temp = lyx::to_utf8(_("Url: ")); - else - temp = lyx::to_utf8(_("HtmlUrl: ")); + docstring const temp = + (getCmdName() == "url") ? _("Url: ") : _("HtmlUrl: "); string url; @@ -54,7 +51,8 @@ string const InsetUrl::getScreenLabel(Buffer const &) const url = url.substr(0, 10) + "..." + url.substr(url.length() - 17, url.length()); } - return temp + url; + // FIXME UNICODE + return temp + lyx::from_utf8(url); } @@ -70,13 +68,16 @@ int InsetUrl::latex(Buffer const &, ostream & os, } -int InsetUrl::plaintext(Buffer const &, ostream & os, +int InsetUrl::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { + // FIXME UNICODE + os << '[' << lyx::from_utf8(getContents()); if (getOptions().empty()) - os << '[' << getContents() << ']'; + os << ']'; else - os << '[' << getContents() << "||" << getOptions() << ']'; + // FIXME UNICODE + os << "||" << lyx::from_utf8(getOptions()) << ']'; return 0; } @@ -90,7 +91,7 @@ int InsetUrl::docbook(Buffer const &, ostream & os, } -int InsetUrl::textString(Buffer const & buf, ostream & os, +int InsetUrl::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index 1aba7e51e3..a509ea60e1 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -29,7 +29,7 @@ public: /// void validate(LaTeXFeatures &) const; /// - std::string const getScreenLabel(Buffer const &) const; + lyx::docstring const getScreenLabel(Buffer const &) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -38,13 +38,13 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; private: virtual std::auto_ptr doClone() const { diff --git a/src/insets/insetvspace.C b/src/insets/insetvspace.C index e5cb547a9c..65cb980c0d 100644 --- a/src/insets/insetvspace.C +++ b/src/insets/insetvspace.C @@ -210,7 +210,7 @@ int InsetVSpace::latex(Buffer const & buf, ostream & os, } -int InsetVSpace::plaintext(Buffer const &, ostream & os, +int InsetVSpace::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { os << "\n\n"; diff --git a/src/insets/insetvspace.h b/src/insets/insetvspace.h index 0aaf68e736..e96024dd43 100644 --- a/src/insets/insetvspace.h +++ b/src/insets/insetvspace.h @@ -33,7 +33,7 @@ public: int latex(Buffer const &, std::ostream &, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index 6cf8150a3a..f3903c16d3 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -233,10 +233,10 @@ void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const for (; pit != end; ++pit) { if (pit->layout()->labeltype == LABEL_SENSITIVE) { string const type = params_.type; - string const str = - convert(toclist[type].size() + 1) + docstring const str = + convert(toclist[type].size() + 1) + ". " + pit->asString(buf, false); - lyx::toc::TocItem const item(pit, 0 , str); + lyx::toc::TocItem const item(pit, 0, str); toclist[type].push_back(item); } } diff --git a/src/insets/render_button.C b/src/insets/render_button.C index 16a153fcdf..ebc29bc1db 100644 --- a/src/insets/render_button.C +++ b/src/insets/render_button.C @@ -35,7 +35,7 @@ auto_ptr RenderButton::clone(InsetBase const *) const } -void RenderButton::update(string const & text, bool editable) +void RenderButton::update(docstring const & text, bool editable) { text_ = text; editable_ = editable; @@ -49,12 +49,10 @@ void RenderButton::metrics(MetricsInfo &, Dimension & dim) const lyx::frontend::FontMetrics const & fm = theFontMetrics(font); - docstring dtext(text_.begin(), text_.end()); - if (editable_) - fm.buttonText(dtext, dim.wid, dim.asc, dim.des); + fm.buttonText(text_, dim.wid, dim.asc, dim.des); else - fm.rectText(dtext, dim.wid, dim.asc, dim.des); + fm.rectText(text_, dim.wid, dim.asc, dim.des); dim.wid += 4; } @@ -67,12 +65,10 @@ void RenderButton::draw(PainterInfo & pi, int x, int y) const font.setColor(LColor::command); font.decSize(); - docstring dtext(text_.begin(), text_.end()); - if (editable_) { - pi.pain.buttonText(x + 2, y, dtext, font); + pi.pain.buttonText(x + 2, y, text_, font); } else { - pi.pain.rectText(x + 2, y, dtext, font, + pi.pain.rectText(x + 2, y, text_, font, LColor::commandbg, LColor::commandframe); } } diff --git a/src/insets/render_button.h b/src/insets/render_button.h index 4d805359d9..5122c4e197 100644 --- a/src/insets/render_button.h +++ b/src/insets/render_button.h @@ -14,7 +14,7 @@ #include "render_base.h" #include "box.h" -#include +#include "support/docstring.h" class RenderButton : public RenderBase @@ -30,7 +30,7 @@ public: virtual void draw(PainterInfo & pi, int x, int y) const; /// Provide the text for the button - void update(std::string const &, bool editable); + void update(lyx::docstring const &, bool editable); /// The "sensitive area" box, i.e., the button area Box box() const { return button_box_; } @@ -42,7 +42,7 @@ public: private: /// The stored data. - std::string text_; + lyx::docstring text_; bool editable_; Box button_box_; }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 6d25032ddc..b74f997c87 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1281,7 +1281,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) makeAbsPath(argument, owner->buffer()->filePath()); // FIXME Should use bformat setMessage(_("Opening child document ") + - makeDisplayPath(filename) + lyx::from_ascii("...")); + makeDisplayPath(filename) + "..."); view()->savePosition(0); string const parentfilename = owner->buffer()->fileName(); if (theBufferList().exists(filename)) diff --git a/src/mathed/InsetFormulaMacro.C b/src/mathed/InsetFormulaMacro.C index ea9076f75f..1c0df28003 100644 --- a/src/mathed/InsetFormulaMacro.C +++ b/src/mathed/InsetFormulaMacro.C @@ -85,7 +85,7 @@ int InsetFormulaMacro::latex(Buffer const &, ostream & os, } -int InsetFormulaMacro::plaintext(Buffer const &, ostream & os, +int InsetFormulaMacro::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { WriteStream wi(os, false, true); diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 8f9f46a6eb..5c0a325957 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -41,7 +41,7 @@ public: /// void write(Buffer const &, std::ostream & os) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int latex(Buffer const &, std::ostream & os, diff --git a/src/mathed/InsetMathCommand.C b/src/mathed/InsetMathCommand.C index d74801a342..a001ff4132 100644 --- a/src/mathed/InsetMathCommand.C +++ b/src/mathed/InsetMathCommand.C @@ -18,6 +18,8 @@ #include +using lyx::docstring; + using std::string; using std::auto_ptr; using std::ostringstream; @@ -70,9 +72,9 @@ void CommandInset::write(WriteStream & os) const } -string const CommandInset::screenLabel() const +docstring const CommandInset::screenLabel() const { - return name_; + return lyx::from_ascii(name_); } diff --git a/src/mathed/InsetMathCommand.h b/src/mathed/InsetMathCommand.h index ab2b4875fa..130d032a4f 100644 --- a/src/mathed/InsetMathCommand.h +++ b/src/mathed/InsetMathCommand.h @@ -34,7 +34,7 @@ public: // // void infoize(std::ostream & os) const; /// - virtual std::string const screenLabel() const; + virtual lyx::docstring const screenLabel() const; /// generate something that will be understood by the Dialogs. std::string const createDialogStr(std::string const & name) const; /// diff --git a/src/mathed/InsetMathGrid.C b/src/mathed/InsetMathGrid.C index 06b53ae5c4..4336e06572 100644 --- a/src/mathed/InsetMathGrid.C +++ b/src/mathed/InsetMathGrid.C @@ -1210,7 +1210,9 @@ void InsetMathGrid::doDispatch(LCursor & cur, FuncRequest & cmd) int n = 0; is >> n; InsetMathGrid grid(1, 1); - mathed_parse_normal(grid, lyx::cap::getSelection(cur.buffer(), n)); + // FIXME UNICODE + mathed_parse_normal(grid, + lyx::to_utf8(lyx::cap::getSelection(cur.buffer(), n))); if (grid.nargs() == 1) { // single cell/part of cell recordUndo(cur); diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index c6f12f3523..927e533acb 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -1425,7 +1425,7 @@ void InsetMathHull::read(Buffer const &, LyXLex & lex) } -int InsetMathHull::plaintext(Buffer const &, ostream & os, +int InsetMathHull::plaintext(Buffer const &, lyx::odocstream & os, OutputParams const &) const { if (0 && display()) { @@ -1439,8 +1439,11 @@ int InsetMathHull::plaintext(Buffer const &, ostream & os, //metrics(); return tpain.textheight(); } else { - WriteStream wi(os, false, true); + std::ostringstream oss; + WriteStream wi(oss, false, true); wi << cell(0); + // FIXME UNICODE + os << lyx::from_utf8(oss.str()); return wi.line(); } } @@ -1498,7 +1501,7 @@ int InsetMathHull::docbook(Buffer const & buf, ostream & os, } -int InsetMathHull::textString(Buffer const & buf, ostream & os, +int InsetMathHull::textString(Buffer const & buf, lyx::odocstream & os, OutputParams const & op) const { return plaintext(buf, os, op); diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 9add217f75..08d1833d78 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -100,13 +100,13 @@ public: /// void read(Buffer const &, LyXLex & lex); /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, OutputParams const &) const; /// the string that is passed to the TOC - virtual int textString(Buffer const &, std::ostream & os, + virtual int textString(Buffer const &, lyx::odocstream &, OutputParams const &) const; /// get notification when the cursor leaves this inset diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index b23dc673d7..a882e0e659 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -59,6 +59,7 @@ #include +using lyx::docstring; using lyx::cap::copySelection; using lyx::cap::grabAndEraseSelection; using lyx::cap::cutSelection; @@ -424,8 +425,9 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) size_t n = 0; istringstream is(lyx::to_utf8(cmd.argument())); is >> n; - string const selection = lyx::cap::getSelection(cur.buffer(), n); - cur.niceInsert(selection); + docstring const selection = lyx::cap::getSelection(cur.buffer(), n); + // FIXME UNICODE + cur.niceInsert(lyx::to_utf8(selection)); cur.clearSelection(); // bug 393 cur.bv().switchKeyMap(); finishUndo(); diff --git a/src/mathed/InsetMathRef.C b/src/mathed/InsetMathRef.C index ac9f9726cb..e36839981f 100644 --- a/src/mathed/InsetMathRef.C +++ b/src/mathed/InsetMathRef.C @@ -26,6 +26,8 @@ #include "outputparams.h" #include "sgml.h" +using lyx::docstring; + using std::string; using std::auto_ptr; using std::endl; @@ -118,16 +120,16 @@ bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd, } -string const RefInset::screenLabel() const +docstring const RefInset::screenLabel() const { - string str; + docstring str; for (int i = 0; !types[i].latex_name.empty(); ++i) if (commandname() == types[i].latex_name) { - // FIXME UNICODE - str = lyx::to_utf8(_(types[i].short_gui_name)); + str = _(types[i].short_gui_name); break; } - str += asString(cell(0)); + // FIXME UNICODE + str += lyx::from_utf8(asString(cell(0))); //if (/* !isLatex && */ !cell(0).empty()) { // str += "||"; @@ -146,9 +148,10 @@ void RefInset::validate(LaTeXFeatures & features) const } -int RefInset::plaintext(std::ostream & os, OutputParams const &) const +int RefInset::plaintext(lyx::odocstream & os, OutputParams const &) const { - os << '[' << asString(cell(0)) << ']'; + // FIXME UNICODE + os << '[' << lyx::from_utf8(asString(cell(0))) << ']'; return 0; } diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h index daf0c8c316..aa23efe093 100644 --- a/src/mathed/InsetMathRef.h +++ b/src/mathed/InsetMathRef.h @@ -28,14 +28,14 @@ public: /// void infoize(std::ostream & os) const; /// - std::string const screenLabel() const; + lyx::docstring const screenLabel() const; /// void validate(LaTeXFeatures & features) const; /// virtual RefInset * asRefInset() { return this; } - /// plain ascii output - int plaintext(std::ostream & os, OutputParams const &) const; + /// plain text output in ucs4 encoding + int plaintext(lyx::odocstream &, OutputParams const &) const; /// docbook output int docbook(Buffer const & buf, std::ostream & os, OutputParams const &) const; diff --git a/src/mathed/TextPainter.C b/src/mathed/TextPainter.C index e2403f625c..79180784e8 100644 --- a/src/mathed/TextPainter.C +++ b/src/mathed/TextPainter.C @@ -62,7 +62,7 @@ void TextPainter::draw(int x, int y, char c) } -void TextPainter::show(std::ostream & os, int offset) const +void TextPainter::show(lyx::odocstream & os, int offset) const { os << '\n'; for (int j = 0; j <= ymax_; ++j) { diff --git a/src/mathed/TextPainter.h b/src/mathed/TextPainter.h index d9da7234bc..6f02fd57e0 100644 --- a/src/mathed/TextPainter.h +++ b/src/mathed/TextPainter.h @@ -13,8 +13,9 @@ #define TEXTPAINTER_H +#include "support/docstream.h" + #include -#include class TextPainter { public: @@ -25,7 +26,7 @@ class TextPainter { /// void draw(int x, int y, char c); /// - void show(std::ostream & os, int offset = 0) const; + void show(lyx::odocstream & os, int offset = 0) const; /// int textheight() const { return ymax_; } /// diff --git a/src/output.C b/src/output.C index fbdef6bbbb..e946cb2b82 100644 --- a/src/output.C +++ b/src/output.C @@ -18,8 +18,7 @@ #include "support/filetools.h" -#include - +using lyx::odocfstream; using lyx::support::bformat; using lyx::support::makeDisplayPath; @@ -28,7 +27,10 @@ using lyx::docstring; using std::ofstream; using std::string; -bool openFileWrite(ofstream & ofs, string const & fname) +namespace { + +template +bool doOpenFileWrite(OFStream & ofs, string const & fname) { ofs.open(fname.c_str()); if (!ofs) { @@ -40,3 +42,17 @@ bool openFileWrite(ofstream & ofs, string const & fname) } return true; } + +} + + +bool openFileWrite(ofstream & ofs, string const & fname) +{ + return doOpenFileWrite(ofs, fname); +} + + +bool openFileWrite(odocfstream & ofs, string const & fname) +{ + return doOpenFileWrite(ofs, fname); +} diff --git a/src/output.h b/src/output.h index beecef7a39..4b39c9c8fd 100644 --- a/src/output.h +++ b/src/output.h @@ -12,9 +12,9 @@ #ifndef OUTPUT_H #define OUTPUT_H -#include -#include +#include "support/docstream.h" bool openFileWrite(std::ofstream & ofs, std::string const & fname); +bool openFileWrite(lyx::odocfstream & ofs, std::string const & fname); #endif diff --git a/src/output_latex.C b/src/output_latex.C index c945e19c2d..643b456242 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -133,7 +133,8 @@ TeXEnvironment(Buffer const & buf, os << "{" << pit->params().labelWidthString() << "}\n"; } else if (style->labeltype == LABEL_BIBLIO) { // ale970405 - os << "{" << bibitemWidest(buf) << "}\n"; + // FIXME UNICODE + os << '{' << lyx::to_utf8(bibitemWidest(buf)) << "}\n"; } else os << style->latexparam() << '\n'; texrow.newline(); diff --git a/src/output_plaintext.C b/src/output_plaintext.C index 311a0058e7..5903965595 100644 --- a/src/output_plaintext.C +++ b/src/output_plaintext.C @@ -23,15 +23,13 @@ #include "ParagraphParameters.h" #include "support/lstrings.h" -#include "support/unicode.h" - -#include using lyx::support::ascii_lowercase; using lyx::support::compare_ascii_no_case; using lyx::support::compare_no_case; using lyx::support::contains; +using lyx::docstring; using lyx::pos_type; using std::endl; using std::ostream; @@ -44,14 +42,14 @@ void writeFileAscii(Buffer const & buf, string const & fname, OutputParams const & runparams) { - ofstream ofs; + lyx::odocfstream ofs; if (!::openFileWrite(ofs, fname)) return; writeFileAscii(buf, ofs, runparams); } -void writeFileAscii(Buffer const & buf, ostream & os, +void writeFileAscii(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams) { bool ref_printed = false; @@ -68,12 +66,12 @@ void writeFileAscii(Buffer const & buf, ostream & os, namespace { -pair const addDepth(int depth, int ldepth) +pair const addDepth(int depth, int ldepth) { int d = depth * 2; if (ldepth > depth) d += (ldepth - depth) * 2; - return make_pair(d, string(d, ' ')); + return make_pair(d, docstring(d, ' ')); } } @@ -81,7 +79,7 @@ pair const addDepth(int depth, int ldepth) void asciiParagraph(Buffer const & buf, Paragraph const & par, - ostream & os, + lyx::odocstream & os, OutputParams const & runparams, bool & ref_printed) { @@ -136,7 +134,7 @@ void asciiParagraph(Buffer const & buf, if (runparams.linelen > 0) os << "\n\n"; - os << string(depth * 2, ' '); + os << docstring(depth * 2, ' '); currlinelen += depth * 2; //-- @@ -152,10 +150,10 @@ void asciiParagraph(Buffer const & buf, case 6: // Abstract if (runparams.linelen > 0) { - os << lyx::to_utf8(_("Abstract")) << "\n\n"; + os << _("Abstract") << "\n\n"; currlinelen = 0; } else { - string const abst = lyx::to_utf8(_("Abstract: ")); + docstring const abst = _("Abstract: "); os << abst; currlinelen += abst.length(); } @@ -164,10 +162,10 @@ void asciiParagraph(Buffer const & buf, case 7: // Bibliography if (!ref_printed) { if (runparams.linelen > 0) { - os << lyx::to_utf8(_("References")) << "\n\n"; + os << _("References") << "\n\n"; currlinelen = 0; } else { - string const refs = lyx::to_utf8(_("References: ")); + docstring const refs = _("References: "); os << refs; currlinelen += refs.length(); } @@ -176,7 +174,9 @@ void asciiParagraph(Buffer const & buf, break; default: { - string const label = par.params().labelString(); + // FIXME UNICODE + docstring const label = + lyx::from_utf8(par.params().labelString()); os << label << ' '; currlinelen += label.length() + 1; break; @@ -185,7 +185,7 @@ void asciiParagraph(Buffer const & buf, } if (!currlinelen) { - pair p = addDepth(depth, ltype_depth); + pair p = addDepth(depth, ltype_depth); os << p.second; currlinelen += p.first; } @@ -194,7 +194,7 @@ void asciiParagraph(Buffer const & buf, // intelligent hopefully! (only in the case where we have a // max runparams.linelength!) (Jug) - string word; + docstring word; for (pos_type i = 0; i < par.size(); ++i) { lyx::char_type c = par.getUChar(buf.params(), i); @@ -218,8 +218,8 @@ void asciiParagraph(Buffer const & buf, case ' ': if (runparams.linelen > 0 && currlinelen + word.length() > runparams.linelen - 10) { - os << "\n"; - pair p = addDepth(depth, ltype_depth); + os << '\n'; + pair p = addDepth(depth, ltype_depth); os << p.second; currlinelen = p.first; } @@ -233,20 +233,18 @@ void asciiParagraph(Buffer const & buf, "writeAsciiFile: NULL char in structure." << endl; break; - default: { - std::vector const tmp = ucs4_to_utf8(c); - word.append(tmp.begin(), tmp.end()); + default: + word += c; if (runparams.linelen > 0 && currlinelen + word.length() > runparams.linelen) { - os << "\n"; - pair p = addDepth(depth, ltype_depth); + os << '\n'; + pair p = addDepth(depth, ltype_depth); os << p.second; currlinelen = p.first; } break; } - } } os << word; } diff --git a/src/output_plaintext.h b/src/output_plaintext.h index f4ad4f7768..c997b9be2b 100644 --- a/src/output_plaintext.h +++ b/src/output_plaintext.h @@ -12,8 +12,7 @@ #ifndef OUTPUT_PLAINTEXT_H #define OUTPUT_PLAINTEXT_H -#include -#include +#include "support/docstream.h" class Buffer; class OutputParams; @@ -25,12 +24,12 @@ void writeFileAscii(Buffer const & buf, std::string const &, OutputParams const &); /// -void writeFileAscii(Buffer const & buf, std::ostream &, OutputParams const &); +void writeFileAscii(Buffer const & buf, lyx::odocstream &, OutputParams const &); /// void asciiParagraph(Buffer const & buf, Paragraph const & paragraphs, - std::ostream & ofs, + lyx::odocstream & ofs, OutputParams const &, bool & ref_printed); diff --git a/src/paragraph.C b/src/paragraph.C index eafe3ce560..7abffd2ea2 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -54,6 +54,7 @@ #include #include +using lyx::docstring; using lyx::pos_type; using lyx::char_type; @@ -1338,14 +1339,14 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams) const // Convert the paragraph to a string. // Used for building the table of contents -string const Paragraph::asString(Buffer const & buffer, bool label) const +docstring const Paragraph::asString(Buffer const & buffer, bool label) const { OutputParams runparams; return asString(buffer, runparams, label); } -string const Paragraph::asString(Buffer const & buffer, +docstring const Paragraph::asString(Buffer const & buffer, OutputParams const & runparams, bool label) const { @@ -1369,13 +1370,13 @@ string const Paragraph::asString(Buffer const & buffer, return s; #else // This should really be done by the caller and not here. - string ret = asString(buffer, runparams, 0, size(), label); + docstring ret = asString(buffer, runparams, 0, size(), label); return subst(ret, '\n', ' '); #endif } -string const Paragraph::asString(Buffer const & buffer, +docstring const Paragraph::asString(Buffer const & buffer, pos_type beg, pos_type end, bool label) const { @@ -1384,19 +1385,21 @@ string const Paragraph::asString(Buffer const & buffer, } -string const Paragraph::asString(Buffer const & buffer, +docstring const Paragraph::asString(Buffer const & buffer, OutputParams const & runparams, pos_type beg, pos_type end, bool label) const { - ostringstream os; + lyx::odocstringstream os; if (beg == 0 && label && !params().labelString().empty()) - os << params().labelString() << ' '; + // FIXME UNICODE + os << lyx::from_utf8(params().labelString()) << ' '; for (pos_type i = beg; i < end; ++i) { value_type const c = getUChar(buffer.params(), i); + // FIXME: isPrintable does not work for lyx::char_type if (isPrintable(c)) - os << c; + os.put(c); else if (c == META_INSET) getInset(i)->textString(buffer, os, runparams); } diff --git a/src/paragraph.h b/src/paragraph.h index d7a6a2841f..df46cb4b40 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -111,18 +111,18 @@ public: bool isMultiLingual(BufferParams const &) const; /// - std::string const asString(Buffer const &, + lyx::docstring const asString(Buffer const &, OutputParams const & runparams, bool label) const; /// - std::string const asString(Buffer const &, bool label) const; + lyx::docstring const asString(Buffer const &, bool label) const; /// - std::string const asString(Buffer const & buffer, + lyx::docstring const asString(Buffer const & buffer, lyx::pos_type beg, lyx::pos_type end, bool label) const; /// - std::string const asString(Buffer const &, + lyx::docstring const asString(Buffer const &, OutputParams const & runparams, lyx::pos_type beg, lyx::pos_type end, diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 2fe007d7db..bf4ab321f2 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -446,7 +446,10 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, if (c != '\0') os << c; } else { - owner_->getInset(i)->plaintext(buf, os, runparams); + lyx::odocstringstream oss; + owner_->getInset(i)->plaintext(buf, oss, runparams); + // FIXME UNICODE + os << lyx::to_utf8(oss.str()); } return; } diff --git a/src/support/Makefile.am b/src/support/Makefile.am index de535eebb3..b3c3f775e3 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -27,6 +27,8 @@ libsupport_la_SOURCES = \ copied_ptr.h \ cow_ptr.h \ debugstream.h \ + docstream.C \ + docstream.h \ docstring.C \ docstring.h \ environment.h \ diff --git a/src/support/docstream.C b/src/support/docstream.C new file mode 100644 index 0000000000..24c08ee18c --- /dev/null +++ b/src/support/docstream.C @@ -0,0 +1,233 @@ +/** + * \file docstream.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Georg Baum + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "docstream.h" + +#include +#include +#include +#include + +namespace { + +#ifdef WORDS_BIGENDIAN +char const * ucs4_codeset = "UCS-4BE"; +#else +char const * ucs4_codeset = "UCS-4LE"; +#endif +char const * utf8_codeset = "UTF-8"; + +// We use C IO throughout this file, because the facets might be used with +// lyxerr in the future. + + +class utf8_codecvt_facet_exception : public std::exception { +public: + virtual ~utf8_codecvt_facet_exception() throw() {} + virtual const char* what() const throw() + { + return "iconv problem in utf8_codecvt_facet initialization"; + } +}; + + +/// codecvt facet for conversion of UCS4 (internal representation) to UTF8 +/// (external representation) or vice versa +class utf8_codecvt_facet : public std::codecvt +{ + typedef std::codecvt base; +public: + /// Constructor. You have to specify with \p inout whether you want + /// to use this facet only for input, only for output or for both. + explicit utf8_codecvt_facet(std::ios_base::openmode inout = std::ios_base::in | std::ios_base::out, + size_t refs = 0) + : base(refs) + { + if (inout & std::ios_base::in) { + in_cd_ = iconv_open(ucs4_codeset, utf8_codeset); + if (in_cd_ == (iconv_t)(-1)) { + fprintf(stderr, "Error %d returned from iconv_open(in_cd_): %s\n", + errno, strerror(errno)); + fflush(stderr); + throw utf8_codecvt_facet_exception(); + } + } else + in_cd_ = (iconv_t)(-1); + if (inout & std::ios_base::out) { + out_cd_ = iconv_open(utf8_codeset, ucs4_codeset); + if (out_cd_ == (iconv_t)(-1)) { + fprintf(stderr, "Error %d returned from iconv_open(out_cd_): %s\n", + errno, strerror(errno)); + fflush(stderr); + throw utf8_codecvt_facet_exception(); + } + } else + out_cd_ = (iconv_t)(-1); + } +protected: + virtual ~utf8_codecvt_facet() + { + if (in_cd_ != (iconv_t)(-1)) + if (iconv_close(in_cd_) == -1) { + fprintf(stderr, "Error %d returned from iconv_close(in_cd_): %s\n", + errno, strerror(errno)); + fflush(stderr); + } + if (out_cd_ != (iconv_t)(-1)) + if (iconv_close(out_cd_) == -1) { + fprintf(stderr, "Error %d returned from iconv_close(out_cd_): %s\n", + errno, strerror(errno)); + fflush(stderr); + } + } + virtual result do_out(state_type &, intern_type const * from, + intern_type const * from_end, intern_type const *& from_next, + extern_type * to, extern_type * to_end, + extern_type *& to_next) const + { + size_t inbytesleft = (from_end - from) * sizeof(intern_type); + size_t outbytesleft = (to_end - to) * sizeof(extern_type); + from_next = from; + to_next = to; + return do_iconv(out_cd_, reinterpret_cast(&from_next), + &inbytesleft, &to_next, &outbytesleft); + } + virtual result do_unshift(state_type &, extern_type * to, + extern_type *, extern_type *& to_next) const + { + // utf8 does not use shifting + to_next = to; + return base::noconv; + } + virtual result do_in(state_type &, + extern_type const * from, extern_type const * from_end, + extern_type const *& from_next, + intern_type * to, intern_type * to_end, + intern_type *& to_next) const + { + size_t inbytesleft = (from_end - from) * sizeof(extern_type); + size_t outbytesleft = (to_end - to) * sizeof(intern_type); + from_next = from; + to_next = to; + return do_iconv(in_cd_, &from_next, &inbytesleft, + reinterpret_cast(&to_next), + &outbytesleft); + } + virtual int do_encoding() const throw() + { + return 0; + } + virtual bool do_always_noconv() const throw() + { + return false; + } + virtual int do_length(state_type & /*state*/, extern_type const * from, + extern_type const * end, size_t max) const + { + // The docs are a bit unclear about this method. + // It seems that we should calculate the actual length of the + // converted sequence, but that would not make sense, since + // once could just do the conversion directly. + // Therefore we just return the number of unconverted + // characters, since that is the best guess we can do. +#if 0 + intern_type * to = new intern_type[max]; + intern_type * to_end = to + max; + intern_type * to_next = to; + extern_type const * from_next = from; + do_in(state, from, end, from_next, to, to_end, to_next); + delete[] to; + return to_next - to; +#else + size_t const length = end - from; + return std::min(length, max); +#endif + } + virtual int do_max_length() const throw() + { + // UTF8 uses at most 6 bytes to represent one code point + return 6; + } +private: + /// Do the actual conversion. The interface is equivalent to that of + /// iconv() (but const correct). + inline base::result do_iconv(iconv_t cd, char const ** from, + size_t * inbytesleft, char ** to, size_t * outbytesleft) const + { + char const * to_start = *to; + size_t converted = iconv(cd, const_cast(from), + inbytesleft, to, outbytesleft); + if (converted == (size_t)(-1)) { + switch(errno) { + case EINVAL: + case E2BIG: + return base::partial; + case EILSEQ: + default: + fprintf(stderr, "Error %d returned from iconv: %s\n", + errno, strerror(errno)); + fflush(stderr); + return base::error; + } + } + if (*to == to_start) + return base::noconv; + return base::ok; + } + iconv_t in_cd_; + iconv_t out_cd_; +}; + +} + + +namespace lyx { + + +idocfstream::idocfstream() : base() +{ + std::locale global; + std::locale locale(global, new utf8_codecvt_facet(in)); + imbue(locale); +} + + +idocfstream::idocfstream(const char* s, std::ios_base::openmode mode) + : base() +{ + // We must imbue the stream before openening the file + std::locale global; + std::locale locale(global, new utf8_codecvt_facet(in)); + imbue(locale); + open(s, mode); +} + + +odocfstream::odocfstream() : base() +{ + std::locale global; + std::locale locale(global, new utf8_codecvt_facet(out)); + imbue(locale); +} + + +odocfstream::odocfstream(const char* s, std::ios_base::openmode mode) + : base() +{ + // We must imbue the stream before openening the file + std::locale global; + std::locale locale(global, new utf8_codecvt_facet(out)); + imbue(locale); + open(s, mode); +} + +} diff --git a/src/support/docstream.h b/src/support/docstream.h new file mode 100644 index 0000000000..4552a2f68f --- /dev/null +++ b/src/support/docstream.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +/** + * \file docstream.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Georg Baum + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_DOCSTREAM_H +#define LYX_DOCSTREAM_H + +#include "support/docstring.h" + +#include +#include + +namespace lyx { + +/// Base class for UCS4 input streams +typedef std::basic_istream idocstream; + +/** Base class for UCS4 output streams. + If you want to output a single UCS4 character, use \code + os.put(c); + \endcode, not \code + os << c; + \endcode . The latter will not output the character, but the code point + as number. This is because we can't overload operator<< (our character + type is not a real type but a typedef). Narrow characters of type char + can be output as usual. + */ +typedef std::basic_ostream odocstream; + +/// File stream for reading UTF8-encoded files with automatic conversion to +/// UCS4. +class idocfstream : public std::basic_ifstream { + typedef std::basic_ifstream base; +public: + idocfstream(); + explicit idocfstream(const char* s, + std::ios_base::openmode mode = std::ios_base::in); + ~idocfstream() {} +}; + +/// File stream for writing UTF8-encoded files with automatic conversion from +/// UCS4. +class odocfstream : public std::basic_ofstream { + typedef std::basic_ofstream base; +public: + odocfstream(); + explicit odocfstream(const char* s, + std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc); + ~odocfstream() {} +}; + +/// UCS4 input stringstream +typedef std::basic_istringstream idocstringstream; + +/// UCS4 output stringstream +typedef std::basic_ostringstream odocstringstream; + +} +#endif diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 1cd22acbb9..578eb85f39 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -93,18 +93,19 @@ int compare_no_case(docstring const & s, docstring const & s2) namespace { - int ascii_tolower(int c) { - if (c >= 'A' && c <= 'Z') - return c - 'A' + 'a'; - return c; - } + +int ascii_tolower(int c) { + if (c >= 'A' && c <= 'Z') + return c - 'A' + 'a'; + return c; } -int compare_ascii_no_case(string const & s, string const & s2) +template inline +int do_compare_ascii_no_case(String const & s, String const & s2) { - string::const_iterator p = s.begin(); - string::const_iterator p2 = s2.begin(); + typename String::const_iterator p = s.begin(); + typename String::const_iterator p2 = s2.begin(); while (p != s.end() && p2 != s2.end()) { int const lc1 = ascii_tolower(*p); @@ -122,6 +123,20 @@ int compare_ascii_no_case(string const & s, string const & s2) return 1; } +} + + +int compare_ascii_no_case(string const & s, string const & s2) +{ + return do_compare_ascii_no_case(s, s2); +} + + +int compare_ascii_no_case(docstring const & s, docstring const & s2) +{ + return do_compare_ascii_no_case(s, s2); +} + int compare_no_case(string const & s, string const & s2, unsigned int len) { @@ -411,6 +426,7 @@ int tokenPos(string const & a, char delim, string const & tok) namespace { +/// Substitute all \a oldchar with \a newchar template inline std::basic_string const subst_char(std::basic_string const & a, Ch oldchar, Ch newchar) @@ -426,6 +442,7 @@ std::basic_string const subst_char(std::basic_string const & a, } +/// substitutes all instances of \a oldstr with \a newstr template inline String const subst_string(String const & a, String const & oldstr, String const & newstr) @@ -542,6 +559,8 @@ string const ltrim(string const & a, char const * p) } +namespace { + template inline String const doSplit(String const & a, String & piece, Char delim) { @@ -561,6 +580,8 @@ String const doSplit(String const & a, String & piece, Char delim) return tmp; } +} + string const split(string const & a, string & piece, char delim) { diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 4011708b72..2f61aaa8f4 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -31,6 +31,9 @@ int compare_no_case(lyx::docstring const & s, lyx::docstring const & s2); /// int compare_ascii_no_case(std::string const & s, std::string const & s2); +/// +int compare_ascii_no_case(docstring const & s, docstring const & s2); + /// int compare_no_case(std::string const & s, std::string const & s2, unsigned int len); diff --git a/src/tabular.C b/src/tabular.C index 10c59096e0..bb28318de3 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -37,6 +37,7 @@ #include +using lyx::docstring; using lyx::support::ltrim; using lyx::support::prefixIs; using lyx::support::rtrim; @@ -2434,7 +2435,7 @@ int LyXTabular::docbook(Buffer const & buf, ostream & os, } -int LyXTabular::asciiTopHLine(ostream & os, row_type row, +int LyXTabular::asciiTopHLine(lyx::odocstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -2450,7 +2451,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, if (!tmp) return 0; - unsigned char ch; + lyx::char_type ch; for (idx_type i = fcell; i < n; ++i) { if (topLine(i)) { if (leftLine(i)) @@ -2467,7 +2468,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, while (column < columns_ - 1 && isPartOfMultiColumn(row, ++column)) len += clen[column] + 4; - os << string(len, ch); + os << docstring(len, ch); if (topLine(i)) { if (rightLine(i)) os << "-+"; @@ -2482,7 +2483,7 @@ int LyXTabular::asciiTopHLine(ostream & os, row_type row, } -int LyXTabular::asciiBottomHLine(ostream & os, row_type row, +int LyXTabular::asciiBottomHLine(lyx::odocstream & os, row_type row, vector const & clen) const { idx_type const fcell = getFirstCellInRow(row); @@ -2498,7 +2499,7 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, if (!tmp) return 0; - unsigned char ch; + lyx::char_type ch; for (idx_type i = fcell; i < n; ++i) { if (bottomLine(i)) { if (leftLine(i)) @@ -2515,7 +2516,7 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, while (column < columns_ -1 && isPartOfMultiColumn(row, ++column)) len += clen[column] + 4; - os << string(len, ch); + os << docstring(len, ch); if (bottomLine(i)) { if (rightLine(i)) os << "-+"; @@ -2530,13 +2531,13 @@ int LyXTabular::asciiBottomHLine(ostream & os, row_type row, } -int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, +int LyXTabular::asciiPrintCell(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams, idx_type cell, row_type row, col_type column, vector const & clen, bool onlydata) const { - ostringstream sstr; + lyx::odocstringstream sstr; int const ret = getCellInset(cell)->plaintext(buf, sstr, runparams); if (onlydata) { @@ -2571,7 +2572,8 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, break; } - os << string(len1, ' ') << sstr.str() << string(len2, ' '); + os << docstring(len1, ' ') << sstr.str() + << docstring(len2, ' '); if (rightLine(cell)) os << " |"; @@ -2582,7 +2584,7 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os, } -int LyXTabular::plaintext(Buffer const & buf, ostream & os, +int LyXTabular::plaintext(Buffer const & buf, lyx::odocstream & os, OutputParams const & runparams, int const depth, bool onlydata, unsigned char delim) const @@ -2600,7 +2602,7 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, idx_type cell = getCellNumber(i, j); if (isMultiColumnReal(cell)) continue; - ostringstream sstr; + lyx::odocstringstream sstr; getCellInset(cell)->plaintext(buf, sstr, runparams); if (clen[j] < sstr.str().length()) clen[j] = sstr.str().length(); @@ -2612,7 +2614,7 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, idx_type cell = getCellNumber(i, j); if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j)) continue; - ostringstream sstr; + lyx::odocstringstream sstr; getCellInset(cell)->plaintext(buf, sstr, runparams); int len = int(sstr.str().length()); idx_type const n = cells_in_multicolumn(cell); @@ -2626,7 +2628,7 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, idx_type cell = 0; for (row_type i = 0; i < rows_; ++i) { if (!onlydata && asciiTopHLine(os, i, clen)) - os << string(depth * 2, ' '); + os << docstring(depth * 2, ' '); for (col_type j = 0; j < columns_; ++j) { if (isPartOfMultiColumn(i, j)) continue; @@ -2638,9 +2640,9 @@ int LyXTabular::plaintext(Buffer const & buf, ostream & os, } os << endl; if (!onlydata) { - os << string(depth * 2, ' '); + os << docstring(depth * 2, ' '); if (asciiBottomHLine(os, i, clen)) - os << string(depth * 2, ' '); + os << docstring(depth * 2, ' '); } } return ret; diff --git a/src/tabular.h b/src/tabular.h index e3fe328fe8..b650db8717 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -316,7 +316,7 @@ public: int docbook(Buffer const & buf, std::ostream & os, OutputParams const &) const; /// - int plaintext(Buffer const &, std::ostream &, + int plaintext(Buffer const &, lyx::odocstream &, OutputParams const & runparams, int const depth, bool onlydata, unsigned char delim) const; @@ -605,13 +605,13 @@ public: /// // helper function for ASCII returns number of newlines /// - int asciiTopHLine(std::ostream &, row_type row, + int asciiTopHLine(lyx::odocstream &, row_type row, std::vector const &) const; /// - int asciiBottomHLine(std::ostream &, row_type row, + int asciiBottomHLine(lyx::odocstream &, row_type row, std::vector const &) const; /// - int asciiPrintCell(Buffer const &, std::ostream &, + int asciiPrintCell(Buffer const &, lyx::odocstream &, OutputParams const &, idx_type cell, row_type row, col_type column, std::vector const &, diff --git a/src/text.C b/src/text.C index a224f124ac..975c658a48 100644 --- a/src/text.C +++ b/src/text.C @@ -2481,7 +2481,8 @@ string LyXText::getPossibleLabel(LCursor & cur) const if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0) text.erase(); - string par_text = pars_[pit].asString(cur.buffer(), false); + // FIXME UNICODE + string par_text = lyx::to_utf8(pars_[pit].asString(cur.buffer(), false)); for (int i = 0; i < lyxrc.label_init_length; ++i) { if (par_text.empty()) break; diff --git a/src/toc.C b/src/toc.C index f4485aaf72..ffd5ee9fbc 100644 --- a/src/toc.C +++ b/src/toc.C @@ -93,7 +93,7 @@ vector const & getTypes(Buffer const & buf) } -void asciiTocList(string const & type, Buffer const & buf, ostream & os) +void asciiTocList(string const & type, Buffer const & buf, lyx::odocstream & os) { toc_backend_[&buf].asciiTocList(type, os); } diff --git a/src/toc.h b/src/toc.h index 919d1ba282..750b841467 100644 --- a/src/toc.h +++ b/src/toc.h @@ -44,7 +44,7 @@ TocIterator const getCurrentTocItem(Buffer const &, LCursor const &, std::string const & type); /// -void asciiTocList(std::string const &, Buffer const &, std::ostream &); +void asciiTocList(std::string const &, Buffer const &, lyx::odocstream &); /** Given the cmdName of the TOC param, returns the type used by ControlToc::getContents() */