Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/commentstream.cc
[mareframe] / trunk / gadget / commentstream.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/commentstream.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "commentstream.h"
2 :     #include "errorhandler.h"
3 :     #include "global.h"
4 :    
5 :     istream& operator >> (istream& istr, Whitespace& ws) {
6 :     int c;
7 :     while (istr.peek() == ' ' || istr.peek() == '\t' || istr.peek() == '\r' || istr.peek() == '\n')
8 :     c = istr.get();
9 :     return istr;
10 :     }
11 :    
12 :     CommentStream& ws(CommentStream& ins) {
13 :     ins.killComments();
14 :     return ins;
15 :     }
16 :    
17 :     void CommentStream::killComments() {
18 :     if (istrptr->eof())
19 :     return;
20 :    
21 :     Whitespace ws;
22 :     *istrptr >> ws;
23 :     if (istrptr->eof())
24 :     return;
25 :    
26 :     char c;
27 :     while (istrptr->peek() == chrComment) {
28 :     while (istrptr->peek() != '\n' && !(istrptr->eof()))
29 :     istrptr->get(c);
30 :     *istrptr >> ws;
31 :     }
32 :     }
33 :    
34 :     char CommentStream::peek() {
35 :     if (istrptr->peek() == chrComment) {
36 :     this->killComments();
37 :     return '\n';
38 :     } else if (istrptr->peek() == '\r') {
39 :     char tmp;
40 :     istrptr->get(tmp); //JMB get the carriage return and discard it
41 :     } else if (istrptr->peek() == '\\') {
42 :     //attempting to read backslash will do nasty things to the input stream
43 :     handle.logFileMessage(LOGFAIL, "backslash is an invalid character");
44 :     } else if ((istrptr->peek() == '\'') || (istrptr->peek() == '\"')) {
45 :     //attempting to read quote will do nasty things to the input stream
46 :     handle.logFileMessage(LOGFAIL, "quote is an invalid character");
47 :     }
48 :     //JMB GCC 4.3 has a stricter implemenation of the C++ standard
49 :     //so we need to cast this to a char to avoid generating warnings
50 :     return (char)istrptr->peek();
51 :     }
52 :    
53 :     CommentStream& CommentStream::get(char& c) {
54 :     if (istrptr->peek() == chrComment) {
55 :     this->killComments();
56 :     c = '\n';
57 :     } else if (istrptr->peek() == '\r') {
58 :     char tmp;
59 :     istrptr->get(tmp); //JMB throw away carriage return ...
60 :     istrptr->get(c); //JMB ... to be left with end of line
61 :     } else
62 :     istrptr->get(c);
63 :     return *this;
64 :     }
65 :    
66 :     CommentStream& CommentStream::getLine(char* text, int length) {
67 :     int i = 0;
68 :     while ((i < length - 2) && (istrptr->peek() != chrComment)
69 :     && (istrptr->peek() != '\n') && (istrptr->peek() != '\r'))
70 :     text[i++] = (char)istrptr->get();
71 :    
72 :     if ((istrptr->peek() == '\n') || (istrptr->peek() == '\r'))
73 :     text[i++] = (char)istrptr->get();
74 :     text[i] = '\0';
75 :     return *this;
76 :     }
77 :    
78 :     CommentStream& CommentStream::operator >> (int& a) {
79 :     this->killComments();
80 :     (*istrptr) >> a;
81 :     return *this;
82 :     }
83 :    
84 :     CommentStream& CommentStream::operator >> (double& a) {
85 :     this->killComments();
86 :     (*istrptr) >> a;
87 :     return *this;
88 :     }
89 :    
90 :     CommentStream& CommentStream::operator >> (char* a) {
91 :     this->killComments();
92 :     string s;
93 :     (*istrptr) >> s;
94 :     s.copy(a, string::npos);
95 :     a[s.length()] = '\0';
96 :     return *this;
97 :     }
98 :    
99 :     CommentStream& CommentStream::operator >> (__commentmanip func) {
100 :     (*func)(*this);
101 :     return *this;
102 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge