Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

readline.cc

Go to the documentation of this file.
00001 #include <fstream>
00002 #include <string>
00003 #include <iostream>
00004 
00005 #include "Debug.h"
00006 #include "readline.h"
00007 
00008 using namespace std;
00009 
00010 int nlreadline(istream & is,    // Input-Stream
00011                string & strg,   // String to store line
00012                int keepnl       // Keep newline
00013     )
00014 {
00015         int pos, len;
00016         try {
00017                 getline(is, strg);
00018         } catch(...) {
00019                 // FIXME: should be improved or removed (Debugging)
00020                 slog.p(Logger::Error) << "nlreadline: Error in getline\n";
00021                 exit(1);
00022         }
00023         pos = len = strg.length();
00024         while (pos) {
00025                 pos--;
00026                 if (strg[pos] != '\r' && strg[pos] != '\n') {
00027                         pos++;
00028                         break;
00029                 }
00030         }
00031         if (keepnl) {
00032                 strg.replace(pos, len - pos, "\r\n");
00033         } else {
00034                 strg.replace(pos, len - pos, (char *) NULL, 0);
00035         }
00036         return strg.length();
00037 }
00038 
00039 int readtext(istream & is,      // Input-Stream
00040              string & strg,     // String to store line
00041              int keepnl,        // Keep newlines in text
00042              char *eot          // EndOfText Marker
00043     )
00044 {
00045         int lines = 0;
00046         string line;
00047 
00048         for (;;) {
00049                 nlreadline(is, line, keepnl);
00050                 if (line == eot)
00051                         break;
00052                 if (!is.good()) {
00053                         if (is.eof())
00054                                 break;
00055                         break;
00056                 }
00057                 strg += line;
00058                 lines++;
00059         }
00060 
00061         return lines;
00062 }

Generated on Fri Aug 20 10:58:08 2004 for NewsCache by doxygen 1.3.6-20040222