Remove CStr::FromUInt

There is `std::to_string` which does the same. For most uses it's better
to use `fmt::format`.
This commit is contained in:
phosit 2026-08-03 17:44:20 +02:00
parent 06e199b12a
commit ae936e8177
No known key found for this signature in database
GPG key ID: C9430B600671C268
8 changed files with 21 additions and 22 deletions

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
@ -156,7 +156,8 @@ bool ResolveIncludesImpl(
it = includeCache.emplace(path, std::move(includeContent)).first;
}
// We need to insert #line directives to have correct line numbers in errors.
chunks.emplace_back(lineDirective + "1\n" + it->second + "\n" + lineDirective + CStr::FromUInt(line + 1) + "\n");
chunks.emplace_back(fmt::format("{}1\n{}\n{}{}\n", lineDirective, it->second, lineDirective,
line + 1));
processedParts.emplace_back(currentPart.substr(0, lineStart));
if (!ResolveIncludesImpl(chunks.back(), includeCache, includeCallback, chunks, processedParts))
return false;

View file

@ -755,7 +755,7 @@ void CGUI::Xeromyces_ReadObject(const XMBData& xmb, XMBElement element, IGUIObje
// Check if name isn't set, generate an internal name in that case.
if (!NameSet)
{
object->SetName("__internal(" + CStr::FromInt(m_InternalNameNumber) + ")");
object->SetName(fmt::format("__internal({})", m_InternalNameNumber));
++m_InternalNameNumber;
}
@ -977,7 +977,7 @@ void CGUI::Xeromyces_ReadRepeat(const XMBData& xmb, XMBElement element, IGUIObje
for (int n = 0; n < count; ++n)
{
NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]");
NameSubst.emplace_back(var, fmt::format("[{}]", n));
XERO_ITER_EL(element, child)
{

View file

@ -54,6 +54,7 @@
#include <algorithm>
#include <cstring>
#include <fmt/format.h>
#include <functional>
#include <iterator>
#include <memory>
@ -70,6 +71,10 @@
#include <miniupnpc/upnperrors.h>
#endif
#if FMT_VERSION >= 80000
#include <fmt/xchar.h>
#endif
/**
* Number of peers to allocate for the enet host.
* Limited by ENET_PROTOCOL_MAXIMUM_PEER_ID (4096).
@ -1641,7 +1646,7 @@ CStrW CNetServerWorker::DeduplicatePlayerName(const CStrW& original)
if (unique)
return name;
name = original + L" (" + CStrW::FromUInt(id++) + L")";
name = fmt::format(L"{}({})", original, id++);
}
}

View file

@ -19,6 +19,7 @@
#include "NetStats.h"
#include <fmt/format.h>
#include <string>
enum
@ -77,7 +78,7 @@ const std::vector<ProfileColumn>& CNetStatsTable::GetColumns()
std::lock_guard<std::mutex> lock(m_Mutex);
for (size_t i = 0; i < m_LatchedData.size(); ++i)
m_ColumnDescriptions.push_back(ProfileColumn("Peer "+CStr::FromUInt(i), 80));
m_ColumnDescriptions.push_back(ProfileColumn(fmt::format("Peer {}", i), 80));
}
return m_ColumnDescriptions;
@ -95,7 +96,7 @@ CStr CNetStatsTable::GetCellText(size_t row, size_t col)
#define ROW(id, title, member) \
case id: \
if (col == 0) return title; \
if (m_Peer) return CStr::FromUInt(m_Peer->member); \
if (m_Peer) return std::to_string(m_Peer->member); \
return "???"
switch(row)
@ -129,7 +130,7 @@ void CNetStatsTable::LatchHostState(const ENetHost& host)
std::lock_guard<std::mutex> lock(m_Mutex);
#define ROW(id, title, member) \
m_LatchedData[i].push_back(CStr::FromUInt(host.peers[i].member));
m_LatchedData[i].push_back(std::to_string(host.peers[i].member));
m_LatchedData.clear();
m_LatchedData.resize(host.peerCount);

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
@ -25,7 +25,7 @@
static inline CStr NetMessageStringConvert(u32 arg)
{
return CStr::FromUInt(arg);
return std::to_string(arg);
}
static inline CStr NetMessageStringConvert(const CStr8& arg)

View file

@ -202,13 +202,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps)
// Construction from numbers:
CStr CStr::FromUInt(unsigned int n)
{
tstringstream<StrBase> ss;
ss << n;
return ss.str();
}
CStr CStr::FromInt64(i64 n)
{
tstringstream<StrBase> ss;

View file

@ -95,7 +95,6 @@ public:
// Conversions:
static CStr FromUInt(unsigned int n);
static CStr FromInt64(i64 n);
static CStr FromDouble(double n);

View file

@ -90,21 +90,21 @@ CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
if (col == 0)
return "max nominal heap bytes";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_MAX_BYTES);
return CStr::FromUInt(n);
return std::to_string(n);
}
case Row_Bytes:
{
if (col == 0)
return "allocated bytes";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_BYTES);
return CStr::FromUInt(n);
return std::to_string(n);
}
case Row_NumberGC:
{
if (col == 0)
return "number of GCs";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_NUMBER);
return CStr::FromUInt(n);
return std::to_string(n);
}
default:
return "???";
@ -116,4 +116,4 @@ AbstractProfileTable* CScriptStatsTable::GetChild(size_t /*row*/)
return 0;
}
} // namespace Script
} // namespace Script