diff --git a/source/gui/Scripting/JSInterface_CGUISize.cpp b/source/gui/Scripting/JSInterface_CGUISize.cpp index 7f447e6957..fa1df5ac94 100644 --- a/source/gui/Scripting/JSInterface_CGUISize.cpp +++ b/source/gui/Scripting/JSInterface_CGUISize.cpp @@ -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* wrapper{JS::GetMaybePtrFromReservedSlot>(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) + " "; diff --git a/source/gui/Scripting/JSInterface_GUISize.cpp b/source/gui/Scripting/JSInterface_GUISize.cpp index 1f9c7e0918..9656328fef 100644 --- a/source/gui/Scripting/JSInterface_GUISize.cpp +++ b/source/gui/Scripting/JSInterface_GUISize.cpp @@ -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; diff --git a/source/gui/Scripting/JSInterface_GUISize.h b/source/gui/Scripting/JSInterface_GUISize.h index c2250d5e04..a3dc798a23 100644 --- a/source/gui/Scripting/JSInterface_GUISize.h +++ b/source/gui/Scripting/JSInterface_GUISize.h @@ -21,7 +21,8 @@ #include "lib/posix/posix_types.h" #include "lib/types.h" -#include "ps/CStr.h" + +#include 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 diff --git a/source/network/scripting/JSInterface_Network.cpp b/source/network/scripting/JSInterface_Network.cpp index 83cd27d970..279dd4a1ef 100644 --- a/source/network/scripting/JSInterface_Network.cpp +++ b/source/network/scripting/JSInterface_Network.cpp @@ -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()) ); } diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index cedab6cde7..6693a272cb 100644 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -200,15 +200,6 @@ CStr CStr::Repeat(const CStr& str, size_t reps) return ret; } -// Construction from numbers: - -CStr CStr::FromDouble(double n) -{ - tstringstream ss; - ss << n; - return ss.str(); -} - // Conversion to numbers: int CStr::ToInt() const diff --git a/source/ps/CStr.h b/source/ps/CStr.h index cf7e36cae4..85ff427842 100644 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -95,8 +95,6 @@ public: // Conversions: - static CStr FromDouble(double n); - /** * Return CStr as Integer. * Conversion is from the beginning of CStr. diff --git a/source/ps/UserReport.cpp b/source/ps/UserReport.cpp index 59d86cf892..eb7ad21bfa 100644 --- a/source/ps/UserReport.cpp +++ b/source/ps/UserReport.cpp @@ -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(self->m_RequestDataOffset) / self->m_RequestData.size())); return amount; }