]> git.lyx.org Git - lyx.git/blobdiff - src/lyxlex_pimpl.C
lyxstring compile fixes ; small stuff
[lyx.git] / src / lyxlex_pimpl.C
index 1f8309193da6aa09c3e2d1404582670d6e31a91b..bcb41376211e00a5e3b20d7844be60e2142cf944 100644 (file)
@@ -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;
 }
@@ -53,7 +56,7 @@ void LyXLex::Pimpl::printError(string const & message) const
 void LyXLex::Pimpl::printTable(ostream & os)
 {
        os << "\nNumber of tags: " << no_items << '\n';
-       for(int i= 0; i < no_items; ++i)
+       for (int i= 0; i < no_items; ++i)
                os << "table[" << i
                   << "]:  tag: `" << table[i].tag
                   << "'  code:" << table[i].code << '\n';
@@ -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;