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:
phosit 2026-08-06 19:09:46 +02:00
parent d6bdf51d83
commit 146ed257bd
No known key found for this signature in database
GPG key ID: C9430B600671C268
7 changed files with 18 additions and 24 deletions

View file

@ -81,10 +81,10 @@ bool SetCRectField(JSContext* cx, unsigned argc, JS::Value* vp)
} }
// Produces "10", "-10", "50%", "50%-10", "50%+10", etc // 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) if (per == 0)
return CStr::FromDouble(pix); return fmt::format("{}", pix);
if (pix == 0) if (pix == 0)
return fmt::format("{}%", per); 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::CallArgs args{JS::CallArgsFromVp(argc, vp)};
JS::RootedObject obj{cx, &args.thisv().toObject()}; JS::RootedObject obj{cx, &args.thisv().toObject()};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE)}; 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.left, wrapper->GetMutable().percent.left) + " ";
buffer += ToPercentString(wrapper->GetMutable().pixel.top, wrapper->GetMutable().percent.top) + " "; buffer += ToPercentString(wrapper->GetMutable().pixel.top, wrapper->GetMutable().percent.top) + " ";

View file

@ -106,18 +106,21 @@ bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp)
} }
// Produces "10", "-10", "50%", "50%-10", "50%+10", etc // 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) 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) bool JSI_GUISize::toString(JSContext* cx, uint argc, JS::Value* vp)
{ {
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
CStr buffer; std::string buffer;
Script::Request rq(cx); Script::Request rq(cx);
double val, valr; double val, valr;

View file

@ -21,7 +21,8 @@
#include "lib/posix/posix_types.h" #include "lib/posix/posix_types.h"
#include "lib/types.h" #include "lib/types.h"
#include "ps/CStr.h"
#include <string>
namespace JS { class Value; } namespace JS { class Value; }
namespace Script { class Interface; } namespace Script { class Interface; }
@ -43,7 +44,7 @@ namespace JSI_GUISize
bool construct(JSContext* cx, uint argc, JS::Value* vp); bool construct(JSContext* cx, uint argc, JS::Value* vp);
bool toString(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 #endif // INCLUDED_JSI_GUISIZE

View file

@ -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. // (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. // It causes somewhat awkward message handling, but the resulting efficiency losses are negligible.
g_NetClient->SendFlareMessage( g_NetClient->SendFlareMessage(
CStr::FromDouble(positionX.toNumber()), fmt::format("{}", positionX.toNumber()),
CStr::FromDouble(positionY.toNumber()), fmt::format("{}", positionY.toNumber()),
CStr::FromDouble(positionZ.toNumber()) fmt::format("{}", positionZ.toNumber())
); );
} }

View file

@ -200,15 +200,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps)
return ret; return ret;
} }
// Construction from numbers:
CStr CStr::FromDouble(double n)
{
tstringstream<StrBase> ss;
ss << n;
return ss.str();
}
// Conversion to numbers: // Conversion to numbers:
int CStr::ToInt() const int CStr::ToInt() const

View file

@ -95,8 +95,6 @@ public:
// Conversions: // Conversions:
static CStr FromDouble(double n);
/** /**
* Return CStr as Integer. * Return CStr as Integer.
* Conversion is from the beginning of CStr. * Conversion is from the beginning of CStr.

View file

@ -449,7 +449,8 @@ private:
self->m_RequestDataOffset += amount; 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; return amount;
} }