Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ToString.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Stroika/Foundation/Debug/Demangle.h"
7#include "Stroika/Foundation/Execution/Exceptions.h"
9
10#include "ToString.h"
11
12using namespace Stroika::Foundation;
14
15/*
16 ********************************************************************************
17 **************** Characters::ToStringDefaults::ToString ************************
18 ********************************************************************************
19 */
20String Characters::ToStringDefaults::ToString (const exception_ptr& e)
21{
22 static const String kExceptPrefix_{"Exception: "sv};
23 static const String kUnknown_{"Unknown Exception"sv};
24 if (e == nullptr) {
25 return "nullptr"sv;
26 }
27 try {
28 rethrow_exception (e);
29 }
30 catch (const Execution::ExceptionStringHelper& e) {
31 //saying Exception: first produces 'Exception: HTTP exception: status 404 (URL not found)}' - redundant. Not sure about all cases, but try this way.
32 //return kExceptPrefix_ + e.As<String> ();
33 return e.As<String> ();
34 }
35 catch (const exception& e) {
36 return kExceptPrefix_ + String::FromNarrowSDKString (e.what ());
37 }
38 catch (...) {
39 // fall through
40 }
41 return kUnknown_;
42}
43
44String Characters::ToStringDefaults::ToString (const std::exception& t)
45{
46 if (auto p = dynamic_cast<const Execution::ExceptionStringHelper*> (&t)) {
47 return p->As<String> ();
48 }
49 return String::FromNarrowSDKString (t.what ());
50}
51
52String Characters::ToStringDefaults::ToString (const type_info& t)
53{
54 //nb: demangle needed for gcc, but not msvc (but harmless there)
55 return Debug::Demangle (String::FromNarrowSDKString (t.name ()));
56}
57
58String Characters::ToStringDefaults::ToString (const type_index& t)
59{
60 //nb: demangle needed for gcc, but not msvc (but harmless there)
61 return Debug::Demangle (String::FromNarrowSDKString (t.name ()));
62}
63
64String Characters::ToStringDefaults::ToString (const thread::id& t)
65{
66 return String{Execution::Thread::FormatThreadID_A (t)};
67}
68
69String Characters::ToStringDefaults::ToString (bool t)
70{
71 static const String kTrue_{"true"sv};
72 static const String kFalse{"false"sv};
73 return t ? kTrue_ : kFalse;
74}
75
76String Characters::ToStringDefaults::ToString (const Time::Duration& t, FloatConversion::Precision p)
77{
78 return t.As<String> (p);
79}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Duration is a chrono::duration<double> (=.
Definition Duration.h:96