Move global variable to preamble

This will be needed in the future, when I need to parse the preamble twice
for detecting japanese encoding (bug #8218).
This commit is contained in:
Georg Baum 2015-01-06 19:20:05 +01:00
parent 41405babc5
commit 59b705dcd9
3 changed files with 30 additions and 28 deletions

View File

@ -39,9 +39,6 @@ using namespace lyx::support;
namespace lyx {
// special columntypes
extern map<char, int> special_columns;
Preamble preamble;
namespace {
@ -402,6 +399,15 @@ Author const & Preamble::getAuthor(std::string const & name) const
}
int Preamble::getSpecialTableColumnArguments(char c) const
{
map<char, int>::const_iterator it = special_columns_.find(c);
if (it == special_columns_.end())
return -1;
return it->second;
}
void Preamble::add_package(string const & name, vector<string> & options)
{
// every package inherits the global options
@ -1240,7 +1246,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
TeX2LyXDocClass & tc)
{
// initialize fixed types
special_columns['D'] = 3;
special_columns_['D'] = 3;
bool is_full_document = false;
bool is_lyx_file = false;
bool in_lyx_preamble = false;
@ -1705,7 +1711,7 @@ void Preamble::parse(Parser & p, string const & forceclass,
istringstream is(string(opts, 1));
is >> nargs;
}
special_columns[name[0]] = nargs;
special_columns_[name[0]] = nargs;
h_preamble << "\\newcolumntype{" << name << "}";
if (nargs)
h_preamble << "[" << nargs << "]";

View File

@ -85,6 +85,9 @@ public:
void registerAuthor(std::string const & name);
/// Get author named \p name (must be registered first)
Author const & getAuthor(std::string const & name) const;
/// Get number of arguments of special table column type \c or -1
/// if no column type \p c exists
int getSpecialTableColumnArguments(char c) const;
/// Parses the LaTeX preamble into internal data
void parse(Parser & p, std::string const & forceclass,
@ -214,7 +217,10 @@ private:
///
void handle_if(Parser & p, bool in_lyx_preamble);
///
AuthorList authors_;
/// special table column types
std::map<char, int> special_columns_;
};

View File

@ -31,9 +31,6 @@ using namespace std;
namespace lyx {
// filled in preamble.cpp
map<char, int> special_columns;
namespace {
@ -420,30 +417,23 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
next.special += t.character();
next.special += '{' + p.verbatim_item() + '}';
break;
default:
default: {
// try user defined column types
if (special_columns.find(t.character()) !=
special_columns.end()) {
// unknown column types (nargs == -1) are
// assumed to consume no arguments
ci2special(next);
next.special += t.character();
int const nargs =
special_columns[t.character()];
preamble.getSpecialTableColumnArguments(t.character());
for (int i = 0; i < nargs; ++i)
next.special += '{' +
p.verbatim_item() +
'}';
p.verbatim_item() + '}';
colinfo.push_back(next);
next = ColInfo();
} else {
// unknown column specifier, assume no arguments
ci2special(next);
next.special += t.character();
colinfo.push_back(next);
next = ColInfo();
}
break;
}
}
}
// Maybe we have some column separators that need to be added to the
// last column?