maintenance: string search methods

This commit is contained in:
tmj-fstate
2021-05-27 14:23:00 +02:00
parent b3940d47cb
commit 7b816594ba
23 changed files with 120 additions and 106 deletions

View File

@@ -287,7 +287,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
while (fin.good() && !((ConversionError != 0) || EndTable))
{
std::getline(fin, lines); /*wczytanie linii*/
if (lines.find("___________________") != std::string::npos) /*linia pozioma górna*/
if (contains( lines, "___________________") ) /*linia pozioma górna*/
{
fin >> s;
if (s == "[") /*lewy pion*/
@@ -312,7 +312,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
TrainName = s; // nadanie nazwy z pliku TXT (bez ścieżki do pliku)
while (fin >> s || fin.bad())
{
if (s.find("_______|") != std::string::npos)
if (contains( s,"_______|") )
{
break;
}
@@ -393,7 +393,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
do
{
fin >> s;
} while (!(s.find("[______________") != std::string::npos || fin.bad()));
} while (!(contains( s,"[______________" ) || fin.bad()));
auto activeradiochannel{ -1 };
while (!fin.bad() && !EndTable)
{
@@ -408,21 +408,20 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
else
ConversionError = -4;
if (s.find("|") == std::string::npos)
if (false == contains( s,"|") )
{
record->km = atof(s.c_str());
fin >> s;
}
if (s.find("|_____|") !=
std::string::npos) /*zmiana predkosci szlakowej*/
if (contains( s,"|_____|")) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual);
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains( s,"|"))
fin >> s;
fin >> record->StationName;
// get rid of non-ascii chars. TODO: run correct version based on locale
@@ -435,7 +434,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
if (s != "|")
{
if (s.find(hrsd) != std::string::npos)
if (contains( s, hrsd) )
{
record->Ah = atoi( s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu
record->Am = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu
@@ -457,7 +456,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
} while (!((s == "[") || fin.bad()));
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
{
/*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s;
@@ -468,10 +467,10 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains(s,"|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains(s,"|"))
fin >> s;
// stationware. added fix for empty entry
fin >> s;
@@ -482,7 +481,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
}
// cache relevant station data
record->is_maintenance = ( s.find( "pt" ) != std::string::npos );
record->is_maintenance = ( contains( s, "pt" ) );
{
auto const stationware { Split( record->StationWare, ',' ) };
for( auto const &entry : stationware ) {
@@ -510,7 +509,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
if (s != "|")
{
if (s.find(hrsd) != std::string::npos)
if (contains( s, hrsd) )
{
record->Dh = atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu
record->Dm = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu
@@ -535,28 +534,27 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
do
{
fin >> s;
} while (!((s.find("[") != std::string::npos) || fin.bad()));
if (s.find("_|_") == std::string::npos)
} while (!(contains( s, "[" ) || fin.bad()));
if (false == contains( s, "_|_"))
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains( s, "|"))
{
/*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s;
}
if (s.find("|_____|") !=
std::string::npos) /*zmiana predkosci szlakowej*/
if (contains( s, "|_____|") ) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual);
else
{
fin >> s;
if (s.find("|") == std::string::npos)
if (false == contains( s, "|"))
vActual = atof(s.c_str());
}
while (s.find("|") == std::string::npos)
while (false == contains( s, "|" ) )
fin >> s;
while ((s.find("]") == std::string::npos))
while ((false == contains( s,"]") ))
fin >> s;
if (s.find("_|_") != std::string::npos)
if (contains( s,"_|_") )
EndTable = true;
} /*timetableline*/
}
@@ -633,7 +631,7 @@ bool TTrainParameters::DirectionChange()
// sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy
{
if ((StationIndex > 0) && (StationIndex < StationCount)) // dla ostatniej stacji nie
if (TimeTable[StationIndex].StationWare.find('@') != std::string::npos)
if (contains( TimeTable[StationIndex].StationWare, '@') )
return true;
return false;
}