mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Remove CStr::Left
It was only a wrapper around `std::string::substr`. In some places it's better to use `std::string::starts_with`.
This commit is contained in:
+1
-1
@@ -732,7 +732,7 @@ void CGUI::Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObje
|
||||
{
|
||||
CStr name(attr.Value);
|
||||
|
||||
if (name.Left(2) == "__")
|
||||
if (name.starts_with("__"))
|
||||
{
|
||||
LOGERROR("GUI: Names starting with '__' are reserved for the engine (object: %s)", name.c_str());
|
||||
continue;
|
||||
|
||||
@@ -293,10 +293,10 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode)
|
||||
break;
|
||||
|
||||
if (m_iBufferPos == static_cast<int>(caption.length()))
|
||||
caption = caption.Left(static_cast<long>(caption.length()) - 1);
|
||||
caption = caption.substr(0, static_cast<long>(caption.length()) - 1);
|
||||
else
|
||||
caption =
|
||||
caption.Left(m_iBufferPos - 1) +
|
||||
caption.substr(0, m_iBufferPos - 1) +
|
||||
caption.Right(static_cast<long>(caption.length()) - m_iBufferPos);
|
||||
|
||||
--m_iBufferPos;
|
||||
@@ -320,7 +320,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode)
|
||||
break;
|
||||
|
||||
caption =
|
||||
caption.Left(m_iBufferPos) +
|
||||
caption.substr(0, m_iBufferPos) +
|
||||
caption.Right(static_cast<long>(caption.length()) - (m_iBufferPos + 1));
|
||||
|
||||
UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos);
|
||||
@@ -364,7 +364,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode)
|
||||
caption += cooked;
|
||||
else
|
||||
caption =
|
||||
caption.Left(m_iBufferPos) + cooked +
|
||||
caption.substr(0, m_iBufferPos) + cooked +
|
||||
caption.Right(static_cast<long>(caption.length()) - m_iBufferPos);
|
||||
|
||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos + 1);
|
||||
@@ -655,7 +655,7 @@ Input::Reaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event& ev)
|
||||
caption += text;
|
||||
else
|
||||
caption =
|
||||
caption.Left(m_iBufferPos) + text +
|
||||
caption.substr(0, m_iBufferPos) + text +
|
||||
caption.Right(static_cast<long>(caption.length()) - m_iBufferPos);
|
||||
|
||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
|
||||
@@ -691,7 +691,7 @@ Input::Reaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event& ev)
|
||||
virtualTo = m_iBufferPos;
|
||||
}
|
||||
|
||||
CStrW text = caption.Left(virtualTo).Right(virtualTo - virtualFrom);
|
||||
CStrW text = caption.substr(virtualFrom, virtualTo - virtualFrom);
|
||||
|
||||
SDL_SetClipboardText(text.ToUTF8().c_str());
|
||||
|
||||
@@ -718,7 +718,7 @@ Input::Reaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event& ev)
|
||||
if (!caption.empty() && m_iBufferPos != 0)
|
||||
{
|
||||
m_iBufferPos_Tail = m_iBufferPos;
|
||||
CStrW searchString = caption.Left(m_iBufferPos);
|
||||
CStrW searchString = caption.substr(0, m_iBufferPos);
|
||||
|
||||
// If we are starting in whitespace, adjust position until we get a non whitespace
|
||||
while (m_iBufferPos > 0)
|
||||
@@ -801,7 +801,7 @@ Input::Reaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event& ev)
|
||||
|
||||
if (!caption.empty() && m_iBufferPos != 0)
|
||||
{
|
||||
CStrW searchString = caption.Left(m_iBufferPos);
|
||||
CStrW searchString = caption.substr(0, m_iBufferPos);
|
||||
|
||||
// If we are starting in whitespace, adjust position until we get a non whitespace
|
||||
while (m_iBufferPos > 0)
|
||||
@@ -2009,8 +2009,8 @@ void CInput::DeleteCurSelection()
|
||||
}
|
||||
|
||||
// Silently change.
|
||||
m_Caption.Set(m_Caption->Left(virtualFrom) + m_Caption->Right(static_cast<long>(m_Caption->length()) - virtualTo),
|
||||
false);
|
||||
m_Caption.Set(m_Caption->substr(0, virtualFrom) +
|
||||
m_Caption->Right(static_cast<long>(m_Caption->length()) - virtualTo), false);
|
||||
|
||||
UpdateText(virtualFrom, virtualTo, virtualFrom);
|
||||
|
||||
|
||||
@@ -1613,7 +1613,7 @@ CStrW CNetServerWorker::SanitisePlayerName(const CStrW& original)
|
||||
|
||||
// Restrict the length
|
||||
if (name.length() > MAX_LENGTH)
|
||||
name = name.Left(MAX_LENGTH);
|
||||
name = name.substr(0, MAX_LENGTH);
|
||||
|
||||
// Don't allow surrounding whitespace
|
||||
name.Trim(PS_TRIM_BOTH);
|
||||
|
||||
@@ -643,7 +643,7 @@ void CConsole::LoadHistory()
|
||||
if (pos != CStrW::npos)
|
||||
{
|
||||
if (pos > 0)
|
||||
m_BufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos));
|
||||
m_BufHistory.push_front(str.substr(0, str[pos-1] == '\r' ? pos - 1 : pos));
|
||||
str.erase(0, pos + 1);
|
||||
}
|
||||
else if (str.length() > 0)
|
||||
|
||||
@@ -293,14 +293,6 @@ CStr CStr::UpperCase() const
|
||||
return newStr;
|
||||
}
|
||||
|
||||
|
||||
// Retrieve the substring of the first n characters
|
||||
CStr CStr::Left(size_t len) const
|
||||
{
|
||||
ENSURE(len <= length());
|
||||
return substr(0, len);
|
||||
}
|
||||
|
||||
// Retrieve the substring of the last n characters
|
||||
CStr CStr::Right(size_t len) const
|
||||
{
|
||||
|
||||
@@ -161,14 +161,6 @@ public:
|
||||
**/
|
||||
CStr UpperCase() const;
|
||||
|
||||
/**
|
||||
* Retrieve first n characters of the CStr.
|
||||
*
|
||||
* @param size_t len the number of characters to retrieve.
|
||||
* @return CStr retrieved substring.
|
||||
**/
|
||||
CStr Left(size_t len) const;
|
||||
|
||||
/**
|
||||
* Retrieve last n characters of the CStr.
|
||||
*
|
||||
|
||||
@@ -109,7 +109,7 @@ SDL_Scancode FindScancode(const CStr8& keyname)
|
||||
return code;
|
||||
|
||||
// Parse SYM_XX codes, see below.
|
||||
if (keyname.size() > 4 && keyname.Left(4) == "SYM_")
|
||||
if (keyname.size() > 4 && keyname.starts_with("SYM_"))
|
||||
return static_cast<SDL_Scancode>(CStr(keyname.substr(4)).ToInt());
|
||||
|
||||
return SDL_SCANCODE_UNKNOWN;
|
||||
|
||||
@@ -288,7 +288,7 @@ void WriteJSONFile(const Script::Interface& scriptInterface, const std::wstring&
|
||||
bool DeleteCampaignSave(const CStrW& filePath)
|
||||
{
|
||||
OsPath realPath;
|
||||
if (filePath.Left(16) != L"saves/campaigns/" || filePath.Right(12) != L".0adcampaign")
|
||||
if (!filePath.starts_with(L"saves/campaigns/") || filePath.Right(12) != L".0adcampaign")
|
||||
return false;
|
||||
if (!VfsFileExists(filePath))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user