X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftex2lyx%2FParser.cpp;h=41ab92063c031a50b2a496d67dd75de963f039a6;hb=a7aef29600ee5cb01212e2fa9316f57c5b979b27;hp=1f9ae6c3c553d9ebac9ca097a3713a715d582cf8;hpb=df4f08862e6827017664c4a56e7e251d03f80400;p=lyx.git diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index 1f9ae6c3c5..41ab92063c 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -12,7 +12,6 @@ #include "Encoding.h" #include "Parser.h" -#include "support/foreach.h" #include "support/lstrings.h" #include "support/textutils.h" @@ -154,10 +153,15 @@ iparserdocstream & iparserdocstream::get(char_type &c) // -Parser::Parser(idocstream & is) - : lineno_(0), pos_(0), iss_(0), is_(is), encoding_iconv_("UTF-8"), - theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES) +Parser::Parser(idocstream & is, std::string const & fixedenc) + : lineno_(0), pos_(0), iss_(0), is_(is), + encoding_iconv_(fixedenc.empty() ? "UTF-8" : fixedenc), + theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES), + fixed_enc_(!fixedenc.empty()) { + if (fixed_enc_) + is_.setEncoding(fixedenc); + catInit(); } @@ -165,8 +169,11 @@ Parser::Parser(string const & s) : lineno_(0), pos_(0), iss_(new idocstringstream(from_utf8(s))), is_(*iss_), encoding_iconv_("UTF-8"), - theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES) + theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES), + // An idocstringstream can not change the encoding + fixed_enc_(true) { + catInit(); } @@ -261,7 +268,12 @@ bool Parser::setEncoding(std::string const & e) { //cerr << "setting encoding to " << e << std::endl; encoding_iconv_ = e; - is_.setEncoding(e); + // If the encoding is fixed, we must not change the stream encoding + // (because the whole input uses that encoding, e.g. if it comes from + // the clipboard). We still need to track the original encoding in + // encoding_iconv_, so that the generated output is correct. + if (!fixed_enc_) + is_.setEncoding(e); return true; } @@ -308,11 +320,10 @@ Token const Parser::next_next_token() return dummy; // If tokenize_one() has not been called after the last get_token() we // need to tokenize two more tokens. - if (pos_ >= tokens_.size()) { + if (pos_ >= tokens_.size()) + tokenize_one(); + if (pos_ + 1 >= tokens_.size()) tokenize_one(); - if (pos_ + 1 >= tokens_.size()) - tokenize_one(); - } return pos_ + 1 < tokens_.size() ? tokens_[pos_ + 1] : dummy; } @@ -694,7 +705,7 @@ string Parser::verbatimOption() putback(); res += '{' + verbatim_item() + '}'; } else - res += t.cs(); + res += t.asInput(); } } return res;