I have written a fairly complex parsing tool that is used to parse information from company documents. The program works very well, but in order to insure that all the data is copied properly, I had to remove some of the things that are not part of the data, but are simply headings. Here is what I mean:
Expand|Select|Wrap|Line Numbers
- *Heading
- <CODE1> = <COMMAND1>
- <CODE2> = <COMMAND2>
Here is the problem: when retrieving <COMMAND1> directly below the heading, the code isn't simply <CODE1>, but all the stuff in the heading is part of it. What I mean is, if I want to get whatever is stored as <COMMAND2>, I would type:
Expand|Select|Wrap|Line Numbers
- CMapStringToStringObject["<CODE2>"]
Expand|Select|Wrap|Line Numbers
- CMapStringToStringObject["*Heading\n<CODE1>"]
So here is what I put before the printing is done:
Expand|Select|Wrap|Line Numbers
- int i = 0;
- BOOL newLine = false, text = false;
- std_string code , cmd, dummy;
- while (std::getline(input, code, input.widen('='))) { //reads in characters until the '='
- std::getline(input,cmd); //reads in remaining characters in the line
- code.erase(code.begin() + (code.size()-1)); //erase last character, a whitespace
- cmd.erase(cmd.begin()); //erase first character, a whitespace
- while (code[0] != '<') { //checks if the first character of 'code' is not <
- if (code[0] == '\n') {
- newLine = true;
- } else {
- text = true;
- }
- dummy[i] = code[0];
- code.erase(code.begin());
- i++;
- }
- if (newLine) { //checks if there has been a newline character preceding a 'code' in this iteration
- wcout << endl; //if there is, a newline character is printed onto console and ofstream file
- output << endl;
- }
- if (text) { //checks if there has been text preceding a 'code' in this iteration
- wcout << dummy << endl; //if there is, the text is printed onto console and ofstream file
- output << dummy << endl;
- }
- newLine = false; //resets the value for newLine to false
- text = false;
- i = 0;
- }
Expand|Select|Wrap|Line Numbers
- while (code[0] != '<') { //checks if the first character of 'code' is not <
- if (code[0] == '\n') {
- newLine = true;
- } else {
- text = true;
- }
- dummy[i] = code[0];
- code.erase(code.begin());
- i++;
- }