Remove CStr::Find(CStr)

It was only a wrapper around `std::string::find`. In some places it's
now better to use `std::string::starts_with`.
This commit is contained in:
phosit
2026-08-23 17:07:27 +02:00
parent 45ea0432a2
commit 982ede2a55
7 changed files with 17 additions and 47 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ bool CObjectEntry::BuildVariation(const std::vector<const std::set<CStr>*>& comp
bool isAmmo = false;
// Handle the special attachpoint 'loaded-<proppoint>'
if (ppn.Find("loaded-") == 0)
if (ppn.starts_with("loaded-"))
{
ppn = prop.m_PropPointName.substr(7);
isAmmo = true;
+9 -9
View File
@@ -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<CGUISprite>();
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<SGUIImage>();
image->m_TextureName = TextureName;
if (SpriteName.Find("grayscale:") != -1)
if (SpriteName.find("grayscale:") != std::string::npos)
{
image->m_Effects = std::make_shared<SGUIImageEffects>();
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<SGUIImage>();
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<SGUIImageEffects>();
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<SGUIImageEffects>();
-12
View File
@@ -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<long>(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
{
-18
View File
@@ -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.
+5 -5
View File
@@ -334,8 +334,8 @@ std::vector<CStr> Mod::CheckForIncompatibleMods(const std::vector<CStr>& 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());
+1 -1
View File
@@ -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)
@@ -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<ICmpAttack> cmpAttack(m.Simulation2, m.Entity);
if (cmpAttack)