mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
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:
parent
06e199b12a
commit
ae936e8177
8 changed files with 21 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.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 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;
|
it = includeCache.emplace(path, std::move(includeContent)).first;
|
||||||
}
|
}
|
||||||
// We need to insert #line directives to have correct line numbers in errors.
|
// 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));
|
processedParts.emplace_back(currentPart.substr(0, lineStart));
|
||||||
if (!ResolveIncludesImpl(chunks.back(), includeCache, includeCallback, chunks, processedParts))
|
if (!ResolveIncludesImpl(chunks.back(), includeCache, includeCallback, chunks, processedParts))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Check if name isn't set, generate an internal name in that case.
|
||||||
if (!NameSet)
|
if (!NameSet)
|
||||||
{
|
{
|
||||||
object->SetName("__internal(" + CStr::FromInt(m_InternalNameNumber) + ")");
|
object->SetName(fmt::format("__internal({})", m_InternalNameNumber));
|
||||||
++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)
|
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)
|
XERO_ITER_EL(element, child)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -70,6 +71,10 @@
|
||||||
#include <miniupnpc/upnperrors.h>
|
#include <miniupnpc/upnperrors.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FMT_VERSION >= 80000
|
||||||
|
#include <fmt/xchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of peers to allocate for the enet host.
|
* Number of peers to allocate for the enet host.
|
||||||
* Limited by ENET_PROTOCOL_MAXIMUM_PEER_ID (4096).
|
* Limited by ENET_PROTOCOL_MAXIMUM_PEER_ID (4096).
|
||||||
|
|
@ -1641,7 +1646,7 @@ CStrW CNetServerWorker::DeduplicatePlayerName(const CStrW& original)
|
||||||
if (unique)
|
if (unique)
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
name = original + L" (" + CStrW::FromUInt(id++) + L")";
|
name = fmt::format(L"{}({})", original, id++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "NetStats.h"
|
#include "NetStats.h"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -77,7 +78,7 @@ const std::vector<ProfileColumn>& CNetStatsTable::GetColumns()
|
||||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||||
|
|
||||||
for (size_t i = 0; i < m_LatchedData.size(); ++i)
|
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;
|
return m_ColumnDescriptions;
|
||||||
|
|
@ -95,7 +96,7 @@ CStr CNetStatsTable::GetCellText(size_t row, size_t col)
|
||||||
#define ROW(id, title, member) \
|
#define ROW(id, title, member) \
|
||||||
case id: \
|
case id: \
|
||||||
if (col == 0) return title; \
|
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 "???"
|
return "???"
|
||||||
|
|
||||||
switch(row)
|
switch(row)
|
||||||
|
|
@ -129,7 +130,7 @@ void CNetStatsTable::LatchHostState(const ENetHost& host)
|
||||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||||
|
|
||||||
#define ROW(id, title, member) \
|
#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.clear();
|
||||||
m_LatchedData.resize(host.peerCount);
|
m_LatchedData.resize(host.peerCount);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2025 Wildfire Games.
|
/* Copyright (C) 2026 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
static inline CStr NetMessageStringConvert(u32 arg)
|
static inline CStr NetMessageStringConvert(u32 arg)
|
||||||
{
|
{
|
||||||
return CStr::FromUInt(arg);
|
return std::to_string(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CStr NetMessageStringConvert(const CStr8& arg)
|
static inline CStr NetMessageStringConvert(const CStr8& arg)
|
||||||
|
|
|
||||||
|
|
@ -202,13 +202,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps)
|
||||||
|
|
||||||
// Construction from numbers:
|
// Construction from numbers:
|
||||||
|
|
||||||
CStr CStr::FromUInt(unsigned int n)
|
|
||||||
{
|
|
||||||
tstringstream<StrBase> ss;
|
|
||||||
ss << n;
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
CStr CStr::FromInt64(i64 n)
|
CStr CStr::FromInt64(i64 n)
|
||||||
{
|
{
|
||||||
tstringstream<StrBase> ss;
|
tstringstream<StrBase> ss;
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,6 @@ public:
|
||||||
|
|
||||||
// Conversions:
|
// Conversions:
|
||||||
|
|
||||||
static CStr FromUInt(unsigned int n);
|
|
||||||
static CStr FromInt64(i64 n);
|
static CStr FromInt64(i64 n);
|
||||||
static CStr FromDouble(double n);
|
static CStr FromDouble(double n);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,21 +90,21 @@ CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
return "max nominal heap bytes";
|
return "max nominal heap bytes";
|
||||||
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_MAX_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:
|
case Row_Bytes:
|
||||||
{
|
{
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
return "allocated bytes";
|
return "allocated bytes";
|
||||||
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_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:
|
case Row_NumberGC:
|
||||||
{
|
{
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
return "number of GCs";
|
return "number of GCs";
|
||||||
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_NUMBER);
|
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_NUMBER);
|
||||||
return CStr::FromUInt(n);
|
return std::to_string(n);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return "???";
|
return "???";
|
||||||
|
|
@ -116,4 +116,4 @@ AbstractProfileTable* CScriptStatsTable::GetChild(size_t /*row*/)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Script
|
} // namespace Script
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue