]> git.lyx.org Git - features.git/commitdiff
Fix bug 3067: Special column attributes can contain non-ascii characters,
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 5 Jan 2007 17:11:32 +0000 (17:11 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 5 Jan 2007 17:11:32 +0000 (17:11 +0000)
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
src/insets/insetbibtex.C
src/insets/insettabular.C
src/support/lstrings.C
src/support/lstrings.h
src/tabular.C
src/tabular.h

index f42c12f1b4e9d6ceb633b8884a2558f0a9a38fed..b259d8f7afff067425299fb000fb98bdc272e157 100644 (file)
@@ -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) {
index 8d3a3f6cd457139ff978ef690e82d7b5fb517445..fa604fddd381159f9b1e90203dcfaab0bbae44ed 100644 (file)
@@ -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, '(');
index 1383370f93eeb97cb0d201b20b62fff05128080d..521806dea635cb2ab6c62b3e5d8b7269df850c3e 100644 (file)
@@ -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:
index cd498896a72121c745d19b71b2fb5880a11eda51..973b260d7cc93ef10501efc7c94200ebeb09a883 100644 (file)
@@ -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();
index 87e7f242fd7691785e12966ba4f5ad98f444537b..5f9b559dc7de77d25660011590b82fe8ce139c5b 100644 (file)
@@ -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 &);
index 711e5432ab5f1044e0fa8b5c219f034386ae6ad0..7d6f1aabb3bc25bace03dc6d4cd8f29e69218060 100644 (file)
@@ -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 << '|';
index 8c8180e8f619055833c29e0aa7fc69146ca0b3ba..add8f0aeec1b92fe908fa546a4c190e981e653aa 100644 (file)
@@ -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<columnstruct> column_vector;