1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/*
méthode qui vérifie la validité de la chaîne rentrée par l'utilisateur et si possible construit chA et chB
*/
void CAISBasicDoc::parsage(const string str,string &souschA,string &souschB, bool &estValide)
{
estValide = true;
size_t foundv,foundvdouble,foundA,foundB,foundAdouble,foundBdouble,foundspaceA,foundspaceB,found1,found2;
foundv = str.find(",");
if(foundv==string::npos)
estValide = false;
else
{
foundvdouble = str.find(",",foundv+1);
if(foundvdouble!=string::npos)
estValide = false;
else
{
foundA = str.find("(A)");
foundB = str.find("(B)");
if(
foundA == string::npos
||
foundB == string::npos
||
!((0 <= foundA && foundA + 3 < foundv && foundB > foundv && foundB + 3 < str.length()) || (0 <= foundB && foundB + 3 < foundv && foundA > foundv && foundA + 3 < str.length()))
)
estValide = false;
else
{
foundAdouble = str.find("(A)",foundA+1);
foundBdouble = str.find("(B)",foundB+1);
if(foundAdouble!=string::npos || foundBdouble!=string::npos)
estValide = false;
else
{
if(0 <= foundA && foundA + 3 < foundv && foundB > foundv && foundB + 3 < str.length())
{
souschA = str.substr(foundA + 3, foundv - foundA - 3);
souschB = str.substr(foundB + 3);
}
else
{
souschA = str.substr(foundA + 3);
souschB = str.substr(foundB + 3, foundv - foundB - 3);
}
foundspaceA = souschA.find_last_not_of(" ");
foundspaceB = souschB.find_last_not_of(" ");
if (foundspaceA==string::npos || foundspaceB==string::npos)
estValide = false;
else
{
souschA = souschA.substr(souschA.find_first_not_of(" "));
found1 = souschA.find_last_not_of(" ");
if(found1!=string::npos)
souschA.erase(found1 + 1);
souschB = souschB.substr(souschB.find_first_not_of(" "));
found2 = souschB.find_last_not_of(" ");
if(found2!=string::npos)
souschB.erase(found2 + 1);
}
}
}
}
}
} |
Partager