diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index 518a3e1199..dc347b6a15 100644 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -271,7 +271,7 @@ bool CObjectEntry::BuildVariation(const std::vector*>& comp bool isAmmo = false; // Handle the special attachpoint 'loaded-' - if (ppn.Find("loaded-") == 0) + if (ppn.starts_with("loaded-")) { ppn = prop.m_PropPointName.substr(7); isAmmo = true; diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 107bdd6812..04cdd39b1a 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -90,7 +90,7 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const * "grayscale:color:255 255 255 100:stretched:filename.ext" */ // Check that this can be a special sprite. - if (SpriteName.ReverseFind(":") == -1 && SpriteName.Find("color(") == -1) + if (SpriteName.ReverseFind(":") == -1 && SpriteName.find("color(") == std::string::npos) { LOGERROR("Trying to use a sprite that doesn't exist (\"%s\").", SpriteName.c_str()); return; @@ -98,13 +98,13 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const auto sprite = std::make_unique(); VfsPath TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.AfterLast(":")); - if (SpriteName.Find("stretched:") != -1) + if (SpriteName.find("stretched:") != std::string::npos) { // TODO: Should check (nicely) that this is a valid file? auto image = std::make_unique(); image->m_TextureName = TextureName; - if (SpriteName.Find("grayscale:") != -1) + if (SpriteName.find("grayscale:") != std::string::npos) { image->m_Effects = std::make_shared(); image->m_Effects->m_Greyscale = true; @@ -112,12 +112,12 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const sprite->AddImage(std::move(image)); } - else if (SpriteName.Find("cropped:") != -1) + else if (SpriteName.find("cropped:") != std::string::npos) { // TODO: Should check (nicely) that this is a valid file? auto image = std::make_unique(); - const bool centered = SpriteName.Find("center:") != -1; + const bool centered = SpriteName.find("center:") != std::string::npos; CStr info = SpriteName.AfterLast("cropped:").BeforeFirst(":"); double xRatio = info.BeforeFirst(",").ToDouble(); @@ -128,7 +128,7 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const image->m_TextureSize = CGUISize(CRect(0, 0, 0, 0), percentSize); image->m_TextureName = TextureName; - if (SpriteName.Find("grayscale:") != -1) + if (SpriteName.find("grayscale:") != std::string::npos) { image->m_Effects = std::make_shared(); image->m_Effects->m_Greyscale = true; @@ -136,7 +136,7 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const sprite->AddImage(std::move(image)); } - if (SpriteName.Find("color:") != -1) + if (SpriteName.find("color:") != std::string::npos) { CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":")); @@ -146,7 +146,7 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const // If we are using a mask, this is an effect. // Otherwise we can fallback to the "back color" attribute // TODO: we are assuming there is a filename here. - if (SpriteName.Find("textureAsMask:") != -1) + if (SpriteName.find("textureAsMask:") != std::string::npos) { image->m_TextureName = TextureName; image->m_Effects = std::make_shared(); diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 6693a272cb..16368933e3 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -264,17 +264,6 @@ double CStr::ToDouble() const return ret; } -// Search the string for another string -long CStr::Find(const CStr& str) const -{ - size_t pos = find(str, 0); - - if (pos != npos) - return static_cast(pos); - - return -1; -} - // Search the string for another string long CStr::Find(const Char chr) const { @@ -299,7 +288,6 @@ long CStr::Find(const int start, const Char chr) const long CStr::FindInsensitive(const int start, const Char chr) const { return LowerCase().Find(start, totlower(chr)); } long CStr::FindInsensitive(const Char chr) const { return LowerCase().Find(totlower(chr)); } -long CStr::FindInsensitive(const CStr& str) const { return LowerCase().Find(str.LowerCase()); } long CStr::ReverseFind(const CStr& str) const { diff --git a/source/ps/CStr.h b/source/ps/CStr.h index 85ff427842..64874153a1 100644 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -138,15 +138,6 @@ public: **/ double ToDouble() const; - /** - * Search the CStr for another string. - * The search is case-sensitive. - * - * @param const CStr & str reference to the search string - * @return long offset into the CStr of the first occurrence of the search string - * -1 if the search string is not found - **/ - long Find(const CStr& str) const; /** * Search the CStr for another string. * The search is case-sensitive. @@ -167,15 +158,6 @@ public: **/ long Find(const int start, const Char chr) const; - /** - * Search the CStr for another string. - * The search is case-insensitive. - * - * @param const CStr & str reference to the search string - * @return long offset into the CStr of the first occurrence of the search string - * -1 if the search string is not found - **/ - long FindInsensitive(const CStr& str) const; /** * Search the CStr for another string. * The search is case-insensitive. diff --git a/source/ps/Mod.cpp b/source/ps/Mod.cpp index 8eb71fc370..a6a7feeaf5 100644 --- a/source/ps/Mod.cpp +++ b/source/ps/Mod.cpp @@ -334,8 +334,8 @@ std::vector Mod::CheckForIncompatibleMods(const std::vector& mods) c // 0ad<=0.0.24 for (const CStr& op : toCheck) { - const int pos = dep.Find(op.c_str()); - if (pos == -1) + const std::size_t pos{dep.find(op)}; + if (pos == std::string::npos) continue; //0ad const CStr modToCheck = dep.substr(0, pos); @@ -364,9 +364,9 @@ bool Mod::CompareVersionStrings(const CStr& version, const CStr& op, const CStr& boost::split(versionSplit, versionSplit[0], boost::is_any_of("."), boost::token_compress_on); boost::split(requiredSplit, requiredSplit[0], boost::is_any_of("."), boost::token_compress_on); - const bool eq = op.Find("=") != -1; - const bool lt = op.Find("<") != -1; - const bool gt = op.Find(">") != -1; + const bool eq = op.find("=") != std::string::npos; + const bool lt = op.find("<") != std::string::npos; + const bool gt = op.find(">") != std::string::npos; const size_t min = std::min(versionSplit.size(), requiredSplit.size()); diff --git a/source/soundmanager/scripting/SoundGroup.cpp b/source/soundmanager/scripting/SoundGroup.cpp index 3a853f405d..fd9514c53b 100644 --- a/source/soundmanager/scripting/SoundGroup.cpp +++ b/source/soundmanager/scripting/SoundGroup.cpp @@ -370,7 +370,7 @@ bool CSoundGroup::LoadSoundGroup(const VfsPath& pathnameXML) } else if (child_name == el_heardby) { - if (child.GetText().FindInsensitive("owner") == 0) + if (child.GetText().LowerCase().starts_with("owner")) SetFlag(eOwnerOnly); } else if (child_name == el_distanceless) diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index eba78e0968..6cf10b5bcb 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -430,7 +430,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStr& animation, player_id_t m.CurrentSpeed = speed; } - else if (anim.Find("attack_") == 0) + else if (anim.starts_with("attack_")) { CmpPtr cmpAttack(m.Simulation2, m.Entity); if (cmpAttack)