void Sintatico::Analisador::TransformaLexico(QString _filename) { QFile arquivo; arquivo.setFileName(_filename); arquivo.open(QIODevice::ReadOnly); QTextStream tsFile(&arquivo); while(!tsFile.atEnd()){ QString line = tsFile.readLine(); //remove o nome do arquivo while(line[0]!=':'){ line.remove(0,1); } line.remove(0,1); //tranforma string em Stream QTextStream tsLine(&line,QIODevice::ReadOnly); //Contador de linhas int lineCount; //le o numero da linha tsLine>>lineCount; //remove caracteres de controle line.remove(0,2); line.replace(',',' '); line.replace('[',' '); line.replace(']',' '); //lê os tokens while(!tsLine.atEnd()){ //remove '[' Tokens temp; temp.linha = lineCount; tsLine>>temp.token_class; tsLine>>temp.value; if(!temp.value.isEmpty()){ this->valores_lexico.append(temp); // qDebug()<<temp.value<<" - "<<temp.token_class; } } } }
void Transforma(QFile &arquivo, QList<Tokens*> * tokens) { QTextStream tsFile(&arquivo); while(!tsFile.atEnd()){ QString line = tsFile.readLine(); //remove o nome do arquivo while(line[0]!=':'){ line.remove(0,1); } line.remove(0,1); //tranforma string em Stream QTextStream tsLine(&line,QIODevice::ReadOnly); //Contador de linhas int lineCount; //le o numero da linha tsLine>>lineCount; //remove caracteres de controle line.remove(0,2); line.replace(',',' '); line.replace('[',' '); line.replace(']',' '); //lê os tokens while(!tsLine.atEnd()){ //remove '[' Tokens * temp = new Tokens(); temp->linha = lineCount; tsLine>>temp->Classificacao; tsLine>>temp->token; if(!temp->token.isEmpty()){ tokens->append(temp); qDebug()<<temp->token<<" - "<<temp->Classificacao; } } } }
bool TfrmEnterResults::fnParseLine(String strLine) { pEmpowerOutputRow TheEmpowerOutputRow; char *szTok, *szLine; // cheap test to see if input is valid: szLine = strLine.c_str(); int count = 0; while (*szLine != '\0') if (*szLine++ == ',') count++; if (count < 5) return false; try { TheEmpowerOutputRow = new EmpowerOutputRow; TokenString tsLine(strLine, ","); /*if (IDYES == APPMSG("tsLine: "+String(tsLine), "", MB_YESNO)) { String temp; temp = "Barcode: "+tsLine.First(); temp += "Test: "+tsLine.Next(); temp += "Conc: "+tsLine.Next(); temp += "Height: "+tsLine.Next(); temp += "Date: "+tsLine.Next(); temp += "Vial: "+tsLine.Next(); APPMSG("Result:\n"+temp, "", MB_OK); } */ String strTok; // # <row number> strTok = tsLine.First(); if (strTok.IsEmpty()) throw Exception("Missing row number"); TheEmpowerOutputRow->iRow = atoi(strTok.c_str()); // SampleName <sample barcode> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing barcode"); TheEmpowerOutputRow->strBarcode = fnTrimQuotes(strTok); // Name <test ID> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing test ID"); TheEmpowerOutputRow->strTestID = fnTrimQuotes(strTok); // Concentration <result value> strTok = tsLine.Next(); if (strTok.IsEmpty()) TheEmpowerOutputRow->flResultValue = -1; else TheEmpowerOutputRow->flResultValue = atof(strTok.c_str()); // Area/Height <peak area/height of component> strTok = tsLine.Next(); if (strTok.IsEmpty()) TheEmpowerOutputRow->flAreaHeight = -1; else TheEmpowerOutputRow->flAreaHeight = atof(strTok.c_str()); // Date Acquired <date of analysis> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing date"); TheEmpowerOutputRow->tdtDateOfAnalysis = TDateTime::TDateTime(fnTrimQuotes(strTok), TDateTime::DateTime); // Vial <vial number when analysed> strTok = tsLine.Next(); if (strTok.IsEmpty()) throw Exception("Missing vial number"); TheEmpowerOutputRow->iVialNum = atoi(fnTrimQuotes(strTok).c_str()); //APPMSG("Result: "+String(*TheEmpowerOutputRow), "", MB_OK); vecpEmpowerOutputRows.push_back(TheEmpowerOutputRow); } catch (Exception &e) { APPMSG(e.Message, "Error", MB_OK); delete TheEmpowerOutputRow; return false; } return true; }