mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
Remove CStr::FromDouble
In most places `fmt::format` is used because it's locale indidendant. For the user reporter the locale dependant form of `fmt::format` is used because it's shown to the user.
This commit is contained in:
parent
d6bdf51d83
commit
146ed257bd
7 changed files with 18 additions and 24 deletions
|
|
@ -81,10 +81,10 @@ bool SetCRectField(JSContext* cx, unsigned argc, JS::Value* vp)
|
|||
}
|
||||
|
||||
// Produces "10", "-10", "50%", "50%-10", "50%+10", etc
|
||||
CStr ToPercentString(double pix, double per)
|
||||
std::string ToPercentString(double pix, double per)
|
||||
{
|
||||
if (per == 0)
|
||||
return CStr::FromDouble(pix);
|
||||
return fmt::format("{}", pix);
|
||||
|
||||
if (pix == 0)
|
||||
return fmt::format("{}%", per);
|
||||
|
|
@ -97,7 +97,7 @@ bool toString(JSContext* cx, uint argc, JS::Value* vp)
|
|||
JS::CallArgs args{JS::CallArgsFromVp(argc, vp)};
|
||||
JS::RootedObject obj{cx, &args.thisv().toObject()};
|
||||
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE)};
|
||||
CStr buffer;
|
||||
std::string buffer;
|
||||
|
||||
buffer += ToPercentString(wrapper->GetMutable().pixel.left, wrapper->GetMutable().percent.left) + " ";
|
||||
buffer += ToPercentString(wrapper->GetMutable().pixel.top, wrapper->GetMutable().percent.top) + " ";
|
||||
|
|
|
|||
|
|
@ -106,18 +106,21 @@ bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp)
|
|||
}
|
||||
|
||||
// Produces "10", "-10", "50%", "50%-10", "50%+10", etc
|
||||
CStr JSI_GUISize::ToPercentString(double pix, double per)
|
||||
std::string JSI_GUISize::ToPercentString(double pix, double per)
|
||||
{
|
||||
if (per == 0)
|
||||
return CStr::FromDouble(pix);
|
||||
return fmt::format("{}", pix);
|
||||
|
||||
return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix));
|
||||
if (pix == 0.0)
|
||||
return fmt::format("{}%", per);
|
||||
|
||||
return fmt::format("{}%{:+}", per, pix);
|
||||
}
|
||||
|
||||
bool JSI_GUISize::toString(JSContext* cx, uint argc, JS::Value* vp)
|
||||
{
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
CStr buffer;
|
||||
std::string buffer;
|
||||
|
||||
Script::Request rq(cx);
|
||||
double val, valr;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
#include "lib/posix/posix_types.h"
|
||||
#include "lib/types.h"
|
||||
#include "ps/CStr.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace JS { class Value; }
|
||||
namespace Script { class Interface; }
|
||||
|
|
@ -43,7 +44,7 @@ namespace JSI_GUISize
|
|||
bool construct(JSContext* cx, uint argc, JS::Value* vp);
|
||||
bool toString(JSContext* cx, uint argc, JS::Value* vp);
|
||||
|
||||
CStr ToPercentString(double pix, double per);
|
||||
std::string ToPercentString(double pix, double per);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_GUISIZE
|
||||
|
|
|
|||
|
|
@ -280,9 +280,9 @@ void SendNetworkFlare(JS::HandleValue position)
|
|||
// (TODO?): Converting the doubles into strings here is a workaround because direct (de)serialisation of floating point numbers is not supported.
|
||||
// It causes somewhat awkward message handling, but the resulting efficiency losses are negligible.
|
||||
g_NetClient->SendFlareMessage(
|
||||
CStr::FromDouble(positionX.toNumber()),
|
||||
CStr::FromDouble(positionY.toNumber()),
|
||||
CStr::FromDouble(positionZ.toNumber())
|
||||
fmt::format("{}", positionX.toNumber()),
|
||||
fmt::format("{}", positionY.toNumber()),
|
||||
fmt::format("{}", positionZ.toNumber())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,15 +200,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// Construction from numbers:
|
||||
|
||||
CStr CStr::FromDouble(double n)
|
||||
{
|
||||
tstringstream<StrBase> ss;
|
||||
ss << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
// Conversion to numbers:
|
||||
|
||||
int CStr::ToInt() const
|
||||
|
|
|
|||
|
|
@ -95,8 +95,6 @@ public:
|
|||
|
||||
// Conversions:
|
||||
|
||||
static CStr FromDouble(double n);
|
||||
|
||||
/**
|
||||
* Return CStr as Integer.
|
||||
* Conversion is from the beginning of CStr.
|
||||
|
|
|
|||
|
|
@ -449,7 +449,8 @@ private:
|
|||
self->m_RequestDataOffset += amount;
|
||||
}
|
||||
|
||||
self->SetStatus("sending:" + CStr::FromDouble((double)self->m_RequestDataOffset / self->m_RequestData.size()));
|
||||
self->SetStatus(fmt::format("sending:{:L}",
|
||||
static_cast<double>(self->m_RequestDataOffset) / self->m_RequestData.size()));
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue