std::string Input;
// The input line with comments stripped.
std::string Fragment;
+
+ // Grab the next line of F and place it in Input.
do
{
char *Buffer = new char[1024];
}
while (F.fail() && !F.eof());
+ // Expand tabs in the input line and remove leading and trailing
+ // whitespace.
{
- // Allocate enough space to expand an entire line of tabs
- // below.
const int BufferSize = Input.size() * 8 + 1;
char *Buffer = new char[BufferSize];
try
}
CurLine++;
+ // Now strip comments; if the whole line is contained in a
+ // comment, skip this line.
+
// The first meaningful character in the current fragment; will
// be adjusted below as we remove bytes from the front.
std::string::const_iterator Start = Input.begin();
if (Fragment.empty())
continue;
- // We now have a valid line fragment. Walk down it and
- // interpret it.
+ // The line has actual content; interpret what it means.
InQuote = false;
Start = Fragment.begin();
End = Fragment.end();
for (std::string::const_iterator I = Start;
I != End; ++I)
{
- if(Start > End)
- {
- _error->Error("Why is Start > End?");
- }
-
if (*I == '"')
InQuote = !InQuote;
if (InQuote == false && (*I == '{' || *I == ';' || *I == '}'))
{
// Put the last fragment into the buffer
- std::string::const_iterator FirstNonWhitespace = Start;
- std::string::const_iterator LastNonWhitespace = I;
- for (; FirstNonWhitespace != I && isspace(*FirstNonWhitespace) != 0; FirstNonWhitespace++)
+ std::string::const_iterator NonWhitespaceStart = Start;
+ std::string::const_iterator NonWhitespaceStop = I;
+ for (; NonWhitespaceStart != I && isspace(*NonWhitespaceStart) != 0; NonWhitespaceStart++)
;
- for (; LastNonWhitespace != FirstNonWhitespace && isspace(LastNonWhitespace[-1]) != 0; LastNonWhitespace--)
+ for (; NonWhitespaceStop != NonWhitespaceStart && isspace(NonWhitespaceStop[-1]) != 0; NonWhitespaceStop--)
;
- if (LineBuffer.empty() == false && LastNonWhitespace - FirstNonWhitespace != 0)
+ if (LineBuffer.empty() == false && NonWhitespaceStop - NonWhitespaceStart != 0)
LineBuffer += ' ';
- LineBuffer += string(FirstNonWhitespace, LastNonWhitespace);
+ LineBuffer += string(NonWhitespaceStart, NonWhitespaceStop);
// Drop this from the input string, saving the character
// that terminated the construct we just closed. (i.e., a