16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 22:09:19 +02:00

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

@@ -453,7 +453,7 @@ bool TAnimModel::Load(cParser *parser, bool ter)
{ // gdy brak modelu
if (ter) // jeśli teren
{
if( name.substr( name.rfind( '.' ) ) == ".t3d" ) {
if( ends_with( name, ".t3d" ) ) {
name[ name.length() - 3 ] = 'e';
}
#ifdef EU07_USE_OLD_TERRAINCODE
@@ -959,11 +959,11 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
// don't include 'textures/' in the path
texturefile.erase( 0, std::string{ szTexturePath }.size() );
}
if( texturefile.find( ' ' ) == std::string::npos ) {
Output << texturefile << ' ';
if( contains( texturefile, ' ' ) ) {
Output << "\"" << texturefile << "\"" << ' ';
}
else {
Output << "\"" << texturefile << "\"" << ' ';
Output << texturefile << ' ';
}
// light submodels activation configuration
if( iNumLights > 0 ) {

View File

@@ -145,7 +145,7 @@ bool TPoKeys55::Connect()
DeviceIDFromRegistry = ToLower( DeviceIDFromRegistry );
DeviceIDToFind = ToLower( DeviceIDToFind );
// Now check if the hardware ID we are looking at contains the correct VID/PID
MatchFound = ( DeviceIDFromRegistry.find( DeviceIDToFind ) != std::string::npos );
MatchFound = ( contains( DeviceIDFromRegistry, DeviceIDToFind ) );
if (MatchFound == true)
{
// Device must have been found. Open read and write handles. In order to do this,we

View File

@@ -5130,7 +5130,7 @@ void TController::OrdersInit(double fVel)
+ ", " + std::to_string(t->Dh) + ":" + std::to_string(t->Dm)
+ " " + t->StationWare);
}
if (t->StationWare.find('@') != std::string::npos)
if ( contains( t->StationWare, '@' ) )
{ // zmiana kierunku i dalsza jazda wg rozk?adu
if (iDrivigFlags & movePushPull) // SZT również! SN61 zależnie od wagonów...
{ // jeśli skład zespolony, wystarczy zmienić kierunek jazdy

View File

@@ -169,7 +169,7 @@ void
material_data::assign( std::string const &Replacableskin ) {
// check for the pipe method first
if( Replacableskin.find( '|' ) != std::string::npos ) {
if( contains( Replacableskin, '|' ) ) {
cParser nameparser( Replacableskin );
nameparser.getTokens( 4, true, "|" );
int skinindex = 0;
@@ -1172,7 +1172,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
if( cabsection ) {
// check whether we're still processing cab sections
auto const &sectionname { section.compartment->pName };
cabsection &= ( ( sectionname.size() >= 4 ) && ( sectionname.substr( 0, 3 ) == "cab" ) );
cabsection &= ( ( sectionname.size() >= 4 ) && ( starts_with( sectionname, "cab" ) ) );
}
// TODO: add cablight devices
auto const sectionlightlevel { section.light_level * ( cabsection ? 1.0f : MoverParameters->CompartmentLights.intensity ) };
@@ -1904,40 +1904,40 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
if (ActPar.substr(0, 1) == "B") // jesli hamulce
{ // sprawdzanie kolejno nastaw
WriteLog("Wpis hamulca: " + ActPar);
if (ActPar.find('G') != std::string::npos)
if ( contains( ActPar, 'G') )
{
MoverParameters->BrakeDelaySwitch(bdelay_G);
}
if( ActPar.find( 'P' ) != std::string::npos )
if( contains( ActPar, 'P' ) )
{
MoverParameters->BrakeDelaySwitch(bdelay_P);
}
if( ActPar.find( 'R' ) != std::string::npos )
if( contains( ActPar, 'R' ) )
{
MoverParameters->BrakeDelaySwitch(bdelay_R);
}
if( ActPar.find( 'M' ) != std::string::npos )
if( contains( ActPar, 'M' ) )
{
MoverParameters->BrakeDelaySwitch(bdelay_R);
MoverParameters->BrakeDelaySwitch(bdelay_R + bdelay_M);
}
// wylaczanie hamulca
if (ActPar.find("<>") != std::string::npos) // wylaczanie na probe hamowania naglego
if ( contains( ActPar, "<>") ) // wylaczanie na probe hamowania naglego
{
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
}
if (ActPar.find('0') != std::string::npos) // wylaczanie na sztywno
if ( contains( ActPar, '0' ) ) // wylaczanie na sztywno
{
MoverParameters->Hamulec->ForceEmptiness();
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
}
if (ActPar.find('E') != std::string::npos) // oprozniony
if ( contains( ActPar, 'E' ) ) // oprozniony
{
MoverParameters->Hamulec->ForceEmptiness();
MoverParameters->Pipe->CreatePress(0);
MoverParameters->Pipe2->CreatePress(0);
}
if (ActPar.find('Q') != std::string::npos) // oprozniony
if ( contains( ActPar, 'Q' ) ) // oprozniony
{
MoverParameters->Hamulec->ForceEmptiness();
MoverParameters->Pipe->CreatePress(0.0);
@@ -1949,7 +1949,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
MoverParameters->CompressedVolume = 0.0;
}
if (ActPar.find('1') != std::string::npos) // wylaczanie 10%
if ( contains( ActPar, '1' ) ) // wylaczanie 10%
{
if (Random(10) < 1) // losowanie 1/10
{
@@ -1957,7 +1957,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
}
}
if (ActPar.find('X') != std::string::npos) // agonalny wylaczanie 20%, usrednienie przekladni
if ( contains( ActPar, 'X') ) // agonalny wylaczanie 20%, usrednienie przekladni
{
if (Random(100) < 20) // losowanie 20/100
{
@@ -1990,23 +1990,23 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
}
}
// nastawianie ladunku
if (ActPar.find('T') != std::string::npos) // prozny
if ( contains( ActPar, 'T' ) ) // prozny
{
MoverParameters->DecBrakeMult();
MoverParameters->DecBrakeMult();
} // dwa razy w dol
if (ActPar.find('H') != std::string::npos) // ladowny I (dla P-Ł dalej prozny)
if ( contains( ActPar, 'H' ) ) // ladowny I (dla P-Ł dalej prozny)
{
MoverParameters->IncBrakeMult();
MoverParameters->IncBrakeMult();
MoverParameters->DecBrakeMult();
} // dwa razy w gore i obniz
if (ActPar.find('F') != std::string::npos) // ladowny II
if ( contains( ActPar, 'F' ) ) // ladowny II
{
MoverParameters->IncBrakeMult();
MoverParameters->IncBrakeMult();
} // dwa razy w gore
if (ActPar.find('N') != std::string::npos) // parametr neutralny
if ( contains( ActPar, 'N' ) ) // parametr neutralny
{
}
} // koniec hamulce

View File

@@ -297,8 +297,9 @@ basic_event::deserialize( cParser &Input, scene::scratch_data &Scratchpad ) {
Input >> token;
deserialize_targets( token );
if (m_name.substr(0, 5) == "none_")
if( starts_with( m_name, "none_" ) ) {
m_ignored = true; // Ra: takie są ignorowane
}
deserialize_( Input, Scratchpad );
// subclass method is expected to leave next token past its own data preloaded on its exit
@@ -712,9 +713,10 @@ putvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
Input.getTokens( 1, false ); // komendy 'case sensitive'
Input >> token;
// command type, previously held in param 6
if( token.substr( 0, 19 ) == "PassengerStopPoint:" ) {
if( token.find( '#' ) != std::string::npos )
if( starts_with( token, "PassengerStopPoint:" ) ) {
if( contains( token, '#' ) ) {
token.erase( token.find( '#' ) ); // obcięcie unikatowości
}
win1250_to_ascii( token ); // get rid of non-ascii chars
m_input.command_type = TCommandType::cm_PassengerStopPoint;
// nie do kolejki (dla SetVelocity też, ale jak jest do toru dowiązany)
@@ -1224,12 +1226,12 @@ multi_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
}
else {
// potentially valid event name
if( token.substr( 0, 5 ) != "none_" ) {
if( starts_with( token, "none_" ) ) {
// eventy rozpoczynające się od "none_" są ignorowane
m_children.emplace_back( token, nullptr, ( m_conditions.has_else == false ) );
WriteLog( "Multi-event \"" + m_name + "\" ignored link to event \"" + token + "\"" );
}
else {
WriteLog( "Multi-event \"" + m_name + "\" ignored link to event \"" + token + "\"" );
m_children.emplace_back( token, nullptr, ( m_conditions.has_else == false ) );
}
}
}
@@ -1564,7 +1566,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
Input.getTokens();
Input >> token;
if( token.compare( "rotate" ) == 0 ) { // obrót względem osi
if( token == "rotate" ) { // obrót względem osi
Input.getTokens();
// animation submodel, previously held in param 9
Input >> m_animationsubmodel;
@@ -1578,7 +1580,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ]
>> m_animationparams[ 3 ];
}
else if( token.compare( "translate" ) == 0 ) { // przesuw o wektor
else if( token == "translate" ) { // przesuw o wektor
Input.getTokens();
// animation submodel, previously held in param 9
Input >> m_animationsubmodel;
@@ -1592,7 +1594,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ]
>> m_animationparams[ 3 ];
}
else if( token.compare( "digital" ) == 0 ) { // licznik cyfrowy
else if( token == "digital" ) { // licznik cyfrowy
Input.getTokens();
// animation submodel, previously held in param 9
Input >> m_animationsubmodel;
@@ -1606,7 +1608,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ]
>> m_animationparams[ 3 ];
}
else if( token.substr( token.length() - 4, 4 ) == ".vmd" ) // na razie tu, może będzie inaczej
else if( ends_with( token, ".vmd" ) ) // na razie tu, może będzie inaczej
{ // animacja z pliku VMD
{
m_animationfilename = token;
@@ -2227,18 +2229,15 @@ event_manager::insert( basic_event *Event ) {
return false;
}
// tymczasowo wyjątki:
else if( ( size > 8 )
&& ( Event->m_name.substr( 0, 9 ) == "lineinfo:" ) ) {
else if( ends_with( Event->m_name, "lineinfo:" ) ) {
// tymczasowa utylizacja duplikatów W5
return false;
}
else if( ( size > 8 )
&& ( Event->m_name.substr( size - 8 ) == "_warning" ) ) {
else if( ends_with( Event->m_name, "_warning" ) ) {
// tymczasowa utylizacja duplikatu z trąbieniem
return false;
}
else if( ( size > 4 )
&& ( Event->m_name.substr( size - 4 ) == "_shp" ) ) {
else if( ends_with( Event->m_name, "_shp" ) ) {
// nie podlegają logowaniu
// tymczasowa utylizacja duplikatu SHP
return false;
@@ -2263,7 +2262,7 @@ event_manager::insert( basic_event *Event ) {
// if it's first event with such name, it's potential candidate for the execution queue
m_eventmap.emplace( Event->m_name, m_events.size() - 1 );
if( ( Event->m_ignored != true )
&& ( Event->m_name.find( "onstart" ) != std::string::npos ) ) {
&& ( contains( Event->m_name, "onstart" ) ) ) {
// event uruchamiany automatycznie po starcie
AddToQuery( Event, nullptr );
}

View File

@@ -1259,7 +1259,7 @@ global_settings::export_as_text( std::ostream &Output, std::string const Key, st
if( Value.empty() ) { return; }
if( Value.find( ' ' ) != std::string::npos ) {
if( contains( Value, ' ' ) ) {
Output << Key << " \"" << Value << "\"\n";
}
else {

View File

@@ -9179,7 +9179,7 @@ void TMoverParameters::BrakeValveDecode( std::string const &Valve ) {
TBrakeValve::Other;
if( ( BrakeValve == TBrakeValve::Other )
&& ( Valve.find( "ESt" ) != std::string::npos ) ) {
&& ( contains( Valve, "ESt" ) ) ) {
BrakeValve = TBrakeValve::ESt3;
}
@@ -9276,8 +9276,8 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
inputline = fizparser.getToken<std::string>( false, "\n\r" );
bool comment = ( ( inputline.find('#') != std::string::npos )
|| ( inputline.compare( 0, 2, "//" ) == 0 ) );
bool comment = ( ( contains( inputline, '#') )
|| ( starts_with( inputline, "//" ) ) );
if( true == comment ) {
// skip commented lines
continue;
@@ -10530,10 +10530,10 @@ void TMoverParameters::LoadFIZ_Light( std::string const &line ) {
void TMoverParameters::LoadFIZ_Security( std::string const &line ) {
std::string awaresystem = extract_value( "AwareSystem", line );
if( awaresystem.find( "Active" ) != std::string::npos ) {
if( contains( awaresystem, "Active" ) ) {
SetFlag( SecuritySystem.SystemType, 1 );
}
if( awaresystem.find( "CabSignal" ) != std::string::npos ) {
if( contains( awaresystem, "CabSignal" ) ) {
SetFlag( SecuritySystem.SystemType, 2 );
}
@@ -11168,7 +11168,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir)
// WriteLog("aa = " + AxleArangement + " " + std::string( Pos("o", AxleArangement)) );
if( ( AxleArangement.find( "o" ) != std::string::npos ) && ( EngineType == TEngineType::ElectricSeriesMotor ) ) {
if( ( contains( AxleArangement, "o" ) ) && ( EngineType == TEngineType::ElectricSeriesMotor ) ) {
// test poprawnosci ilosci osi indywidualnie napedzanych
OK = ( ( RList[ 1 ].Bn * RList[ 1 ].Mn ) == NPoweredAxles );
// WriteLogSS("aa ok", BoolToYN(OK));

View File

@@ -460,7 +460,7 @@ void TNESt3::SetSize( int const size, std::string const &params ) // ustawianie
static double const dOO1l = 0.907;
static double const dOT1l = 0.524;
if (params.find("ESt3") != std::string::npos)
if (contains( params, "ESt3" ) )
{
Podskok = 0.7;
Przekladniki[1] = std::make_shared<TRura>();
@@ -470,32 +470,32 @@ void TNESt3::SetSize( int const size, std::string const &params ) // ustawianie
{
Podskok = -1.0;
Przekladniki[1] = std::make_shared<TRapid>();
if (params.find("-s216") != std::string::npos)
if (contains( params, "-s216" ) )
Przekladniki[1]->SetRapidParams(2, 16);
else
Przekladniki[1]->SetRapidParams(2, 0);
Przekladniki[3] = std::make_shared<TPrzeciwposlizg>();
if (params.find("-ED") != std::string::npos)
if (contains( params,"-ED") )
{
Przekladniki[1]->SetRapidParams(2, 18);
Przekladniki[3] = std::make_shared<TPrzekED>();
}
}
if (params.find("AL2") != std::string::npos)
if (contains(params,"AL2") )
Przekladniki[2] = std::make_shared<TPrzekCiagly>();
else if (params.find("PZZ") != std::string::npos)
else if (contains(params,"PZZ") )
Przekladniki[2] = std::make_shared<TPrzek_PZZ>();
else
Przekladniki[2] = std::make_shared<TRura>();
if( ( params.find( "3d" ) != std::string::npos )
|| ( params.find( "4d" ) != std::string::npos ) ) {
if( ( contains( params, "3d" ) )
|| ( contains( params, "4d" ) ) ) {
autom = false;
}
else
autom = true;
if ((params.find("HBG300") != std::string::npos))
if ((contains( params,"HBG300")))
HBG300 = 1.0;
else
HBG300 = 0.0;

View File

@@ -82,7 +82,7 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
std::string const buftp { Global.asCurrentTexturePath }; // zapamiętanie aktualnej ścieżki do tekstur,
std::string filename { Name };
if( ( false == Dynamic )
&& ( Name.find( '/' ) != std::string::npos ) ) {
&& ( contains( Name, '/' ) ) ) {
// pobieranie tekstur z katalogu, w którym jest model
// when loading vehicles the path is set by the calling routine, so we can skip it here
Global.asCurrentTexturePath += Name;

View File

@@ -2016,14 +2016,13 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector<std::string> *t,
if (!pName.empty())
{ // jeśli dany submodel jest zgaszonym światłem, to
// domyślnie go ukrywamy
if ((pName.size() >= 8) && (pName.substr(0, 8) == "Light_On"))
if (starts_with( pName, "Light_On" ))
{ // jeśli jest światłem numerowanym
iVisible = 0; // to domyślnie wyłączyć, żeby się nie nakładało z
iVisible = 0; // to domyślnie wyłączyć, żeby się nie nakładało z obiektem "Light_Off"
}
// obiektem "Light_Off"
else if (dynamic)
{ // inaczej wyłączało smugę w latarniach
if ((pName.size() >= 3) && (pName.substr(pName.size() - 3, 3) == "_on")) {
if (ends_with( pName, "_on")) {
// jeśli jest kontrolką w stanie zapalonym to domyślnie wyłączyć,
// żeby się nie nakładało z obiektem "_off"
iVisible = 0;

View File

@@ -1141,8 +1141,9 @@ texture_manager::unit( GLint const Textureunit ) {
texture_handle
texture_manager::create( std::string Filename, bool const Loadnow, GLint Formathint ) {
if( Filename.find( '|' ) != std::string::npos )
if( contains( Filename, '|' ) ) {
Filename.erase( Filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
}
std::pair<std::string, std::string> locator; // resource name, resource type
std::string traits;
@@ -1181,8 +1182,8 @@ texture_manager::create( std::string Filename, bool const Loadnow, GLint Formath
replace_slashes( Filename );
erase_leading_slashes( Filename );
// temporary code for legacy assets -- textures with names beginning with # are to be sharpened
if( ( Filename.front() == '#' )
|| ( Filename.find( "/#" ) != std::string::npos ) ) {
if( ( starts_with( Filename, "#" ) )
|| ( contains( Filename, "/#" ) ) ) {
traits += '#';
}
}

View File

@@ -31,7 +31,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) :
::alGenBuffers( 1, &id );
// fetch audio data
if( Filename.substr( Filename.rfind( '.' ) ) == ".wav" ) {
if( ends_with( Filename, ".wav" ) ) {
// .wav audio data file
auto *file { drwav_open_file( Filename.c_str() ) };
if( file != nullptr ) {
@@ -53,7 +53,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) :
// we're done with the disk data
drwav_close( file );
}
else if( Filename.substr( Filename.rfind( '.' ) ) == ".flac" ) {
else if( ends_with( Filename, ".flac" ) ) {
// .flac audio data file
auto *file { drflac_open_file( Filename.c_str() ) };
if( file != nullptr ) {
@@ -75,7 +75,7 @@ openal_buffer::openal_buffer( std::string const &Filename ) :
// we're done with the disk data
drflac_close( file );
}
else if( Filename.substr( Filename.rfind( '.' ) ) == ".ogg" ) {
else if( ends_with( Filename, ".ogg" ) ) {
// vorbis .ogg audio data file
// TBD, TODO: customized vorbis_decode to avoid unnecessary shuffling around of the decoded data
int channels, samplerate;
@@ -173,7 +173,7 @@ buffer_manager::create( std::string const &Filename ) {
return emplace( filelookup );
}
}
if( filename.find( '/' ) != std::string::npos ) {
if( contains( filename, '/' ) ) {
// if the filename includes path, try to use it directly
lookup = find_buffer( filename );
if( lookup != null_handle ) {

View File

@@ -1257,7 +1257,7 @@ debug_panel::update_section_eventqueue( std::vector<text_line> &Output ) {
auto const label { event->m_name + ( event->m_activator ? " (by: " + event->m_activator->asName + ")" : "" ) };
if( ( false == searchfilter.empty() )
&& ( label.find( searchfilter ) == std::string::npos ) ) {
&& ( false == contains( label, searchfilter ) ) ) {
event = event->m_next;
continue;
}

View File

@@ -394,7 +394,7 @@ nodebank_panel::render() {
continue;
}
if( ( false == searchfilter.empty() )
&& ( entry.first.find( searchfilter ) == std::string::npos ) ) {
&& ( false == contains( entry.first, searchfilter ) ) ) {
continue;
}
auto const label { " " + entry.first + "##" + std::to_string( idx ) };

View File

@@ -456,8 +456,9 @@ material_manager::create( std::string const &Filename, bool const Loadnow ) {
auto filename { Filename };
if( filename.find( '|' ) != std::string::npos )
if( contains( filename, '|' ) ) {
filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
}
// discern references to textures generated by a script
// TBD: support file: for file resources?

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;
}

View File

@@ -246,8 +246,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
if( token == "include" ) {
std::string includefile = readToken(ToLower); // nazwa pliku
if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
|| ( ( false == contains( includefile, "tr/" ) )
&& ( false == contains( includefile, "tra/" ) ) ) ) {
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) {
@@ -266,8 +266,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
cParser includeparser( token.substr( 7 ) );
std::string includefile = includeparser.readToken( ToLower ); // nazwa pliku
if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
|| ( ( false == contains( includefile, "tr/" ) )
&& ( false == contains( includefile, "tra/" ) ) ) ) {
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) {

View File

@@ -1190,7 +1190,7 @@ basic_region::insert( shape_node Shape, scratch_data &Scratchpad, bool const Tra
auto const materialname{ GfxRenderer->Material( Shape.data().material ).name };
for( auto const &switchtrackbedtexture : switchtrackbedtextures ) {
if( materialname.find( switchtrackbedtexture ) != std::string::npos ) {
if( contains( materialname, switchtrackbedtexture ) ) {
// geometry with blacklisted texture, part of old switch trackbed; ignore it
return;
}

View File

@@ -208,17 +208,17 @@ shape_node::import( cParser &Input, scene::node_data const &Nodedata ) {
opengl_texture() ); // dirty workaround for lack of better api
bool const clamps = (
texturehandle ?
texture.traits.find( 's' ) != std::string::npos :
contains( texture.traits, 's' ) :
false );
bool const clampt = (
texturehandle ?
texture.traits.find( 't' ) != std::string::npos :
contains( texture.traits, 't' ) :
false );
// remainder of legacy 'problend' system -- geometry assigned a texture with '@' in its name is treated as translucent, opaque otherwise
if( texturehandle != null_handle ) {
m_data.translucent = (
( ( texture.name.find( '@' ) != std::string::npos )
( ( contains( texture.name, '@' ) )
&& ( true == texture.has_alpha ) ) ?
true :
false );

View File

@@ -497,8 +497,8 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch
// crude way to detect fixed switch trackbed geometry
|| ( ( true == Global.CreateSwitchTrackbeds )
&& ( Input.Name().size() >= 15 )
&& ( Input.Name().substr( 0, 11 ) == "scenery/zwr" )
&& ( Input.Name().substr( Input.Name().size() - 4 ) == ".inc" ) ) };
&& ( starts_with( Input.Name(), "scenery/zwr" ) )
&& ( ends_with( Input.Name(), ".inc" ) ) ) };
if( false == skip ) {

View File

@@ -30,9 +30,9 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
auto const stationname { Schedule.TimeTable[ Schedule.StationIndex ].StationName };
auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare };
auto const trainstop { (
( ( stationname.size() >= 2 ) && ( stationname.substr( stationname.size() - 2 ) == "po" ) )
|| ( stationequipment.find( "po" ) != std::string::npos ) ) };
auto const maintenancestop { ( stationequipment.find( "pt" ) != std::string::npos ) };
( ends_with( stationname, "po" ) )
|| ( contains( stationequipment, "po" ) ) ) };
auto const maintenancestop { ( contains( stationequipment, "pt" ) ) };
// train stops exchange smaller groups than regular stations
// NOTE: this is crude and unaccurate, but for now will do
auto const stationsizemodifier { ( trainstop ? 1.0 : 2.0 ) };

View File

@@ -475,6 +475,19 @@ starts_with( std::string_view const String, std::string_view Prefix ) {
&& ( 0 == String.compare( 0, Prefix.size(), Prefix ) );
}
// returns true if provided string contains another provided string
bool
contains( std::string_view const String, std::string_view Substring ) {
return ( String.find( Substring ) != std::string::npos );
}
bool
contains( std::string_view const String, char Character ) {
return ( String.find( Character ) != std::string::npos );
}
// helper, restores content of a 3d vector from provided input stream
// TODO: review and clean up the helper routines, there's likely some redundant ones
glm::dvec3 LoadPoint( cParser &Input ) {

View File

@@ -216,6 +216,9 @@ std::ptrdiff_t len_common_prefix( std::string const &Left, std::string const &Ri
bool ends_with( std::string_view String, std::string_view Suffix );
// returns true if provided string begins with another provided string
bool starts_with( std::string_view String, std::string_view Prefix );
// returns true if provided string contains another provided string
bool contains( std::string_view const String, std::string_view Substring );
bool contains( std::string_view const String, char Character );
template <typename Type_>
void SafeDelete( Type_ &Pointer ) {