/ src / modules / cmdpal / Microsoft.Terminal.UI / Converters.cpp
Converters.cpp
  1  #include "pch.h"
  2  #include "Converters.h"
  3  #include "Converters.g.cpp"
  4  
  5  #pragma warning(disable : 26497) // We will make these functions constexpr, as they are part of an ABI boundary.
  6  #pragma warning(disable : 26440) // The function ... can be declared as noexcept.
  7  
  8  namespace winrt::Microsoft::Terminal::UI::implementation
  9  {
 10      // Booleans
 11      bool Converters::InvertBoolean(bool value)
 12      {
 13          return !value;
 14      }
 15  
 16      // winrt::Windows::UI::Xaml::Visibility Converters::InvertedBooleanToVisibility(bool value)
 17      // {
 18      //     return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
 19      // }
 20  
 21      // Numbers
 22      double Converters::PercentageToPercentageValue(double value)
 23      {
 24          return value * 100.0;
 25      }
 26  
 27      double Converters::PercentageValueToPercentage(double value)
 28      {
 29          return value / 100.0;
 30      }
 31  
 32      //winrt::hstring Converters::PercentageToPercentageString(double value)
 33      //{
 34      //    return winrt::hstring{ fmt::format(FMT_COMPILE(L"{:.0f}%"), value * 100.0) };
 35      //}
 36  
 37      // Strings
 38      bool Converters::StringsAreNotEqual(const winrt::hstring& expected, const winrt::hstring& actual)
 39      {
 40          return expected != actual;
 41      }
 42  
 43      bool Converters::StringNotEmpty(const winrt::hstring& value)
 44      {
 45          return !value.empty();
 46      }
 47  
 48      // winrt::Windows::UI::Xaml::Visibility Converters::StringNotEmptyToVisibility(const winrt::hstring& value)
 49      // {
 50      //     return value.empty() ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
 51      // }
 52  
 53      winrt::hstring Converters::StringOrEmptyIfPlaceholder(const winrt::hstring& placeholder, const winrt::hstring& value)
 54      {
 55          return placeholder == value ? L"" : value;
 56      }
 57  
 58      // Misc
 59      // winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight(double value)
 60      // {
 61      //     return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric<uint16_t>(value) };
 62      // }
 63  
 64      //winrt::Windows::UI::Xaml::Media::SolidColorBrush Converters::ColorToBrush(const winrt::Windows::UI::Color color)
 65      //{
 66      //    return Windows::UI::Xaml::Media::SolidColorBrush(color);
 67      //}
 68  
 69      // double Converters::FontWeightToDouble(const winrt::Windows::UI::Text::FontWeight fontWeight)
 70      // {
 71      //     return fontWeight.Weight;
 72      // }
 73  
 74      // double Converters::MaxValueFromPaddingString(const winrt::hstring& paddingString)
 75      // {
 76      //     std::wstring_view remaining{ paddingString };
 77      //     double maxVal = 0;
 78  
 79      //     // Get padding values till we run out of delimiter separated values in the stream
 80      //     // Non-numeral values detected will default to 0
 81      //     // std::stod will throw invalid_argument exception if the input is an invalid double value
 82      //     // std::stod will throw out_of_range exception if the input value is more than DBL_MAX
 83      //     try
 84      //     {
 85      //         while (!remaining.empty())
 86      //         {
 87      //             const std::wstring token{ til::prefix_split(remaining, L',') };
 88      //             // std::stod internally calls wcstod which handles whitespace prefix (which is ignored)
 89      //             //  & stops the scan when first char outside the range of radix is encountered
 90      //             // We'll be permissive till the extent that stod function allows us to be by default
 91      //             // Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail
 92      //             const auto curVal = std::stod(token);
 93      //             if (curVal > maxVal)
 94      //             {
 95      //                 maxVal = curVal;
 96      //             }
 97      //         }
 98      //     }
 99      //     catch (...)
100      //     {
101      //         // If something goes wrong, even if due to a single bad padding value, we'll return default 0 padding
102      //         maxVal = 0;
103      //         LOG_CAUGHT_EXCEPTION();
104      //     }
105  
106      //     return maxVal;
107      // }
108  }