diff --git a/cpp-terminal/platforms/conversion.cpp b/cpp-terminal/platforms/conversion.cpp index 5e61b121..56d1182d 100644 --- a/cpp-terminal/platforms/conversion.cpp +++ b/cpp-terminal/platforms/conversion.cpp @@ -105,19 +105,12 @@ std::string utf32_to_utf8(const std::u32string& s) bool is_valid_utf8_code_unit(const std::string& s) { - static const constexpr int b1OOOOOOO{128}; - static const constexpr int b11OOOOOO{192}; - static const constexpr int b111OOOOO{224}; - static const constexpr int b1111OOOO{240}; - static const constexpr int b11111OOO{248}; - switch(s.size()) - { - case 1: return ((s[0] & b1OOOOOOO) == 0) ? true : false; - case 2: return ((s[0] & b111OOOOO) == b11OOOOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO) ? true : false; - case 3: return ((s[0] & b1111OOOO) == b111OOOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO) && ((s[2] & b11OOOOOO) == b1OOOOOOO) ? true : false; - case 4: return ((s[0] & b11111OOO) == b1111OOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO) && ((s[2] & b11OOOOOO) == b1OOOOOOO) && ((s[3] & b11OOOOOO) == b1OOOOOOO) ? true : false; - default: return false; - } + static constexpr const int b1OOOOOOO{128}; + static constexpr const int b11OOOOOO{192}; + static constexpr const int b111OOOOO{224}; + static constexpr const int b1111OOOO{240}; + static constexpr const int b11111OOO{248}; + return ((s[0] & b1OOOOOOO) == 0) || (((s[0] & b111OOOOO) == b11OOOOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO)) || (((s[0] & b1111OOOO) == b111OOOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO) && ((s[2] & b11OOOOOO) == b1OOOOOOO)) || (((s[0] & b11111OOO) == b1111OOOO) && ((s[1] & b11OOOOOO) == b1OOOOOOO) && ((s[2] & b11OOOOOO) == b1OOOOOOO) && ((s[3] & b11OOOOOO) == b1OOOOOOO)); } } // namespace Private diff --git a/cpp-terminal/platforms/input.cpp b/cpp-terminal/platforms/input.cpp index a0b30ec3..a177494c 100644 --- a/cpp-terminal/platforms/input.cpp +++ b/cpp-terminal/platforms/input.cpp @@ -273,22 +273,22 @@ void Term::Private::Input::read_raw() { case 0: { - setButton(buttons, old_state.dwButtonState, state, 0); + setButton(buttons, static_cast(old_state.dwButtonState), state, 0); break; } case MOUSE_MOVED: { - setButton(buttons, old_state.dwButtonState, state, MOUSE_MOVED); + setButton(buttons, static_cast(old_state.dwButtonState), state, MOUSE_MOVED); break; } case DOUBLE_CLICK: { - setButton(buttons, old_state.dwButtonState, state, DOUBLE_CLICK); + setButton(buttons, static_cast(old_state.dwButtonState), state, DOUBLE_CLICK); break; } case MOUSE_WHEELED: { - setButton(buttons, old_state.dwButtonState, state, MOUSE_WHEELED); + setButton(buttons, static_cast(old_state.dwButtonState), state, MOUSE_WHEELED); if(state > 0) buttons[static_cast(Term::Button::Type::Wheel)] = Button(Term::Button::Type::Wheel, Term::Button::Action::RolledUp); else buttons[static_cast(Term::Button::Type::Wheel)] = Button(Term::Button::Type::Wheel, Term::Button::Action::RolledDown); @@ -296,7 +296,7 @@ void Term::Private::Input::read_raw() } case MOUSE_HWHEELED: { - setButton(buttons, old_state.dwButtonState, state, MOUSE_HWHEELED); + setButton(buttons, static_cast(old_state.dwButtonState), state, MOUSE_HWHEELED); if(state > 0) buttons[static_cast(Term::Button::Type::Wheel)] = Button(Term::Button::Type::Wheel, Term::Button::Action::ToRight); else buttons[static_cast(Term::Button::Type::Wheel)] = Button(Term::Button::Type::Wheel, Term::Button::Action::ToLeft);