Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements for SplitToOem #14746

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/host/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,23 @@ BOOL CheckBisectProcessW(const SCREEN_INFORMATION& ScreenInfo,
// Note: may throw on error
void SplitToOem(std::deque<std::unique_ptr<IInputEvent>>& events)
{
const auto codepage = ServiceLocator::LocateGlobals().getConsoleInformation().CP;

// convert events to oem codepage
const auto cp = ServiceLocator::LocateGlobals().getConsoleInformation().CP;
std::deque<std::unique_ptr<IInputEvent>> convertedEvents;
while (!events.empty())

for (auto& currentEvent : events)
{
auto currentEvent = std::move(events.front());
events.pop_front();
if (currentEvent->EventType() == InputEventType::KeyEvent)
{
const auto pKeyEvent = static_cast<const KeyEvent* const>(currentEvent.get());
// convert from wchar to char
std::wstring wstr{ pKeyEvent->GetCharData() };
const auto str = ConvertToA(codepage, wstr);
const auto wch = pKeyEvent->GetCharData();

char buffer[8];
const auto length = WideCharToMultiByte(cp, 0, &wch, 1, &buffer[0], sizeof(buffer), nullptr, nullptr);
THROW_LAST_ERROR_IF(length <= 0);

const std::string_view str{ &buffer[0], gsl::narrow_cast<size_t>(length) };

for (auto& ch : str)
for (const auto& ch : str)
{
auto tempEvent = std::make_unique<KeyEvent>(*pKeyEvent);
tempEvent->SetCharData(ch);
Expand All @@ -218,12 +219,8 @@ void SplitToOem(std::deque<std::unique_ptr<IInputEvent>>& events)
convertedEvents.push_back(std::move(currentEvent));
}
}
// move all events back
while (!convertedEvents.empty())
{
events.push_back(std::move(convertedEvents.front()));
convertedEvents.pop_front();
}

events = std::move(convertedEvents);
lhecker marked this conversation as resolved.
Show resolved Hide resolved
}

// Routine Description:
Expand Down