Reference no: EM13168456
There is segmentation fault in this code and I don't know where or how to fix it. The purpose of this code right here is to grab the tokens from the token vecctor and find single quotes. Then combine the single quote string into one token and the fix the rest of the token vector.
Example:
Label Code C'Program 5' test
This should be four tokens
Fix the code or give me a replacement.
void file_parser::check_quote(vector<string> tokens)
{
bool has_quote = false;
string tmpstr;
unsigned int FirstQuote = 0;
unsigned int SecondQuote;
string tmp;
string tmpstr2;
for (unsigned int i = 0; i <= tokens.size() - 1; i++) {
tmp = tokens[i].c_str();
for (unsigned int m = 0; m <= tmp.size() - 1; m++) {
if (tmp[m] == '\'') {
has_quote = true;
FirstQuote = m;
}
if (has_quote && m != FirstQuote && tmp[m] == '\'') {
SecondQuote = m;
for (unsigned int k = FirstQuote; k <= SecondQuote; k++) {
tmpstr += tokens[k];
}
tokens.insert(tokens.begin() + FirstQuote, tmpstr);
for (unsigned int j = FirstQuote + 1; j <= tokens.size() - 1; j++) {
for (unsigned int l = SecondQuote + 1; l <= tokens.size() - 1; l++) {
tmpstr2 = tokens[SecondQuote + 1];
tokens.insert(tokens.begin() + j, tmpstr2);
}
}
int test = tokens.size() - SecondQuote + 1;
while (test > 0) {
tokens.erase(tokens.end() - 1);
}
}
}
}
}