@@ -201,7 +201,8 @@ namespace conversions
201201 _ASYNCRTIMP std::vector<unsigned char > __cdecl from_base64 (const utility::string_t & str);
202202
203203 template <typename Source>
204- utility::string_t print_string (const Source &val, const std::locale &loc)
204+ CASABLANCA_DEPRECATED (" All locale-sensitive APIs will be removed in a future update. Use stringstreams directly if locale support is required." )
205+ utility::string_t print_string (const Source &val, const std::locale& loc = std::locale())
205206 {
206207 utility::ostringstream_t oss;
207208 oss.imbue (loc);
@@ -213,19 +214,81 @@ namespace conversions
213214 return oss.str ();
214215 }
215216
216- template < typename Source>
217- utility::string_t print_string (const Source &val)
217+ CASABLANCA_DEPRECATED ( " All locale-sensitive APIs will be removed in a future update. Use stringstreams directly if locale support is required. " )
218+ inline utility::string_t print_string (const utility:: string_t &val)
218219 {
219- return print_string ( val, std::locale ()) ;
220+ return val;
220221 }
221222
222- inline utility:: string_t print_string ( const utility:: string_t &val)
223+ namespace details
223224 {
224- return val;
225+
226+ #if defined(__ANDROID__)
227+ template <class T >
228+ inline std::string to_string (const T& t)
229+ {
230+ std::ostringstream os;
231+ os.imbue (std::locale::classic ());
232+ os << t;
233+ return os.str ();
234+ }
235+ #endif
236+
237+ template <class T >
238+ inline utility::string_t to_string_t (T&& t)
239+ {
240+ #ifdef _UTF16_STRINGS
241+ using std::to_wstring;
242+ return to_wstring (std::forward<T>(t));
243+ #else
244+ #if !defined(__ANDROID__)
245+ using std::to_string;
246+ #endif
247+ return to_string (std::forward<T>(t));
248+ #endif
249+ }
250+
251+ template <typename Source>
252+ utility::string_t print_string (const Source &val)
253+ {
254+ utility::ostringstream_t oss;
255+ oss.imbue (std::locale::classic ());
256+ oss << val;
257+ if (oss.bad ())
258+ {
259+ throw std::bad_cast ();
260+ }
261+ return oss.str ();
262+ }
263+
264+ inline const utility::string_t & print_string (const utility::string_t &val)
265+ {
266+ return val;
267+ }
268+
269+ template <typename Target>
270+ Target scan_string (const utility::string_t &str)
271+ {
272+ Target t;
273+ utility::istringstream_t iss (str);
274+ iss.imbue (std::locale::classic ());
275+ iss >> t;
276+ if (iss.bad ())
277+ {
278+ throw std::bad_cast ();
279+ }
280+ return t;
281+ }
282+
283+ inline const utility::string_t & scan_string (const utility::string_t &str)
284+ {
285+ return str;
286+ }
225287 }
226288
227289 template <typename Target>
228- Target scan_string (const utility::string_t &str, const std::locale &loc)
290+ CASABLANCA_DEPRECATED (" All locale-sensitive APIs will be removed in a future update. Use stringstreams directly if locale support is required." )
291+ Target scan_string (const utility::string_t &str, const std::locale &loc = std::locale())
229292 {
230293 Target t;
231294 utility::istringstream_t iss (str);
@@ -238,12 +301,7 @@ namespace conversions
238301 return t;
239302 }
240303
241- template <typename Target>
242- Target scan_string (const utility::string_t &str)
243- {
244- return scan_string<Target>(str, std::locale ());
245- }
246-
304+ CASABLANCA_DEPRECATED (" All locale-sensitive APIs will be removed in a future update. Use stringstreams directly if locale support is required." )
247305 inline utility::string_t scan_string (const utility::string_t &str)
248306 {
249307 return str;
0 commit comments