16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 17:29:18 +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 { // gdy brak modelu
if (ter) // jeśli teren if (ter) // jeśli teren
{ {
if( name.substr( name.rfind( '.' ) ) == ".t3d" ) { if( ends_with( name, ".t3d" ) ) {
name[ name.length() - 3 ] = 'e'; name[ name.length() - 3 ] = 'e';
} }
#ifdef EU07_USE_OLD_TERRAINCODE #ifdef EU07_USE_OLD_TERRAINCODE
@@ -959,11 +959,11 @@ TAnimModel::export_as_text_( std::ostream &Output ) const {
// don't include 'textures/' in the path // don't include 'textures/' in the path
texturefile.erase( 0, std::string{ szTexturePath }.size() ); texturefile.erase( 0, std::string{ szTexturePath }.size() );
} }
if( texturefile.find( ' ' ) == std::string::npos ) { if( contains( texturefile, ' ' ) ) {
Output << texturefile << ' '; Output << "\"" << texturefile << "\"" << ' ';
} }
else { else {
Output << "\"" << texturefile << "\"" << ' '; Output << texturefile << ' ';
} }
// light submodels activation configuration // light submodels activation configuration
if( iNumLights > 0 ) { if( iNumLights > 0 ) {

View File

@@ -145,7 +145,7 @@ bool TPoKeys55::Connect()
DeviceIDFromRegistry = ToLower( DeviceIDFromRegistry ); DeviceIDFromRegistry = ToLower( DeviceIDFromRegistry );
DeviceIDToFind = ToLower( DeviceIDToFind ); DeviceIDToFind = ToLower( DeviceIDToFind );
// Now check if the hardware ID we are looking at contains the correct VID/PID // 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) if (MatchFound == true)
{ {
// Device must have been found. Open read and write handles. In order to do this,we // 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) + ", " + std::to_string(t->Dh) + ":" + std::to_string(t->Dm)
+ " " + t->StationWare); + " " + t->StationWare);
} }
if (t->StationWare.find('@') != std::string::npos) if ( contains( t->StationWare, '@' ) )
{ // zmiana kierunku i dalsza jazda wg rozk?adu { // zmiana kierunku i dalsza jazda wg rozk?adu
if (iDrivigFlags & movePushPull) // SZT również! SN61 zależnie od wagonów... if (iDrivigFlags & movePushPull) // SZT również! SN61 zależnie od wagonów...
{ // jeśli skład zespolony, wystarczy zmienić kierunek jazdy { // jeśli skład zespolony, wystarczy zmienić kierunek jazdy

View File

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

View File

@@ -297,8 +297,9 @@ basic_event::deserialize( cParser &Input, scene::scratch_data &Scratchpad ) {
Input >> token; Input >> token;
deserialize_targets( token ); deserialize_targets( token );
if (m_name.substr(0, 5) == "none_") if( starts_with( m_name, "none_" ) ) {
m_ignored = true; // Ra: takie są ignorowane m_ignored = true; // Ra: takie są ignorowane
}
deserialize_( Input, Scratchpad ); deserialize_( Input, Scratchpad );
// subclass method is expected to leave next token past its own data preloaded on its exit // 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.getTokens( 1, false ); // komendy 'case sensitive'
Input >> token; Input >> token;
// command type, previously held in param 6 // command type, previously held in param 6
if( token.substr( 0, 19 ) == "PassengerStopPoint:" ) { if( starts_with( token, "PassengerStopPoint:" ) ) {
if( token.find( '#' ) != std::string::npos ) if( contains( token, '#' ) ) {
token.erase( token.find( '#' ) ); // obcięcie unikatowości token.erase( token.find( '#' ) ); // obcięcie unikatowości
}
win1250_to_ascii( token ); // get rid of non-ascii chars win1250_to_ascii( token ); // get rid of non-ascii chars
m_input.command_type = TCommandType::cm_PassengerStopPoint; m_input.command_type = TCommandType::cm_PassengerStopPoint;
// nie do kolejki (dla SetVelocity też, ale jak jest do toru dowiązany) // 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 { else {
// potentially valid event name // potentially valid event name
if( token.substr( 0, 5 ) != "none_" ) { if( starts_with( token, "none_" ) ) {
// eventy rozpoczynające się od "none_" są ignorowane // 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 { 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.getTokens();
Input >> token; Input >> token;
if( token.compare( "rotate" ) == 0 ) { // obrót względem osi if( token == "rotate" ) { // obrót względem osi
Input.getTokens(); Input.getTokens();
// animation submodel, previously held in param 9 // animation submodel, previously held in param 9
Input >> m_animationsubmodel; Input >> m_animationsubmodel;
@@ -1578,7 +1580,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ] >> m_animationparams[ 2 ]
>> m_animationparams[ 3 ]; >> m_animationparams[ 3 ];
} }
else if( token.compare( "translate" ) == 0 ) { // przesuw o wektor else if( token == "translate" ) { // przesuw o wektor
Input.getTokens(); Input.getTokens();
// animation submodel, previously held in param 9 // animation submodel, previously held in param 9
Input >> m_animationsubmodel; Input >> m_animationsubmodel;
@@ -1592,7 +1594,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ] >> m_animationparams[ 2 ]
>> m_animationparams[ 3 ]; >> m_animationparams[ 3 ];
} }
else if( token.compare( "digital" ) == 0 ) { // licznik cyfrowy else if( token == "digital" ) { // licznik cyfrowy
Input.getTokens(); Input.getTokens();
// animation submodel, previously held in param 9 // animation submodel, previously held in param 9
Input >> m_animationsubmodel; Input >> m_animationsubmodel;
@@ -1606,7 +1608,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ] >> m_animationparams[ 2 ]
>> m_animationparams[ 3 ]; >> 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 { // animacja z pliku VMD
{ {
m_animationfilename = token; m_animationfilename = token;
@@ -2227,18 +2229,15 @@ event_manager::insert( basic_event *Event ) {
return false; return false;
} }
// tymczasowo wyjątki: // tymczasowo wyjątki:
else if( ( size > 8 ) else if( ends_with( Event->m_name, "lineinfo:" ) ) {
&& ( Event->m_name.substr( 0, 9 ) == "lineinfo:" ) ) {
// tymczasowa utylizacja duplikatów W5 // tymczasowa utylizacja duplikatów W5
return false; return false;
} }
else if( ( size > 8 ) else if( ends_with( Event->m_name, "_warning" ) ) {
&& ( Event->m_name.substr( size - 8 ) == "_warning" ) ) {
// tymczasowa utylizacja duplikatu z trąbieniem // tymczasowa utylizacja duplikatu z trąbieniem
return false; return false;
} }
else if( ( size > 4 ) else if( ends_with( Event->m_name, "_shp" ) ) {
&& ( Event->m_name.substr( size - 4 ) == "_shp" ) ) {
// nie podlegają logowaniu // nie podlegają logowaniu
// tymczasowa utylizacja duplikatu SHP // tymczasowa utylizacja duplikatu SHP
return false; 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 // 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 ); m_eventmap.emplace( Event->m_name, m_events.size() - 1 );
if( ( Event->m_ignored != true ) if( ( Event->m_ignored != true )
&& ( Event->m_name.find( "onstart" ) != std::string::npos ) ) { && ( contains( Event->m_name, "onstart" ) ) ) {
// event uruchamiany automatycznie po starcie // event uruchamiany automatycznie po starcie
AddToQuery( Event, nullptr ); 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.empty() ) { return; }
if( Value.find( ' ' ) != std::string::npos ) { if( contains( Value, ' ' ) ) {
Output << Key << " \"" << Value << "\"\n"; Output << Key << " \"" << Value << "\"\n";
} }
else { else {

View File

@@ -9179,7 +9179,7 @@ void TMoverParameters::BrakeValveDecode( std::string const &Valve ) {
TBrakeValve::Other; TBrakeValve::Other;
if( ( BrakeValve == TBrakeValve::Other ) if( ( BrakeValve == TBrakeValve::Other )
&& ( Valve.find( "ESt" ) != std::string::npos ) ) { && ( contains( Valve, "ESt" ) ) ) {
BrakeValve = TBrakeValve::ESt3; BrakeValve = TBrakeValve::ESt3;
} }
@@ -9276,8 +9276,8 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
inputline = fizparser.getToken<std::string>( false, "\n\r" ); inputline = fizparser.getToken<std::string>( false, "\n\r" );
bool comment = ( ( inputline.find('#') != std::string::npos ) bool comment = ( ( contains( inputline, '#') )
|| ( inputline.compare( 0, 2, "//" ) == 0 ) ); || ( starts_with( inputline, "//" ) ) );
if( true == comment ) { if( true == comment ) {
// skip commented lines // skip commented lines
continue; continue;
@@ -10530,10 +10530,10 @@ void TMoverParameters::LoadFIZ_Light( std::string const &line ) {
void TMoverParameters::LoadFIZ_Security( std::string const &line ) { void TMoverParameters::LoadFIZ_Security( std::string const &line ) {
std::string awaresystem = extract_value( "AwareSystem", line ); std::string awaresystem = extract_value( "AwareSystem", line );
if( awaresystem.find( "Active" ) != std::string::npos ) { if( contains( awaresystem, "Active" ) ) {
SetFlag( SecuritySystem.SystemType, 1 ); SetFlag( SecuritySystem.SystemType, 1 );
} }
if( awaresystem.find( "CabSignal" ) != std::string::npos ) { if( contains( awaresystem, "CabSignal" ) ) {
SetFlag( SecuritySystem.SystemType, 2 ); SetFlag( SecuritySystem.SystemType, 2 );
} }
@@ -11168,7 +11168,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir)
// WriteLog("aa = " + AxleArangement + " " + std::string( Pos("o", AxleArangement)) ); // 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 // test poprawnosci ilosci osi indywidualnie napedzanych
OK = ( ( RList[ 1 ].Bn * RList[ 1 ].Mn ) == NPoweredAxles ); OK = ( ( RList[ 1 ].Bn * RList[ 1 ].Mn ) == NPoweredAxles );
// WriteLogSS("aa ok", BoolToYN(OK)); // 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 dOO1l = 0.907;
static double const dOT1l = 0.524; static double const dOT1l = 0.524;
if (params.find("ESt3") != std::string::npos) if (contains( params, "ESt3" ) )
{ {
Podskok = 0.7; Podskok = 0.7;
Przekladniki[1] = std::make_shared<TRura>(); Przekladniki[1] = std::make_shared<TRura>();
@@ -470,32 +470,32 @@ void TNESt3::SetSize( int const size, std::string const &params ) // ustawianie
{ {
Podskok = -1.0; Podskok = -1.0;
Przekladniki[1] = std::make_shared<TRapid>(); Przekladniki[1] = std::make_shared<TRapid>();
if (params.find("-s216") != std::string::npos) if (contains( params, "-s216" ) )
Przekladniki[1]->SetRapidParams(2, 16); Przekladniki[1]->SetRapidParams(2, 16);
else else
Przekladniki[1]->SetRapidParams(2, 0); Przekladniki[1]->SetRapidParams(2, 0);
Przekladniki[3] = std::make_shared<TPrzeciwposlizg>(); Przekladniki[3] = std::make_shared<TPrzeciwposlizg>();
if (params.find("-ED") != std::string::npos) if (contains( params,"-ED") )
{ {
Przekladniki[1]->SetRapidParams(2, 18); Przekladniki[1]->SetRapidParams(2, 18);
Przekladniki[3] = std::make_shared<TPrzekED>(); Przekladniki[3] = std::make_shared<TPrzekED>();
} }
} }
if (params.find("AL2") != std::string::npos) if (contains(params,"AL2") )
Przekladniki[2] = std::make_shared<TPrzekCiagly>(); 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>(); Przekladniki[2] = std::make_shared<TPrzek_PZZ>();
else else
Przekladniki[2] = std::make_shared<TRura>(); Przekladniki[2] = std::make_shared<TRura>();
if( ( params.find( "3d" ) != std::string::npos ) if( ( contains( params, "3d" ) )
|| ( params.find( "4d" ) != std::string::npos ) ) { || ( contains( params, "4d" ) ) ) {
autom = false; autom = false;
} }
else else
autom = true; autom = true;
if ((params.find("HBG300") != std::string::npos)) if ((contains( params,"HBG300")))
HBG300 = 1.0; HBG300 = 1.0;
else else
HBG300 = 0.0; 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 const buftp { Global.asCurrentTexturePath }; // zapamiętanie aktualnej ścieżki do tekstur,
std::string filename { Name }; std::string filename { Name };
if( ( false == Dynamic ) if( ( false == Dynamic )
&& ( Name.find( '/' ) != std::string::npos ) ) { && ( contains( Name, '/' ) ) ) {
// pobieranie tekstur z katalogu, w którym jest model // 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 // when loading vehicles the path is set by the calling routine, so we can skip it here
Global.asCurrentTexturePath += Name; Global.asCurrentTexturePath += Name;

View File

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

View File

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

View File

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

View File

@@ -394,7 +394,7 @@ nodebank_panel::render() {
continue; continue;
} }
if( ( false == searchfilter.empty() ) if( ( false == searchfilter.empty() )
&& ( entry.first.find( searchfilter ) == std::string::npos ) ) { && ( false == contains( entry.first, searchfilter ) ) ) {
continue; continue;
} }
auto const label { " " + entry.first + "##" + std::to_string( idx ) }; 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 }; auto filename { Filename };
if( filename.find( '|' ) != std::string::npos ) if( contains( filename, '|' ) ) {
filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury filename.erase( filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
}
// discern references to textures generated by a script // discern references to textures generated by a script
// TBD: support file: for file resources? // 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)) while (fin.good() && !((ConversionError != 0) || EndTable))
{ {
std::getline(fin, lines); /*wczytanie linii*/ 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; fin >> s;
if (s == "[") /*lewy pion*/ 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) TrainName = s; // nadanie nazwy z pliku TXT (bez ścieżki do pliku)
while (fin >> s || fin.bad()) while (fin >> s || fin.bad())
{ {
if (s.find("_______|") != std::string::npos) if (contains( s,"_______|") )
{ {
break; break;
} }
@@ -393,7 +393,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
do do
{ {
fin >> s; fin >> s;
} while (!(s.find("[______________") != std::string::npos || fin.bad())); } while (!(contains( s,"[______________" ) || fin.bad()));
auto activeradiochannel{ -1 }; auto activeradiochannel{ -1 };
while (!fin.bad() && !EndTable) while (!fin.bad() && !EndTable)
{ {
@@ -408,21 +408,20 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s; fin >> s;
else else
ConversionError = -4; ConversionError = -4;
if (s.find("|") == std::string::npos) if (false == contains( s,"|") )
{ {
record->km = atof(s.c_str()); record->km = atof(s.c_str());
fin >> s; fin >> s;
} }
if (s.find("|_____|") != if (contains( s,"|_____|")) /*zmiana predkosci szlakowej*/
std::string::npos) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual); UpdateVelocity(StationCount, vActual);
else else
{ {
fin >> s; fin >> s;
if (s.find("|") == std::string::npos) if (false == contains(s,"|"))
vActual = atof(s.c_str()); vActual = atof(s.c_str());
} }
while (s.find("|") == std::string::npos) while (false == contains( s,"|"))
fin >> s; fin >> s;
fin >> record->StationName; fin >> record->StationName;
// get rid of non-ascii chars. TODO: run correct version based on locale // 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; fin >> s;
if (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->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 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; fin >> s;
} while (!((s == "[") || fin.bad())); } while (!((s == "[") || fin.bad()));
fin >> s; fin >> s;
if (s.find("|") == std::string::npos) if (false == contains(s,"|"))
{ {
/*tu s moze byc miejscem zmiany predkosci szlakowej*/ /*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s; fin >> s;
@@ -468,10 +467,10 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
else else
{ {
fin >> s; fin >> s;
if (s.find("|") == std::string::npos) if (false == contains(s,"|"))
vActual = atof(s.c_str()); vActual = atof(s.c_str());
} }
while (s.find("|") == std::string::npos) while (false == contains(s,"|"))
fin >> s; fin >> s;
// stationware. added fix for empty entry // stationware. added fix for empty entry
fin >> s; fin >> s;
@@ -482,7 +481,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s; fin >> s;
} }
// cache relevant station data // 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, ',' ) }; auto const stationware { Split( record->StationWare, ',' ) };
for( auto const &entry : stationware ) { for( auto const &entry : stationware ) {
@@ -510,7 +509,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s; fin >> s;
if (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->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 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 do
{ {
fin >> s; fin >> s;
} while (!((s.find("[") != std::string::npos) || fin.bad())); } while (!(contains( s, "[" ) || fin.bad()));
if (s.find("_|_") == std::string::npos) if (false == contains( s, "_|_"))
fin >> s; fin >> s;
if (s.find("|") == std::string::npos) if (false == contains( s, "|"))
{ {
/*tu s moze byc miejscem zmiany predkosci szlakowej*/ /*tu s moze byc miejscem zmiany predkosci szlakowej*/
fin >> s; fin >> s;
} }
if (s.find("|_____|") != if (contains( s, "|_____|") ) /*zmiana predkosci szlakowej*/
std::string::npos) /*zmiana predkosci szlakowej*/
UpdateVelocity(StationCount, vActual); UpdateVelocity(StationCount, vActual);
else else
{ {
fin >> s; fin >> s;
if (s.find("|") == std::string::npos) if (false == contains( s, "|"))
vActual = atof(s.c_str()); vActual = atof(s.c_str());
} }
while (s.find("|") == std::string::npos) while (false == contains( s, "|" ) )
fin >> s; fin >> s;
while ((s.find("]") == std::string::npos)) while ((false == contains( s,"]") ))
fin >> s; fin >> s;
if (s.find("_|_") != std::string::npos) if (contains( s,"_|_") )
EndTable = true; EndTable = true;
} /*timetableline*/ } /*timetableline*/
} }
@@ -633,7 +631,7 @@ bool TTrainParameters::DirectionChange()
// sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy // sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy
{ {
if ((StationIndex > 0) && (StationIndex < StationCount)) // dla ostatniej stacji nie 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 true;
return false; return false;
} }

View File

@@ -246,8 +246,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
if( token == "include" ) { if( token == "include" ) {
std::string includefile = readToken(ToLower); // nazwa pliku std::string includefile = readToken(ToLower); // nazwa pliku
if( ( true == LoadTraction ) if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos ) || ( ( false == contains( includefile, "tr/" ) )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) { && ( false == contains( includefile, "tra/" ) ) ) ) {
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) ); mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
mIncludeParser->autoclear( m_autoclear ); mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) { if( mIncludeParser->mSize <= 0 ) {
@@ -266,8 +266,8 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
cParser includeparser( token.substr( 7 ) ); cParser includeparser( token.substr( 7 ) );
std::string includefile = includeparser.readToken( ToLower ); // nazwa pliku std::string includefile = includeparser.readToken( ToLower ); // nazwa pliku
if( ( true == LoadTraction ) if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos ) || ( ( false == contains( includefile, "tr/" ) )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) { && ( false == contains( includefile, "tra/" ) ) ) ) {
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) ); mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
mIncludeParser->autoclear( m_autoclear ); mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) { 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 }; auto const materialname{ GfxRenderer->Material( Shape.data().material ).name };
for( auto const &switchtrackbedtexture : switchtrackbedtextures ) { 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 // geometry with blacklisted texture, part of old switch trackbed; ignore it
return; 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 opengl_texture() ); // dirty workaround for lack of better api
bool const clamps = ( bool const clamps = (
texturehandle ? texturehandle ?
texture.traits.find( 's' ) != std::string::npos : contains( texture.traits, 's' ) :
false ); false );
bool const clampt = ( bool const clampt = (
texturehandle ? texturehandle ?
texture.traits.find( 't' ) != std::string::npos : contains( texture.traits, 't' ) :
false ); false );
// remainder of legacy 'problend' system -- geometry assigned a texture with '@' in its name is treated as translucent, opaque otherwise // remainder of legacy 'problend' system -- geometry assigned a texture with '@' in its name is treated as translucent, opaque otherwise
if( texturehandle != null_handle ) { if( texturehandle != null_handle ) {
m_data.translucent = ( m_data.translucent = (
( ( texture.name.find( '@' ) != std::string::npos ) ( ( contains( texture.name, '@' ) )
&& ( true == texture.has_alpha ) ) ? && ( true == texture.has_alpha ) ) ?
true : true :
false ); 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 // crude way to detect fixed switch trackbed geometry
|| ( ( true == Global.CreateSwitchTrackbeds ) || ( ( true == Global.CreateSwitchTrackbeds )
&& ( Input.Name().size() >= 15 ) && ( Input.Name().size() >= 15 )
&& ( Input.Name().substr( 0, 11 ) == "scenery/zwr" ) && ( starts_with( Input.Name(), "scenery/zwr" ) )
&& ( Input.Name().substr( Input.Name().size() - 4 ) == ".inc" ) ) }; && ( ends_with( Input.Name(), ".inc" ) ) ) };
if( false == skip ) { 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 stationname { Schedule.TimeTable[ Schedule.StationIndex ].StationName };
auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare }; auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare };
auto const trainstop { ( auto const trainstop { (
( ( stationname.size() >= 2 ) && ( stationname.substr( stationname.size() - 2 ) == "po" ) ) ( ends_with( stationname, "po" ) )
|| ( stationequipment.find( "po" ) != std::string::npos ) ) }; || ( contains( stationequipment, "po" ) ) ) };
auto const maintenancestop { ( stationequipment.find( "pt" ) != std::string::npos ) }; auto const maintenancestop { ( contains( stationequipment, "pt" ) ) };
// train stops exchange smaller groups than regular stations // train stops exchange smaller groups than regular stations
// NOTE: this is crude and unaccurate, but for now will do // NOTE: this is crude and unaccurate, but for now will do
auto const stationsizemodifier { ( trainstop ? 1.0 : 2.0 ) }; 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 ) ); && ( 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 // 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 // TODO: review and clean up the helper routines, there's likely some redundant ones
glm::dvec3 LoadPoint( cParser &Input ) { 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 ); bool ends_with( std::string_view String, std::string_view Suffix );
// returns true if provided string begins with another provided string // returns true if provided string begins with another provided string
bool starts_with( std::string_view String, std::string_view Prefix ); 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_> template <typename Type_>
void SafeDelete( Type_ &Pointer ) { void SafeDelete( Type_ &Pointer ) {