7
7
8
8
namespace winrt ::Microsoft::Terminal::UI::implementation
9
9
{
10
- winrt::hstring Converters::AppendPercentageSign (double value)
10
+ // Booleans
11
+ bool Converters::InvertBoolean (bool value)
11
12
{
12
- return to_hstring (gsl::narrow_cast< uint32_t >( std::lrint ( value))) + L" % " ;
13
+ return ! value;
13
14
}
14
15
15
- winrt::Windows::UI::Xaml::Media::SolidColorBrush Converters::ColorToBrush ( const winrt::Windows::UI::Color& color )
16
+ winrt::Windows::UI::Xaml::Visibility Converters::InvertedBooleanToVisibility ( bool value )
16
17
{
17
- return Windows::UI::Xaml::Media::SolidColorBrush (color) ;
18
+ return value ? winrt:: Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible ;
18
19
}
19
20
20
- winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight (double value)
21
+ // Numbers
22
+ double Converters::PercentageToPercentageValue (double value)
21
23
{
22
- return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric< uint16_t >( value) } ;
24
+ return value * 100.0 ;
23
25
}
24
26
25
- double Converters::FontWeightToDouble ( const winrt::Windows::UI::Text::FontWeight& fontWeight )
27
+ double Converters::PercentageValueToPercentage ( double value )
26
28
{
27
- return fontWeight. Weight ;
29
+ return value / 100.0 ;
28
30
}
29
31
30
- bool Converters::InvertBoolean ( bool value)
32
+ winrt::hstring Converters::PercentageToPercentageString ( double value)
31
33
{
32
- return ! value;
34
+ return winrt::hstring{ fmt::format ( FMT_COMPILE ( L" {:.0f}% " ), value * 100.0 ) } ;
33
35
}
34
36
35
- winrt::Windows::UI::Xaml::Visibility Converters::InvertedBooleanToVisibility (bool value)
37
+ // Strings
38
+ bool Converters::StringsAreNotEqual (const winrt::hstring& expected, const winrt::hstring& actual)
36
39
{
37
- return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
40
+ return expected != actual;
41
+ }
42
+
43
+ winrt::Windows::UI::Xaml::Visibility Converters::StringNotEmptyToVisibility (const winrt::hstring& value)
44
+ {
45
+ return value.empty () ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
46
+ }
47
+
48
+ winrt::hstring Converters::StringOrEmptyIfPlaceholder (const winrt::hstring& placeholder, const winrt::hstring& value)
49
+ {
50
+ return placeholder == value ? L" " : value;
51
+ }
52
+
53
+ // Misc
54
+ winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight (double value)
55
+ {
56
+ return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric<uint16_t >(value) };
57
+ }
58
+
59
+ winrt::Windows::UI::Xaml::Media::SolidColorBrush Converters::ColorToBrush (const winrt::Windows::UI::Color color)
60
+ {
61
+ return Windows::UI::Xaml::Media::SolidColorBrush (color);
62
+ }
63
+
64
+ double Converters::FontWeightToDouble (const winrt::Windows::UI::Text::FontWeight fontWeight)
65
+ {
66
+ return fontWeight.Weight ;
38
67
}
39
68
40
69
double Converters::MaxValueFromPaddingString (const winrt::hstring& paddingString)
41
70
{
42
- const auto singleCharDelim = L' ,' ;
43
- std::wstringstream tokenStream (paddingString.c_str ());
44
- std::wstring token;
71
+ std::wstring_view remaining{ paddingString };
45
72
double maxVal = 0 ;
46
- size_t * idx = nullptr ;
47
73
48
74
// Get padding values till we run out of delimiter separated values in the stream
49
75
// Non-numeral values detected will default to 0
50
- // std::getline will not throw exception unless flags are set on the wstringstream
51
76
// std::stod will throw invalid_argument exception if the input is an invalid double value
52
77
// std::stod will throw out_of_range exception if the input value is more than DBL_MAX
53
78
try
54
79
{
55
- while (std::getline (tokenStream, token, singleCharDelim ))
80
+ while (!remaining. empty ( ))
56
81
{
82
+ const std::wstring token{ til::prefix_split (remaining, L' ,' ) };
57
83
// std::stod internally calls wcstod which handles whitespace prefix (which is ignored)
58
84
// & stops the scan when first char outside the range of radix is encountered
59
85
// We'll be permissive till the extent that stod function allows us to be by default
60
86
// Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail
61
- const auto curVal = std::stod (token, idx );
87
+ const auto curVal = std::stod (token);
62
88
if (curVal > maxVal)
63
89
{
64
90
maxVal = curVal;
@@ -74,35 +100,4 @@ namespace winrt::Microsoft::Terminal::UI::implementation
74
100
75
101
return maxVal;
76
102
}
77
-
78
- int Converters::PercentageToPercentageValue (double value)
79
- {
80
- return base::ClampMul (value, 100u );
81
- }
82
-
83
- double Converters::PercentageValueToPercentage (double value)
84
- {
85
- return base::ClampDiv<double , double >(value, 100 );
86
- }
87
-
88
- bool Converters::StringsAreNotEqual (const winrt::hstring& expected, const winrt::hstring& actual)
89
- {
90
- return expected != actual;
91
- }
92
- winrt::Windows::UI::Xaml::Visibility Converters::StringNotEmptyToVisibility (const winrt::hstring& value)
93
- {
94
- return value.empty () ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
95
- }
96
-
97
- // Method Description:
98
- // - Returns the value string, unless it matches the placeholder in which case the empty string.
99
- // Arguments:
100
- // - placeholder - the placeholder string.
101
- // - value - the value string.
102
- // Return Value:
103
- // - The value string, unless it matches the placeholder in which case the empty string.
104
- winrt::hstring Converters::StringOrEmptyIfPlaceholder (const winrt::hstring& placeholder, const winrt::hstring& value)
105
- {
106
- return placeholder == value ? L" " : value;
107
- }
108
103
}
0 commit comments