X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxlex_pimpl.C;h=bcb41376211e00a5e3b20d7844be60e2142cf944;hb=ab254289c832cd045c56e6012d14b048618cb833;hp=2dcd2c054cd4b4ac60ba4850c532522dec2d48ff;hpb=adaef99e60e28eba8c413a3472cc71e234718af0;p=lyx.git diff --git a/src/lyxlex_pimpl.C b/src/lyxlex_pimpl.C index 2dcd2c054c..bcb4137621 100644 --- a/src/lyxlex_pimpl.C +++ b/src/lyxlex_pimpl.C @@ -22,7 +22,10 @@ struct compare_tags { // used by lower_bound, sort and sorted inline int operator()(keyword_item const & a, keyword_item const & b) const { - return compare_no_case(a.tag, b.tag) < 0; + // we use the ascii version, because in turkish, 'i' + // is not the lowercase version of 'I', and thus + // turkish locale breaks parsing of tags. + return compare_ascii_no_case(a.tag, b.tag) < 0; } }; // } // end of anon namespace @@ -30,7 +33,7 @@ struct compare_tags { LyXLex::Pimpl::Pimpl(keyword_item * tab, int num) : is(&fb__), table(tab), no_items(num), - status(0), lineno(0) + status(0), lineno(0), commentChar('#') { verifyTable(); } @@ -44,7 +47,7 @@ string const LyXLex::Pimpl::GetString() const void LyXLex::Pimpl::printError(string const & message) const { - string tmpmsg = subst(message, "$$Token", GetString()); + string const tmpmsg = subst(message, "$$Token", GetString()); lyxerr << "LyX: " << tmpmsg << " [around line " << lineno << " of file " << MakeDisplayPath(name) << ']' << endl; } @@ -65,7 +68,7 @@ void LyXLex::Pimpl::verifyTable() { // Check if the table is sorted and if not, sort it. if (table - && !sorted(table, table + no_items, compare_tags())) { + && !lyx::sorted(table, table + no_items, compare_tags())) { lyxerr << "The table passed to LyXLex is not sorted!\n" << "Tell the developers to fix it!" << endl; // We sort it anyway to avoid problems. @@ -130,14 +133,30 @@ void LyXLex::Pimpl::setStream(istream & i) lineno = 0; } +void LyXLex::Pimpl::setCommentChar(char c) +{ + commentChar = c; +} + bool LyXLex::Pimpl::next(bool esc /* = false */) { if (!pushTok.empty()) { - pushTok.copy(buff, string::npos); - buff[pushTok.length()] = '\0'; - pushTok.erase(); - return true; + // There can have been a whole line pushed so + // we extract the first word and leaves the rest + // in pushTok. (Lgb) + if (pushTok.find(' ') != string::npos) { + string tmp; + pushTok = split(pushTok, tmp, ' '); + tmp.copy(buff, string::npos); + buff[tmp.length()] = '\0'; + return true; + } else { + pushTok.copy(buff, string::npos); + buff[pushTok.length()] = '\0'; + pushTok.erase(); + return true; + } } if (!esc) { unsigned char c = 0; // getc() returns an int @@ -146,7 +165,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */) while (is && !status) { is.get(cc); c = cc; - if (c == '#') { + if (c == commentChar) { // Read rest of line (fast :-) // That is not fast... (Lgb) #if 1 @@ -154,7 +173,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */) lyxerr[Debug::LYXLEX] << "Comment read: `" << c << buff << "'" << endl; #else - // unfortunately is ignore buggy (Lgb) + // unfortunately ignore is buggy (Lgb) is.ignore(100, '\n'); #endif ++lineno; @@ -262,7 +281,7 @@ bool LyXLex::Pimpl::next(bool esc /* = false */) continue; } - if (c == '#') { + if (c == commentChar) { // Read rest of line (fast :-) // That is still not fast... (Lgb) #if 1 @@ -381,8 +400,8 @@ bool LyXLex::Pimpl::EatLine() while(is && c != '\n' && i != (LEX_MAX_BUFF - 1)) { is.get(cc); c = cc; - lyxerr[Debug::LYXLEX] << "LyXLex::EatLine read char: `" - << c << "'" << endl; + //lyxerr[Debug::LYXLEX] << "LyXLex::EatLine read char: `" + // << c << "'" << endl; if (c != '\r') buff[i++] = c; } @@ -407,10 +426,21 @@ bool LyXLex::Pimpl::EatLine() bool LyXLex::Pimpl::nextToken() { if (!pushTok.empty()) { - pushTok.copy(buff, string::npos); - buff[pushTok.length()] = '\0'; - pushTok.erase(); - return true; + // There can have been a whole line pushed so + // we extract the first word and leaves the rest + // in pushTok. (Lgb) + if (pushTok.find(' ') != string::npos) { + string tmp; + pushTok = split(pushTok, tmp, ' '); + tmp.copy(buff, string::npos); + buff[tmp.length()] = '\0'; + return true; + } else { + pushTok.copy(buff, string::npos); + buff[pushTok.length()] = '\0'; + pushTok.erase(); + return true; + } } status = 0;