00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include "sourcetext.h"
00020 #include "exceptions.h"
00021 #include "file.h"
00022
00023
00024 void SourceText::AppendFile(const String& name)
00025 {
00026 mSfLine.push_back(mText.nelem());
00027 mSfName.push_back(name);
00028
00029 read_text_from_file(mText, name);
00030 }
00031
00032
00033 void SourceText::AdvanceChar()
00034 {
00035 if ( mColumn < mText[mLine].nelem()-1 )
00036 {
00037 ++mColumn;
00038 }
00039 else
00040 {
00041 mLineBreak = true;
00042 do
00043 {
00044 if (mLine>=mText.nelem()-1)
00045 {
00046 throw Eot( "",
00047 this->File(),
00048 this->Line(),
00049 this->Column() );
00050 }
00051 else
00052 {
00053 ++mLine;
00054 mColumn = 0;
00055 }
00056 }
00057 while ( 1 > mText[mLine].nelem() );
00058 }
00059 }
00060
00061
00062 void SourceText::AdvanceLine()
00063 {
00064 mLineBreak = true;
00065 mColumn = 0;
00066 do
00067 {
00068 if (mLine>=mText.nelem()-1)
00069 {
00070 throw Eot( "",
00071 this->File(),
00072 this->Line(),
00073 this->Column() );
00074 }
00075 else
00076 {
00077 ++mLine;
00078 }
00079 }
00080 while ( 1 > mText[mLine].nelem() );
00081 }
00082
00083
00084 const String& SourceText::File()
00085 {
00086 Index i = 0;
00087 bool stop = false;
00088
00089 while ( i<mSfLine.nelem()-1 && !stop )
00090 {
00091 if (mLine>=mSfLine[i+1]) ++i;
00092 else stop = true;
00093 }
00094
00095 return mSfName[i];
00096 }
00097
00098
00099 Index SourceText::Line()
00100 {
00101 Index i = 0;
00102 bool stop = false;
00103
00104 while ( i<mSfLine.nelem()-1 && !stop )
00105 {
00106 if (mLine>=mSfLine[i+1]) ++i;
00107 else stop = true;
00108 }
00109
00110 return mLine - mSfLine[i] + 1;
00111 }
00112
00113
00114 void SourceText::Init()
00115 {
00116 mLine = 0;
00117 mColumn = 0;
00118
00119 if ( 1 > mText.nelem() )
00120 {
00121 throw Eot( "Empty text!",
00122 this->File(),
00123 this->Line(),
00124 this->Column() );
00125 }
00126 else
00127 {
00128
00129 while ( 1 > mText[mLine].nelem() )
00130 {
00131 if (mLine>=mText.nelem()-1)
00132 {
00133 throw Eot( "",
00134 this->File(),
00135 this->Line(),
00136 this->Column() );
00137 }
00138 else
00139 {
00140 mLineBreak = true;
00141 ++mLine;
00142 }
00143 }
00144 }
00145 }
00146
00147
00148 ostream& operator << (ostream& os, const SourceText& text)
00149 {
00150 for (Index i=0; i<text.mText.nelem();++i)
00151 cout << i
00152 << "(" << text.mText[i].nelem() << ")"
00153 << ": " << text.mText[i] << '\n';
00154 return(os);
00155 }
00156