@@ -39,13 +39,10 @@ namespace {
3939 case ' \r ' : escaped += " \\ r" ; break ;
4040 case ' \t ' : escaped += " \\ t" ; break ;
4141 default :
42- if (c < 0x20 ) {
43- escaped += " \\ u" ;
44- escaped += " 0000" [0 ];
45- escaped += " 0000" [1 ];
46- char hex[3 ];
47- sprintf_s (hex, " %02x" , static_cast <unsigned char >(c));
48- escaped += hex;
42+ if (static_cast <unsigned char >(c) < 0x20 ) {
43+ char unicode_escape[7 ];
44+ sprintf_s (unicode_escape, sizeof (unicode_escape), " \\ u%04x" , static_cast <unsigned char >(c));
45+ escaped += unicode_escape;
4946 } else {
5047 escaped += c;
5148 }
@@ -54,6 +51,24 @@ namespace {
5451 }
5552 return escaped;
5653 }
54+
55+ template <typename T>
56+ void AddOptionalValue (std::ostringstream& json, const std::string& key, const T& value, const T& default_value, bool & first) {
57+ if (value != default_value) {
58+ if (!first) json << " ," ;
59+ json << " \" " << key << " \" :" ;
60+ if constexpr (std::is_same_v<T, std::string>) {
61+ json << " \" " << EscapeJsonString (value) << " \" " ;
62+ } else if constexpr (std::is_same_v<T, std::filesystem::path>) {
63+ json << " \" " << EscapeJsonString (value.string ()) << " \" " ;
64+ } else if constexpr (std::is_same_v<T, bool >) {
65+ json << (value ? " true" : " false" );
66+ } else {
67+ json << value;
68+ }
69+ first = false ;
70+ }
71+ }
5772}
5873
5974
@@ -119,25 +134,6 @@ UINT64 OVTelemetry::Keyword() const {
119134 return keyword_;
120135}
121136
122- template <typename T>
123- void AddOptionalValue (std::ostringstream& json, const std::string& key, const T& value, const T& default_value, bool & first) {
124- if (value != default_value) {
125- if (!first) json << " ," ;
126- json << " \" " << key << " \" :" ;
127- if constexpr (std::is_same_v<T, std::string>) {
128- json << " \" " << EscapeJsonString (value) << " \" " ;
129- } else if constexpr (std::is_same_v<T, std::filesystem::path>) {
130- json << " \" " << EscapeJsonString (value.string ()) << " \" " ;
131- } else if constexpr (std::is_same_v<T, bool >) {
132- json << (value ? " true" : " false" );
133- } else {
134- json << value;
135- }
136- first = false ;
137- }
138- }
139-
140-
141137std::string OVTelemetry::SerializeLoadConfig (const SessionContext& ctx) const {
142138 if (ctx.load_config .empty ()) return " {}" ;
143139
0 commit comments