From c8dcb40d5628c755243a8fbb824f915d5fa79478 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sun, 5 Jun 2022 15:42:18 +0200 Subject: [PATCH] chore: rename `wchar_ptr_to_string` to `decode_wide` --- src/platform_impl/windows.rs | 6 +++--- src/util.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform_impl/windows.rs b/src/platform_impl/windows.rs index 77c6fe0..731c8c1 100644 --- a/src/platform_impl/windows.rs +++ b/src/platform_impl/windows.rs @@ -1,6 +1,6 @@ #![cfg(target_os = "windows")] -use crate::util::{encode_wide, wchar_ptr_to_string, Counter, LOWORD}; +use crate::util::{decode_wide, encode_wide, Counter, LOWORD}; use windows_sys::Win32::{ Foundation::{HWND, LPARAM, LRESULT, WPARAM}, UI::{ @@ -72,7 +72,7 @@ impl Submenu { unsafe { GetMenuItemInfoW(self.parent_hmenu, self.hmenu as _, false.into(), &mut info) }; - wchar_ptr_to_string(info.dwTypeData) + decode_wide(info.dwTypeData) } pub fn set_label(&mut self, label: impl AsRef) { @@ -167,7 +167,7 @@ impl TextMenuItem { unsafe { GetMenuItemInfoW(self.parent_hmenu, self.id as _, false.into(), &mut info) }; - wchar_ptr_to_string(info.dwTypeData) + decode_wide(info.dwTypeData) .split("\t") .next() .unwrap_or_default() diff --git a/src/util.rs b/src/util.rs index e96e025..a6bcb48 100644 --- a/src/util.rs +++ b/src/util.rs @@ -31,8 +31,8 @@ pub fn LOWORD(dword: u32) -> u16 { } #[cfg(target_os = "windows")] -pub fn wchar_ptr_to_string(wchar: windows_sys::core::PWSTR) -> String { - let len = unsafe { windows_sys::Win32::Globalization::lstrlenW(wchar) } as usize; - let wchar_slice = unsafe { std::slice::from_raw_parts(wchar, len) }; - String::from_utf16_lossy(wchar_slice) +pub fn decode_wide(w_str: *mut u16) -> String { + let len = unsafe { windows_sys::Win32::Globalization::lstrlenW(w_str) } as usize; + let w_str_slice = unsafe { std::slice::from_raw_parts(w_str, len) }; + String::from_utf16_lossy(w_str_slice) }