44#pragma once
55
66#include < cxxreact/JSExecutor.h>
7+ #include " Utils.h"
78
89namespace facebook {
910namespace react {
@@ -13,13 +14,14 @@ class DevServerHelper {
1314 DevServerHelper () = default ;
1415
1516 static std::string get_WebsocketProxyUrl (const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
16- return string_format (WebsocketProxyUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
17+ return Microsoft::React::FormatString (
18+ WebsocketProxyUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
1719 }
1820
1921 static std::string get_LaunchDevToolsCommandUrl (
2022 const std::string &sourceBundleHost,
2123 const uint16_t sourceBundlePort) {
22- return string_format (
24+ return Microsoft::React::FormatString (
2325 LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
2426 }
2527
@@ -36,16 +38,17 @@ class DevServerHelper {
3638 std::string hermesBytecodeVersionQuery;
3739 if (hermesBytecodeVersion > 0 ) {
3840 static constexpr const char HermesBytecodeVersionQueryFormat[] = " &runtimeBytecodeVersion=%d" ;
39- hermesBytecodeVersionQuery = string_format (HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
41+ hermesBytecodeVersionQuery =
42+ Microsoft::React::FormatString (HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
4043 }
4144
4245 std::string appIdQuery;
4346 if (bundleAppId.size () > 0 ) {
4447 static constexpr const char AppIdQueryFormat[] = " &app=%s" ;
45- appIdQuery = string_format (AppIdQueryFormat, bundleAppId.c_str ());
48+ appIdQuery = Microsoft::React::FormatString (AppIdQueryFormat, bundleAppId.c_str ());
4649 }
4750
48- return string_format (
51+ return Microsoft::React::FormatString (
4952 BundleUrlFormat,
5053 GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str (),
5154 jsbundle.c_str (),
@@ -58,17 +61,19 @@ class DevServerHelper {
5861 }
5962
6063 static std::string get_OnChangeEndpointUrl (const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
61- return string_format (OnChangeEndpointUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
64+ return Microsoft::React::FormatString (
65+ OnChangeEndpointUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
6266 }
6367
6468 static std::string get_PackagerConnectionUrl (const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
65- return string_format (PackagerConnectionUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
69+ return Microsoft::React::FormatString (
70+ PackagerConnectionUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
6671 }
6772
6873 static std::string get_PackagerOpenStackFrameUrl (
6974 const std::string &sourceBundleHost,
7075 const uint16_t sourceBundlePort) {
71- return string_format (
76+ return Microsoft::React::FormatString (
7277 PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost (sourceBundleHost, sourceBundlePort).c_str ());
7378 }
7479
@@ -78,7 +83,7 @@ class DevServerHelper {
7883 const std::string &deviceName,
7984 const std::string &packageName,
8085 const std::string &deviceId) {
81- return string_format (
86+ return Microsoft::React::FormatString (
8287 InspectorDeviceUrlFormat,
8388 GetDeviceLocalHost (packagerHost, packagerPort).c_str (),
8489 deviceName.c_str (),
@@ -88,7 +93,7 @@ class DevServerHelper {
8893
8994 static std::string
9095 get_OpenDebuggerUrl (const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) {
91- return string_format (
96+ return Microsoft::React::FormatString (
9297 OpenDebuggerUrlFormat, GetDeviceLocalHost (packagerHost, packagerPort).c_str (), deviceId.c_str ());
9398 }
9499
@@ -97,7 +102,7 @@ class DevServerHelper {
97102
98103 private:
99104 static std::string GetDeviceLocalHost (const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
100- return string_format (
105+ return Microsoft::React::FormatString (
101106 DeviceLocalHostFormat,
102107 sourceBundleHost.empty () ? DefaultPackagerHost : sourceBundleHost.c_str (),
103108 sourceBundlePort ? sourceBundlePort : DefaultPackagerPort);
@@ -118,15 +123,6 @@ class DevServerHelper {
118123
119124 static constexpr const char PackagerOkStatus[] = " packager-status:running" ;
120125 const int LongPollFailureDelayMs = 5000 ;
121-
122- // TODO: [vmoroz] avoid using vaiadic args for the format and move it to a utility class.
123- template <typename ... Args>
124- static std::string string_format (const char *format, Args... args) {
125- size_t size = snprintf (nullptr , 0 , format, args...) + 1 ;
126- std::unique_ptr<char []> buf (new char [size]);
127- snprintf (buf.get (), size, format, args...);
128- return std::string (buf.get (), buf.get () + size - 1 );
129- }
130126};
131127
132128} // namespace react
0 commit comments