From 31bc611f342db3e6dd6a71ab66450e46c4dfb5b6 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 5 Jan 2007 17:11:32 +0000 Subject: [PATCH] Fix bug 3067: Special column attributes can contain non-ascii characters, so store them in a docstring. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16537 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/QTabular.C | 10 +++++----- src/insets/insetbibtex.C | 2 +- src/insets/insettabular.C | 2 +- src/support/lstrings.C | 16 ++++++++++++++++ src/support/lstrings.h | 6 +++++- src/tabular.C | 33 ++++++++++++++++++++++++--------- src/tabular.h | 8 ++++---- 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/frontends/qt4/QTabular.C b/src/frontends/qt4/QTabular.C index f42c12f1b4..b259d8f7af 100644 --- a/src/frontends/qt4/QTabular.C +++ b/src/frontends/qt4/QTabular.C @@ -173,7 +173,7 @@ void QTabular::update_contents() update_borders(); LyXLength pwidth; - string special; + docstring special; if (multicol) { special = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI); @@ -424,8 +424,8 @@ void QTabular::closeGUI() width2 = llen.asString(); // apply the special alignment - string const sa1 = fromqstr(dialog_->specialAlignmentED->text()); - string sa2; + docstring const sa1 = qstring_to_ucs4(dialog_->specialAlignmentED->text()); + docstring sa2; if (multicol) sa2 = tabular.getAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI); @@ -434,9 +434,9 @@ void QTabular::closeGUI() if (sa1 != sa2) { if (multicol) - controller().set(LyXTabular::SET_SPECIAL_MULTI, sa1); + controller().set(LyXTabular::SET_SPECIAL_MULTI, to_utf8(sa1)); else - controller().set(LyXTabular::SET_SPECIAL_COLUMN, sa1); + controller().set(LyXTabular::SET_SPECIAL_COLUMN, to_utf8(sa1)); } if (width != width2) { diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 8d3a3f6cd4..fa604fddd3 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -355,7 +355,7 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer, docstring linebuf = trim(linebuf0); if (linebuf.empty()) continue; - if (prefixIs(linebuf, from_ascii("@"))) { + if (prefixIs(linebuf, '@')) { linebuf = subst(linebuf, '{', '('); docstring tmp; linebuf = split(linebuf, tmp, '('); diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 1383370f93..521806dea6 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1434,7 +1434,7 @@ void InsetTabular::tabularFeatures(LCursor & cur, case LyXTabular::SET_SPECIAL_COLUMN: case LyXTabular::SET_SPECIAL_MULTI: - tabular.setAlignSpecial(cur.idx(),value,feature); + tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature); break; case LyXTabular::APPEND_ROW: diff --git a/src/support/lstrings.C b/src/support/lstrings.C index cd498896a7..973b260d7c 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -423,6 +423,14 @@ docstring const ascii_lowercase(docstring const & a) } +bool prefixIs(docstring const & a, char_type c) +{ + if (a.empty()) + return false; + return a[0] == c; +} + + bool prefixIs(string const & a, string const & pre) { string::size_type const prelen = pre.length(); @@ -459,6 +467,14 @@ bool suffixIs(string const & a, char c) } +bool suffixIs(docstring const & a, char_type c) +{ + if (a.empty()) + return false; + return a[a.length() - 1] == c; +} + + bool suffixIs(string const & a, string const & suf) { string::size_type const suflen = suf.length(); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 87e7f242fd..5f9b559dc7 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -98,12 +98,16 @@ docstring const lowercase(docstring const &); /// std::string const uppercase(std::string const &); +/// Does the string start with this prefix? +bool prefixIs(docstring const &, char_type); + /// Does the std::string start with this prefix? bool prefixIs(std::string const &, std::string const &); -bool prefixIs(lyx::docstring const &, lyx::docstring const &); +bool prefixIs(docstring const &, docstring const &); /// Does the string end with this char? bool suffixIs(std::string const &, char); +bool suffixIs(docstring const &, char_type); /// Does the std::string end with this suffix? bool suffixIs(std::string const &, std::string const &); diff --git a/src/tabular.C b/src/tabular.C index 711e5432ab..7d6f1aabb3 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -84,6 +84,13 @@ string const write_attribute(string const & name, string const & t) } +template <> +string const write_attribute(string const & name, docstring const & t) +{ + return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\""; +} + + template <> string const write_attribute(string const & name, bool const & b) { @@ -250,6 +257,15 @@ bool getTokenValue(string const & str, char const * token, string & ret) } +bool getTokenValue(string const & str, char const * token, docstring & ret) +{ + string tmp; + bool const success = getTokenValue(str, token, tmp); + ret = from_utf8(tmp); + return success; +} + + bool getTokenValue(string const & str, char const * token, int & num) { string tmp; @@ -689,11 +705,11 @@ bool LyXTabular::leftLine(idx_type cell, bool wholecolumn) const { if (cellinfo_of_cell(cell).align_special.empty()) return cellinfo_of_cell(cell).left_line; - return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), "|"); + return prefixIs(ltrim(cellinfo_of_cell(cell).align_special), '|'); } if (column_info[column_of_cell(cell)].align_special.empty()) return column_info[column_of_cell(cell)].left_line; - return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), "|"); + return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), '|'); } @@ -706,11 +722,11 @@ bool LyXTabular::rightLine(idx_type cell, bool wholecolumn) const { if (cellinfo_of_cell(cell).align_special.empty()) return cellinfo_of_cell(cell).right_line; - return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), "|"); + return suffixIs(rtrim(cellinfo_of_cell(cell).align_special), '|'); } if (column_info[column_of_cell(cell)].align_special.empty()) return column_info[right_column_of_cell(cell)].right_line; - return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), "|"); + return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), '|'); } @@ -1006,7 +1022,7 @@ bool LyXTabular::setMColumnPWidth(LCursor & cur, idx_type cell, } -void LyXTabular::setAlignSpecial(idx_type cell, string const & special, +void LyXTabular::setAlignSpecial(idx_type cell, docstring const & special, LyXTabular::Feature what) { if (what == SET_SPECIAL_MULTI) @@ -1101,7 +1117,7 @@ LyXLength const LyXTabular::getMColumnPWidth(idx_type cell) const } -string const LyXTabular::getAlignSpecial(idx_type cell, int what) const +docstring const LyXTabular::getAlignSpecial(idx_type cell, int what) const { if (what == SET_SPECIAL_MULTI) return cellinfo_of_cell(cell).align_special; @@ -1907,8 +1923,7 @@ int LyXTabular::TeXCellPreamble(odocstream & os, idx_type cell) const if (isMultiColumn(cell)) { os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{"; if (!cellinfo_of_cell(cell).align_special.empty()) { - os << from_ascii(cellinfo_of_cell(cell).align_special) - << "}{"; + os << cellinfo_of_cell(cell).align_special << "}{"; } else { if (leftLine(cell) && (isFirstCellInRow(cell) || @@ -2212,7 +2227,7 @@ int LyXTabular::latex(Buffer const & buf, odocstream & os, os << "\\begin{tabular}{"; for (col_type i = 0; i < columns_; ++i) { if (!column_info[i].align_special.empty()) { - os << from_ascii(column_info[i].align_special); + os << column_info[i].align_special; } else { if (!use_booktabs && column_info[i].left_line) os << '|'; diff --git a/src/tabular.h b/src/tabular.h index 8c8180e8f6..add8f0aeec 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -264,7 +264,7 @@ public: /// bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &); /// - void setAlignSpecial(idx_type cell, std::string const & special, + void setAlignSpecial(idx_type cell, docstring const & special, Feature what); /// LyXAlignment getAlignment(idx_type cell, @@ -279,7 +279,7 @@ public: /// LyXLength const getMColumnPWidth(idx_type cell) const; /// - std::string const getAlignSpecial(idx_type cell, int what) const; + docstring const getAlignSpecial(idx_type cell, int what) const; /// int getWidthOfCell(idx_type cell) const; /// @@ -454,7 +454,7 @@ public: /// bool rotate; /// - std::string align_special; + docstring align_special; /// LyXLength p_width; // this is only set for multicolumn!!! /// @@ -524,7 +524,7 @@ public: /// LyXLength p_width; /// - std::string align_special; + docstring align_special; }; /// typedef std::vector column_vector;