mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 00:59:18 +02:00
Replace starts_with and ends_with with string class methods
This commit is contained in:
@@ -9546,8 +9546,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
|
||||
|
||||
inputline = fizparser.getToken<std::string>(false, "\n\r");
|
||||
|
||||
bool comment = ((contains(inputline, '#')) || (starts_with(inputline, "//")));
|
||||
if (true == comment)
|
||||
if (inputline.starts_with("//") || contains(inputline, '#'))
|
||||
{
|
||||
// skip commented lines
|
||||
continue;
|
||||
|
||||
@@ -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<float>( 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 ) };
|
||||
|
||||
@@ -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 += '#';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2215,13 +2215,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 (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"
|
||||
|
||||
@@ -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 += '#';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 ) };
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ) };
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user