mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
Remove CStr::FromInt
There is `std::to_string` which does the same. For most uses it's better to use `fmt::format`.
This commit is contained in:
parent
84567e66c2
commit
06e199b12a
7 changed files with 16 additions and 22 deletions
|
|
@ -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
|
||||
|
|
@ -69,7 +69,7 @@ CObjectBase::CObjectBase(CObjectManager& objectManager, CActorDef& actorDef, u8
|
|||
m_Properties.m_FloatOnWater = false;
|
||||
|
||||
// Remove leading art/actors/ & include quality level.
|
||||
m_Identifier = m_ActorDef.m_Pathname.string8().substr(11) + CStr::FromInt(m_QualityLevel);
|
||||
m_Identifier = fmt::format("{}{}", m_ActorDef.m_Pathname.string8().substr(11), m_QualityLevel);
|
||||
}
|
||||
|
||||
std::unique_ptr<CObjectBase> CObjectBase::CopyWithQuality(u8 newQualityLevel) const
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ CStr CNetMessage::ToString() const
|
|||
if (GetType() == NMT_INVALID)
|
||||
return "MESSAGE_TYPE_NONE { Undefined Message }";
|
||||
else
|
||||
return "Unknown Message " + CStr::FromInt(GetType());
|
||||
return fmt::format("Unknown Message {}", static_cast<int>(GetType()));
|
||||
}
|
||||
|
||||
CNetMessage* CNetMessageFactory::CreateMessage(const void* pData,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2021 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
|
||||
|
|
@ -202,13 +202,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps)
|
|||
|
||||
// Construction from numbers:
|
||||
|
||||
CStr CStr::FromInt(int n)
|
||||
{
|
||||
tstringstream<StrBase> ss;
|
||||
ss << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
CStr CStr::FromUInt(unsigned int n)
|
||||
{
|
||||
tstringstream<StrBase> ss;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -95,7 +95,6 @@ public:
|
|||
|
||||
// Conversions:
|
||||
|
||||
static CStr FromInt(int n);
|
||||
static CStr FromUInt(unsigned int n);
|
||||
static CStr FromInt64(i64 n);
|
||||
static CStr FromDouble(double n);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
#include <SDL_keycode.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fmt/format.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
|
@ -122,7 +123,7 @@ CStr FindScancodeName(SDL_Scancode scancode)
|
|||
const char* name = SDL_GetScancodeName(scancode);
|
||||
// Some scancodes have no name, but we must have something to save/load/recognize it, so parse it as SYM_XX
|
||||
if (strlen(name) == 0)
|
||||
return CStr("SYM_") + CStr::FromInt(scancode);
|
||||
return fmt::format("SYM_{}", static_cast<int>(scancode));
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +222,7 @@ CStr FindKeyName(SDL_Scancode scancode)
|
|||
return name;
|
||||
|
||||
// Else, show something regardless, so the player knows it's at least recognized.
|
||||
return CStr("SYM_") + CStr::FromInt(scancode);
|
||||
return fmt::format("SYM_{}", static_cast<int>(scancode));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -517,7 +517,7 @@ void rewriteBuffer(u8* buffer, u32& bufferSize)
|
|||
std::string basic = attrib;
|
||||
std::map<std::string, double>::iterator time_attrib = time_per_attribute.find(attrib);
|
||||
if (time_attrib != time_per_attribute.end())
|
||||
basic += " " + CStr::FromInt(1000000*time_attrib->second) + "us";
|
||||
basic = fmt::format("{} {}us", basic, 1000000 * time_attrib->second);
|
||||
|
||||
u32 length = static_cast<u32>(basic.size());
|
||||
memcpy(buffer + writePos, &length, sizeof(length));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <deque>
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
|
@ -337,7 +338,7 @@ private:
|
|||
{
|
||||
long code = -1;
|
||||
curl_easy_getinfo(m_Curl, CURLINFO_RESPONSE_CODE, &code);
|
||||
SetStatus("completed:" + CStr::FromInt(code));
|
||||
SetStatus(fmt::format("completed:{}", code));
|
||||
|
||||
// Check for success code
|
||||
if (code == 200)
|
||||
|
|
@ -360,7 +361,7 @@ private:
|
|||
if (errorString.empty())
|
||||
errorString = curl_easy_strerror(err);
|
||||
|
||||
SetStatus("failed:" + CStr::FromInt(err) + ":" + errorString);
|
||||
SetStatus(fmt::format("failed:{}:{}", static_cast<int>(err), errorString));
|
||||
}
|
||||
|
||||
// We got an unhandled return code or a connection failure;
|
||||
|
|
@ -390,7 +391,7 @@ private:
|
|||
r += "&type=";
|
||||
AppendEscaped(r, report.m_Type);
|
||||
|
||||
r += "&version=" + CStr::FromInt(report.m_Version);
|
||||
r = fmt::format("{}&version={}", std::move(r), report.m_Version);
|
||||
|
||||
r += "&data=";
|
||||
AppendEscaped(r, report.m_Data);
|
||||
|
|
@ -529,7 +530,7 @@ bool CUserReporter::IsReportingEnabled()
|
|||
|
||||
void CUserReporter::SetReportingEnabled(bool enabled)
|
||||
{
|
||||
CStr val = CStr::FromInt(enabled ? REPORTER_VERSION : 0);
|
||||
const std::string val{std::to_string(enabled ? REPORTER_VERSION : 0)};
|
||||
g_ConfigDB.SetValueString(CFG_USER, "userreport.enabledversion", val);
|
||||
g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.enabledversion", val);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue