diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index ab5cf9a5..93c03efb 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -9546,8 +9546,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) inputline = fizparser.getToken(false, "\n\r"); - bool comment = ((contains(inputline, '#')) || (starts_with(inputline, "//"))); - if (true == comment) + if (inputline.starts_with("//") || contains(inputline, '#')) { // skip commented lines continue; diff --git a/audio/sound.cpp b/audio/sound.cpp index fafcd53b..be8d53d6 100644 --- a/audio/sound.cpp +++ b/audio/sound.cpp @@ -190,7 +190,7 @@ sound_source::deserialize_mapping( cParser &Input ) { } 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 auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; @@ -221,7 +221,7 @@ sound_source::deserialize_mapping( cParser &Input ) { Input.getToken( false, "\n\r\t ,;" ), 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 auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; diff --git a/betterRenderer/renderer/source/nvtexture.cpp b/betterRenderer/renderer/source/nvtexture.cpp index 3ea15067..16cc1923 100644 --- a/betterRenderer/renderer/source/nvtexture.cpp +++ b/betterRenderer/renderer/source/nvtexture.cpp @@ -305,7 +305,7 @@ size_t NvTextureManager::FetchTexture(std::string path, int format_hint, path = ToLower(path); // temporary code for legacy assets -- textures with names beginning with # // are to be sharpened - if ((starts_with(path, "#")) || (contains(path, "/#"))) { + if (path.starts_with("#") || contains(path, "/#")) { traits += '#'; } } diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 96543401..85c29249 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -288,7 +288,7 @@ bool TAnimModel::Load(cParser *parser, bool ter) { // gdy brak modelu if (ter) // jeśli teren { - if( ends_with( name, ".t3d" ) ) { + if( name.ends_with(".t3d") ) { name[ name.length() - 3 ] = 'e'; } #ifdef EU07_USE_OLD_TERRAINCODE diff --git a/model/Model3d.cpp b/model/Model3d.cpp index 0e5a12d8..8dfa8be4 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -2215,13 +2215,13 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t, if (!pName.empty()) { // jeśli dany submodel jest zgaszonym światłem, to // domyślnie go ukrywamy - if (starts_with(pName, "Light_On")) + if (pName.starts_with("Light_On")) { // jeśli jest światłem numerowanym iVisible = 0; // to domyślnie wyłączyć, żeby się nie nakładało z obiektem "Light_Off" } else if (dynamic) { // 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ć, // żeby się nie nakładało z obiektem "_off" diff --git a/model/Texture.cpp b/model/Texture.cpp index c4dabd34..4ea7eed7 100644 --- a/model/Texture.cpp +++ b/model/Texture.cpp @@ -1324,8 +1324,7 @@ texture_manager::create( std::string Filename, bool const Loadnow, GLint Formath erase_leading_slashes( Filename ); Filename = ToLower( Filename ); // temporary code for legacy assets -- textures with names beginning with # are to be sharpened - if( ( starts_with( Filename, "#" ) ) - || ( contains( Filename, "/#" ) ) ) { + if( Filename.starts_with("#") || contains( Filename, "/#" ) ) { traits += '#'; } } diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 3c0a6dcd..32fbd962 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -566,8 +566,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 ) - && ( starts_with( Input.Name(), "scenery/zwr" ) ) - && ( ends_with( Input.Name(), ".inc" ) ) ) }; + && Input.Name().starts_with("scenery/zwr") + && Input.Name().ends_with(".inc") ) }; if( false == skip ) { @@ -749,7 +749,7 @@ state_serializer::deserialize_terrain(cParser &Input, scene::scratch_data &Scrat std::string line; Input.getTokens(1); 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); Global.file_binary_terrain_state = true; diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp index 23160586..c157935f 100644 --- a/utilities/utilities.cpp +++ b/utilities/utilities.cpp @@ -404,30 +404,16 @@ std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b) 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 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); } 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); } diff --git a/utilities/utilities.h b/utilities/utilities.h index 2dcb4010..26445a90 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -226,10 +226,6 @@ std::string_view substr_path(std::string const &Filename); // returns common prefix of two provided strings 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 bool contains(std::string_view const String, std::string_view Substring); bool contains(std::string_view const String, char Character); diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index 707acf6b..f1974555 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -1354,7 +1354,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) if( cabsection ) { // check whether we're still processing cab sections auto const §ionname { section.compartment->pName }; - cabsection &= ( ( sectionname.size() >= 4 ) && ( starts_with( sectionname, "cab" ) ) ); + cabsection &= ( ( sectionname.size() >= 4 ) && sectionname.starts_with("cab") ); } // TODO: add cablight devices 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 }; - if( starts_with( Destination, "make:" ) ) { + if( Destination.starts_with("make:") ) { // autogenerated texture destinationhandle = GfxRenderer->Fetch_Material( Destination ); } diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index cf5c2c98..390f8e9b 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -273,7 +273,7 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) { >> soundproofing[ 5 ]; 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 auto const indexstart { key.find_first_of( "-1234567890" ) }; auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) }; diff --git a/world/Event.cpp b/world/Event.cpp index 10a71bac..a2bbd6d9 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -298,7 +298,7 @@ basic_event::deserialize( cParser &Input, scene::scratch_data &Scratchpad ) { Input >> token; deserialize_targets( token ); - if( starts_with( m_name, "none_" ) ) { + if( m_name.starts_with("none_") ) { 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 >> token; // command type, previously held in param 6 - if( starts_with( token, "PassengerStopPoint:" ) ) { + if( token.starts_with("PassengerStopPoint:") ) { if( contains( token, '#' ) ) { token.erase( token.find( '#' ) ); // obcięcie unikatowości } @@ -835,8 +835,9 @@ putvalues_event::export_as_text_( std::ostream &Output ) const { bool putvalues_event::is_command_for_owner( input_data const &Input ) const { - if( starts_with( Input.data_text, "Load=" ) ) { return false; } - if( starts_with( Input.data_text, "UnLoad=" ) ) { return false; } + if (Input.data_text.starts_with("Load=") || Input.data_text.starts_with("UnLoad=")) { + return false; + } // TBD, TODO: add other exceptions return true; @@ -1268,7 +1269,7 @@ multi_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { } else { // potentially valid event name - if( starts_with( token, "none_" ) ) { + if( token.starts_with("none_") ) { // eventy rozpoczynające się od "none_" są ignorowane 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[ 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 { m_animationfilename = token; @@ -2305,15 +2306,15 @@ event_manager::insert( basic_event *Event ) { return false; } // tymczasowo wyjątki: - else if( ends_with( Event->m_name, "lineinfo:" ) ) { + else if( Event->m_name.ends_with("lineinfo:") ) { // tymczasowa utylizacja duplikatów W5 return false; } - else if( ends_with( Event->m_name, "_warning" ) ) { + else if( Event->m_name.ends_with("_warning") ) { // tymczasowa utylizacja duplikatu z trąbieniem return false; } - else if( ends_with( Event->m_name, "_shp" ) ) { + else if( Event->m_name.ends_with("_shp") ) { // nie podlegają logowaniu // tymczasowa utylizacja duplikatu SHP return false; diff --git a/world/MemCell.cpp b/world/MemCell.cpp index a5e79ce0..71c48c97 100644 --- a/world/MemCell.cpp +++ b/world/MemCell.cpp @@ -71,7 +71,7 @@ TCommandType TMemCell::CommandCheck() eCommand = TCommandType::cm_OutsideStation; 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; bCommand = false; // tego nie powinno być w komórce diff --git a/world/mtable.cpp b/world/mtable.cpp index ba560ff1..24a19336 100644 --- a/world/mtable.cpp +++ b/world/mtable.cpp @@ -611,7 +611,7 @@ TTrainParameters::load_sounds() { } // specified arrival time means it's a scheduled stop auto const stationname { ( - ends_with( station.StationName, "_po" ) ? + station.StationName.ends_with("_po") ? station.StationName.substr( 0, station.StationName.size() - 3 ) : station.StationName ) }; diff --git a/world/station.cpp b/world/station.cpp index 7bd18587..e35b2a3f 100644 --- a/world/station.cpp +++ b/world/station.cpp @@ -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 auto const stationname { Schedule.TimeTable[ Schedule.StationIndex ].StationName }; auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare }; - auto const trainstop { ( - ( ends_with( stationname, "po" ) ) - || ( contains( stationequipment, "po" ) ) ) }; + auto const trainstop {stationname.ends_with("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