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

Replace starts_with and ends_with with string class methods

This commit is contained in:
docentYT
2026-05-01 17:31:11 +02:00
parent 9c27b54960
commit ec1dfae953
15 changed files with 29 additions and 50 deletions

View File

@@ -9546,8 +9546,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
inputline = fizparser.getToken<std::string>(false, "\n\r"); inputline = fizparser.getToken<std::string>(false, "\n\r");
bool comment = ((contains(inputline, '#')) || (starts_with(inputline, "//"))); if (inputline.starts_with("//") || contains(inputline, '#'))
if (true == comment)
{ {
// skip commented lines // skip commented lines
continue; continue;

View File

@@ -190,7 +190,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
} }
m_soundproofing = soundproofing; m_soundproofing = soundproofing;
} }
else if( starts_with( key, "sound" ) ) { else if( key.starts_with("sound") ) {
// sound chunks, defined with key soundX where X = activation threshold // sound chunks, defined with key soundX where X = activation threshold
auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };
@@ -221,7 +221,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
Input.getToken<float>( false, "\n\r\t ,;" ), Input.getToken<float>( false, "\n\r\t ,;" ),
0.0f, 1.0f ); 0.0f, 1.0f );
} }
else if( starts_with( key, "pitch" ) ) { else if ( key.starts_with("pitch") ) {
// sound chunk pitch, defined with key pitchX where X = activation threshold // sound chunk pitch, defined with key pitchX where X = activation threshold
auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };

View File

@@ -305,7 +305,7 @@ size_t NvTextureManager::FetchTexture(std::string path, int format_hint,
path = ToLower(path); path = ToLower(path);
// temporary code for legacy assets -- textures with names beginning with # // temporary code for legacy assets -- textures with names beginning with #
// are to be sharpened // are to be sharpened
if ((starts_with(path, "#")) || (contains(path, "/#"))) { if (path.starts_with("#") || contains(path, "/#")) {
traits += '#'; traits += '#';
} }
} }

View File

@@ -288,7 +288,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( ends_with( name, ".t3d" ) ) { if( name.ends_with(".t3d") ) {
name[ name.length() - 3 ] = 'e'; name[ name.length() - 3 ] = 'e';
} }
#ifdef EU07_USE_OLD_TERRAINCODE #ifdef EU07_USE_OLD_TERRAINCODE

View File

@@ -2215,13 +2215,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 (starts_with(pName, "Light_On")) if (pName.starts_with("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 obiektem "Light_Off" iVisible = 0; // to domyślnie wyłączyć, żeby się nie nakładało z obiektem "Light_Off"
} }
else if (dynamic) else if (dynamic)
{ // inaczej wyłączało smugę w latarniach { // inaczej wyłączało smugę w latarniach
if (ends_with(pName, "_on")) if (pName.ends_with("_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"

View File

@@ -1324,8 +1324,7 @@ texture_manager::create( std::string Filename, bool const Loadnow, GLint Formath
erase_leading_slashes( Filename ); erase_leading_slashes( Filename );
Filename = ToLower( Filename ); Filename = ToLower( 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( ( starts_with( Filename, "#" ) ) if( Filename.starts_with("#") || contains( Filename, "/#" ) ) {
|| ( contains( Filename, "/#" ) ) ) {
traits += '#'; traits += '#';
} }
} }

View File

@@ -566,8 +566,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 )
&& ( starts_with( Input.Name(), "scenery/zwr" ) ) && Input.Name().starts_with("scenery/zwr")
&& ( ends_with( Input.Name(), ".inc" ) ) ) }; && Input.Name().ends_with(".inc") ) };
if( false == skip ) { if( false == skip ) {
@@ -749,7 +749,7 @@ state_serializer::deserialize_terrain(cParser &Input, scene::scratch_data &Scrat
std::string line; std::string line;
Input.getTokens(1); Input.getTokens(1);
Input >> line; Input >> line;
if ((true == Global.file_binary_terrain) && (true == ends_with(line, ".sbt"))) if (Global.file_binary_terrain && line.ends_with(".sbt"))
{ {
Scratchpad.binary.terrain = Region->is_scene(line); Scratchpad.binary.terrain = Region->is_scene(line);
Global.file_binary_terrain_state = true; Global.file_binary_terrain_state = true;

View File

@@ -404,30 +404,16 @@ std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b)
return std::distance(a.begin(), it1); return std::distance(a.begin(), it1);
} }
// returns true if provided string ends with another provided string
bool ends_with(std::string_view String, std::string_view Suffix)
{
return (String.size() >= Suffix.size()) && (0 == String.compare(String.size() - Suffix.size(), Suffix.size(), Suffix));
}
// returns true if provided string begins with another provided string
bool starts_with(std::string_view const String, std::string_view Prefix)
{
return (String.size() >= Prefix.size()) && (0 == String.compare(0, Prefix.size(), Prefix));
}
// returns true if provided string contains another provided string // 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, std::string_view Substring)
{ {
// To be replaced with string::contains in C++ 23
return (String.find(Substring) != std::string::npos); return (String.find(Substring) != std::string::npos);
} }
bool contains(std::string_view const String, char Character) bool contains(std::string_view const String, char Character)
{ {
// To be replaced with string::contains in C++ 23
return (String.find(Character) != std::string::npos); return (String.find(Character) != std::string::npos);
} }

View File

@@ -226,10 +226,6 @@ std::string_view substr_path(std::string const &Filename);
// returns common prefix of two provided strings // returns common prefix of two provided strings
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b); std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b);
// returns true if provided string ends with another provided string
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 // 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, std::string_view Substring);
bool contains(std::string_view const String, char Character); bool contains(std::string_view const String, char Character);

View File

@@ -1354,7 +1354,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 ) && ( starts_with( sectionname, "cab" ) ) ); cabsection &= ( ( sectionname.size() >= 4 ) && sectionname.starts_with("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 ) };
@@ -7954,7 +7954,7 @@ material_handle TDynamicObject::DestinationFind( std::string Destination ) {
auto destinationhandle { null_handle }; auto destinationhandle { null_handle };
if( starts_with( Destination, "make:" ) ) { if( Destination.starts_with("make:") ) {
// autogenerated texture // autogenerated texture
destinationhandle = GfxRenderer->Fetch_Material( Destination ); destinationhandle = GfxRenderer->Fetch_Material( Destination );
} }

View File

@@ -273,7 +273,7 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
>> soundproofing[ 5 ]; >> soundproofing[ 5 ];
Scratchpad.soundproofing = soundproofing; Scratchpad.soundproofing = soundproofing;
} }
else if( starts_with( key, "sound" ) ) { else if( key.starts_with("sound") ) {
// sounds assigned to specific gauge values, defined by key soundX: where X = value // sounds assigned to specific gauge values, defined by key soundX: where X = value
auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };

View File

@@ -298,7 +298,7 @@ basic_event::deserialize( cParser &Input, scene::scratch_data &Scratchpad ) {
Input >> token; Input >> token;
deserialize_targets( token ); deserialize_targets( token );
if( starts_with( m_name, "none_" ) ) { if( m_name.starts_with("none_") ) {
m_ignored = true; // Ra: takie są ignorowane m_ignored = true; // Ra: takie są ignorowane
} }
@@ -716,7 +716,7 @@ 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( starts_with( token, "PassengerStopPoint:" ) ) { if( token.starts_with("PassengerStopPoint:") ) {
if( contains( token, '#' ) ) { if( contains( token, '#' ) ) {
token.erase( token.find( '#' ) ); // obcięcie unikatowości token.erase( token.find( '#' ) ); // obcięcie unikatowości
} }
@@ -835,8 +835,9 @@ putvalues_event::export_as_text_( std::ostream &Output ) const {
bool bool
putvalues_event::is_command_for_owner( input_data const &Input ) const { putvalues_event::is_command_for_owner( input_data const &Input ) const {
if( starts_with( Input.data_text, "Load=" ) ) { return false; } if (Input.data_text.starts_with("Load=") || Input.data_text.starts_with("UnLoad=")) {
if( starts_with( Input.data_text, "UnLoad=" ) ) { return false; } return false;
}
// TBD, TODO: add other exceptions // TBD, TODO: add other exceptions
return true; return true;
@@ -1268,7 +1269,7 @@ multi_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
} }
else { else {
// potentially valid event name // potentially valid event name
if( starts_with( token, "none_" ) ) { if( token.starts_with("none_") ) {
// eventy rozpoczynające się od "none_" są ignorowane // eventy rozpoczynające się od "none_" są ignorowane
WriteLog( "Multi-event \"" + m_name + "\" ignored link to event \"" + token + "\"" ); WriteLog( "Multi-event \"" + m_name + "\" ignored link to event \"" + token + "\"" );
} }
@@ -1650,7 +1651,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ] >> m_animationparams[ 2 ]
>> m_animationparams[ 3 ]; >> m_animationparams[ 3 ];
} }
else if( ends_with( token, ".vmd" ) ) // na razie tu, może będzie inaczej else if( token.ends_with(".vmd") ) // na razie tu, może będzie inaczej
{ // animacja z pliku VMD { // animacja z pliku VMD
{ {
m_animationfilename = token; m_animationfilename = token;
@@ -2305,15 +2306,15 @@ event_manager::insert( basic_event *Event ) {
return false; return false;
} }
// tymczasowo wyjątki: // tymczasowo wyjątki:
else if( ends_with( Event->m_name, "lineinfo:" ) ) { else if( Event->m_name.ends_with("lineinfo:") ) {
// tymczasowa utylizacja duplikatów W5 // tymczasowa utylizacja duplikatów W5
return false; return false;
} }
else if( ends_with( Event->m_name, "_warning" ) ) { else if( Event->m_name.ends_with("_warning") ) {
// tymczasowa utylizacja duplikatu z trąbieniem // tymczasowa utylizacja duplikatu z trąbieniem
return false; return false;
} }
else if( ends_with( Event->m_name, "_shp" ) ) { else if( Event->m_name.ends_with("_shp") ) {
// nie podlegają logowaniu // nie podlegają logowaniu
// tymczasowa utylizacja duplikatu SHP // tymczasowa utylizacja duplikatu SHP
return false; return false;

View File

@@ -71,7 +71,7 @@ TCommandType TMemCell::CommandCheck()
eCommand = TCommandType::cm_OutsideStation; eCommand = TCommandType::cm_OutsideStation;
bCommand = false; // tego nie powinno być w komórce bCommand = false; // tego nie powinno być w komórce
} }
else if( starts_with( szText, "PassengerStopPoint:" ) ) // porównanie początków else if( szText.starts_with("PassengerStopPoint:") ) // porównanie początków
{ {
eCommand = TCommandType::cm_PassengerStopPoint; eCommand = TCommandType::cm_PassengerStopPoint;
bCommand = false; // tego nie powinno być w komórce bCommand = false; // tego nie powinno być w komórce

View File

@@ -611,7 +611,7 @@ TTrainParameters::load_sounds() {
} }
// specified arrival time means it's a scheduled stop // specified arrival time means it's a scheduled stop
auto const stationname { ( auto const stationname { (
ends_with( station.StationName, "_po" ) ? station.StationName.ends_with("_po") ?
station.StationName.substr( 0, station.StationName.size() - 3 ) : station.StationName.substr( 0, station.StationName.size() - 3 ) :
station.StationName ) }; station.StationName ) };

View File

@@ -29,9 +29,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
// HACK: determine whether current station is a (small) stop from the presence of "po" at the name end // HACK: determine whether current station is a (small) stop from the presence of "po" at the name end
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.ends_with("po") || contains( stationequipment, "po" ) };
( ends_with( stationname, "po" ) )
|| ( contains( stationequipment, "po" ) ) ) };
auto const maintenancestop { ( contains( stationequipment, "pt" ) ) }; 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