Changeset 27563
- Timestamp:
- 11/16/08 18:02:00 (2 months ago)
- Files:
-
- lyx-devel/trunk/src/tex2lyx/Parser.cpp (modified) (17 diffs)
- lyx-devel/trunk/src/tex2lyx/Parser.h (modified) (7 diffs)
- lyx-devel/trunk/src/tex2lyx/math.cpp (modified) (1 diff)
- lyx-devel/trunk/src/tex2lyx/preamble.cpp (modified) (1 diff)
- lyx-devel/trunk/src/tex2lyx/table.cpp (modified) (1 diff)
- lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp (modified) (6 diffs)
- lyx-devel/trunk/src/tex2lyx/text.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lyx-devel/trunk/src/tex2lyx/Parser.cpp
r27489 r27563 14 14 15 15 #include <iostream> 16 #include <sstream>17 16 18 17 using namespace std; … … 55 54 } 56 55 57 58 56 /*! 59 57 * Translate a line ending to '\n'. … … 61 59 * from \p is. 62 60 */ 63 char getNewline(i stream & is, char c)61 char getNewline(idocstream & is, char c) 64 62 { 65 63 // we have to handle 3 different line endings: … … 69 67 if (c == '\r') { 70 68 // MAC or DOS 71 if (is.get(c) && c != '\n') { 69 char_type wc; 70 if (is.get(wc) && wc != '\n') { 72 71 // MAC 73 is.putback( c);72 is.putback(wc); 74 73 } 75 74 return '\n'; … … 79 78 } 80 79 81 } 82 83 84 // 85 // catcodes 86 // 87 88 CatCode catcode(unsigned char c) 89 { 90 return theCatcode[c]; 91 } 92 80 CatCode catcode(char_type c) 81 { 82 if (c < 256) 83 return theCatcode[(unsigned char)c]; 84 return catOther; 85 } 86 87 } 93 88 94 89 … … 106 101 os << '\\' << t.cs() << ' '; 107 102 else if (t.cat() == catLetter) 108 os << t.c haracter();103 os << t.cs(); 109 104 else if (t.cat() == catNewline) 110 105 os << "[" << t.cs().size() << "\\n," << t.cat() << "]\n"; 111 106 else 112 os << '[' << t.c haracter() << ',' << t.cat() << ']';107 os << '[' << t.cs() << ',' << t.cat() << ']'; 113 108 return os; 114 109 } … … 117 112 string Token::asString() const 118 113 { 119 return cs_ .size() ? cs_ : string(1, char_);114 return cs_; 120 115 } 121 116 … … 125 120 if (cat_ == catComment) 126 121 return '%' + cs_ + '\n'; 127 if (cat_ == cat Space || cat_ == catNewline)128 return cs_;129 return c har_ ? string(1, char_) : '\\' + cs_;122 if (cat_ == catEscape) 123 return '\\' + cs_; 124 return cs_; 130 125 } 131 126 … … 136 131 137 132 138 Parser::Parser(i stream & is)133 Parser::Parser(idocstream & is) 139 134 : lineno_(0), pos_(0), iss_(0), is_(is) 140 135 { … … 143 138 144 139 Parser::Parser(string const & s) 145 : lineno_(0), pos_(0), iss_(new istringstream(s)), is_(*iss_) 140 : lineno_(0), pos_(0), 141 iss_(new idocstringstream(from_utf8(s))), is_(*iss_) 146 142 { 147 143 } … … 268 264 if (!good()) 269 265 error("The input stream is not well..."); 270 return tokens_[pos_++].character();266 return get_token().character(); 271 267 } 272 268 … … 366 362 { 367 363 catInit(); 368 char c;364 char_type c; 369 365 if (!is_.get(c)) 370 366 return; 371 //cerr << "reading c: " << c << "\n";372 367 373 368 switch (catcode(c)) { 374 369 case catSpace: { 375 string s(1, c);370 docstring s(1, c); 376 371 while (is_.get(c) && catcode(c) == catSpace) 377 372 s += c; … … 384 379 case catNewline: { 385 380 ++lineno_; 386 string s(1, getNewline(is_, c));381 docstring s(1, getNewline(is_, c)); 387 382 while (is_.get(c) && catcode(c) == catNewline) { 388 383 ++lineno_; … … 398 393 // We don't treat "%\n" combinations here specially because 399 394 // we want to preserve them in the preamble 400 string s;395 docstring s; 401 396 while (is_.get(c) && catcode(c) != catNewline) 402 397 s += c; … … 416 411 error("unexpected end of input"); 417 412 } else { 418 string s(1, c);413 docstring s(1, c); 419 414 if (catcode(c) == catLetter) { 420 415 // collect letters … … 430 425 431 426 case catIgnore: { 432 cerr << "ignoring a char: " << int(c)<< "\n";427 cerr << "ignoring a char: " << c << "\n"; 433 428 break; 434 429 } 435 430 436 431 default: 437 push_back(Token(c, catcode(c))); 438 } 432 push_back(Token(docstring(1, c), catcode(c))); 433 } 434 //cerr << tokens_.back(); 439 435 } 440 436 … … 465 461 if (next_token().character() == '[') { 466 462 Token t = get_token(); 467 for ( Tokent = get_token(); t.character() != ']' && good(); t = get_token()) {463 for (t = get_token(); t.character() != ']' && good(); t = get_token()) { 468 464 if (t.cat() == catBegin) { 469 465 putback(); lyx-devel/trunk/src/tex2lyx/Parser.h
r27489 r27563 13 13 #define PARSER_H 14 14 15 #include <vector>16 15 #include <string> 17 16 #include <utility> 18 17 #include <vector> 18 19 #include "support/docstream.h" 19 20 20 21 namespace lyx { … … 47 48 48 49 49 CatCode catcode(unsigned char c);50 51 52 50 enum { 53 51 FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing … … 76 74 public: 77 75 /// 78 Token() : cs_(), char_(0), cat_(catIgnore) {} 79 /// 80 Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {} 81 /// 82 Token(std::string const & cs, CatCode cat) : cs_(cs), char_(0), cat_(cat) {} 76 Token() : cs_(), cat_(catIgnore) {} 77 /// 78 Token(docstring const & cs, CatCode cat) : cs_(to_utf8(cs)), cat_(cat) {} 83 79 84 80 /// … … 87 83 CatCode cat() const { return cat_; } 88 84 /// 89 char character() const { return c har_; }85 char character() const { return cs_.empty() ? 0 : cs_[0]; } 90 86 /// Returns the token as string 91 87 std::string asString() const; … … 96 92 /// 97 93 std::string cs_; 98 ///99 char char_;100 94 /// 101 95 CatCode cat_; … … 120 114 public: 121 115 /// 122 Parser( std::istream & is);116 Parser(idocstream & is); 123 117 /// 124 118 Parser(std::string const & s); … … 218 212 unsigned pos_; 219 213 /// 220 std::istringstream * iss_;221 /// 222 std::istream & is_;214 idocstringstream * iss_; 215 /// 216 idocstream & is_; 223 217 }; 224 218 lyx-devel/trunk/src/tex2lyx/math.cpp
r27425 r27563 95 95 t.cat() == catActive || 96 96 t.cat() == catParameter) 97 os << t.c haracter();97 os << t.cs(); 98 98 99 99 else if (t.cat() == catBegin) { lyx-devel/trunk/src/tex2lyx/preamble.cpp
r27425 r27563 414 414 { 415 415 os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n" 416 << "\\lyxformat 24 7\n"416 << "\\lyxformat 249\n" 417 417 << "\\begin_document\n" 418 418 << "\\begin_header\n" lyx-devel/trunk/src/tex2lyx/table.cpp
r27425 r27563 662 662 } 663 663 664 else if (t.cat() == catSpace || t.cat() == catNewline) 665 os << t.cs(); 666 667 else if (t.cat() == catLetter || 668 t.cat() == catSuper || 669 t.cat() == catSub || 670 t.cat() == catOther || 671 t.cat() == catActive || 672 t.cat() == catParameter) 673 os << t.character(); 664 else if (t.cat() == catSpace 665 || t.cat() == catNewline 666 || t.cat() == catLetter 667 || t.cat() == catSuper 668 || t.cat() == catSub 669 || t.cat() == catOther 670 || t.cat() == catActive 671 || t.cat() == catParameter) 672 os << t.cs(); 674 673 675 674 else if (t.cat() == catBegin) { lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
r27428 r27563 19 19 #include "Layout.h" 20 20 21 #include "support/lassert.h"22 21 #include "support/convert.h" 23 22 #include "support/debug.h" 24 23 #include "support/ExceptionMessage.h" 25 24 #include "support/filetools.h" 25 #include "support/lassert.h" 26 26 #include "support/lstrings.h" 27 27 #include "support/os.h" … … 29 29 30 30 #include <cstdlib> 31 #include <fstream>32 31 #include <iostream> 33 32 #include <string> … … 203 202 void read_syntaxfile(FileName const & file_name) 204 203 { 205 if stream is(file_name.toFilesystemEncoding().c_str());204 ifdocstream is(file_name.toFilesystemEncoding().c_str()); 206 205 if (!is.good()) { 207 206 cerr << "Could not open syntax file \"" << file_name … … 390 389 * this function! 391 390 */ 392 void tex2lyx(i stream & is, ostream & os)391 void tex2lyx(idocstream & is, ostream & os) 393 392 { 394 393 Parser p(is); … … 412 411 #ifdef TEST_PARSER 413 412 p.reset(); 414 of stream parsertest("parsertest.tex");413 ofdocstream parsertest("parsertest.tex"); 415 414 while (p.good()) 416 415 parsertest << p.get_token().asInput(); … … 423 422 bool tex2lyx(FileName const & infilename, ostream & os) 424 423 { 425 if stream is(infilename.toFilesystemEncoding().c_str());424 ifdocstream is(infilename.toFilesystemEncoding().c_str()); 426 425 if (!is.good()) { 427 426 cerr << "Could not open input file \"" << infilename lyx-devel/trunk/src/tex2lyx/text.cpp
r27489 r27563 1263 1263 // This translates "&" to "\\&" which may be wrong... 1264 1264 context.check_layout(os); 1265 os << t.c haracter();1265 os << t.cs(); 1266 1266 } 1267 1267 … … 1282 1282 os << "\\InsetSpace ~\n"; 1283 1283 } else 1284 os << t.c haracter();1284 os << t.cs(); 1285 1285 } 1286 1286 … … 1310 1310 p.get_token(); 1311 1311 if (p.next_token().cat() == catEnd) { 1312 os << next.c haracter();1312 os << next.cs(); 1313 1313 p.get_token(); 1314 1314 } else {
