chore: rename wchar_ptr_to_string to decode_wide

This commit is contained in:
amrbashir 2022-06-05 15:42:18 +02:00
parent fc7b519b6a
commit c8dcb40d56
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
2 changed files with 7 additions and 7 deletions

View file

@ -1,6 +1,6 @@
#![cfg(target_os = "windows")] #![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::{ use windows_sys::Win32::{
Foundation::{HWND, LPARAM, LRESULT, WPARAM}, Foundation::{HWND, LPARAM, LRESULT, WPARAM},
UI::{ UI::{
@ -72,7 +72,7 @@ impl Submenu {
unsafe { GetMenuItemInfoW(self.parent_hmenu, self.hmenu as _, false.into(), &mut info) }; 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<str>) { pub fn set_label(&mut self, label: impl AsRef<str>) {
@ -167,7 +167,7 @@ impl TextMenuItem {
unsafe { GetMenuItemInfoW(self.parent_hmenu, self.id as _, false.into(), &mut info) }; unsafe { GetMenuItemInfoW(self.parent_hmenu, self.id as _, false.into(), &mut info) };
wchar_ptr_to_string(info.dwTypeData) decode_wide(info.dwTypeData)
.split("\t") .split("\t")
.next() .next()
.unwrap_or_default() .unwrap_or_default()

View file

@ -31,8 +31,8 @@ pub fn LOWORD(dword: u32) -> u16 {
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn wchar_ptr_to_string(wchar: windows_sys::core::PWSTR) -> String { pub fn decode_wide(w_str: *mut u16) -> String {
let len = unsafe { windows_sys::Win32::Globalization::lstrlenW(wchar) } as usize; let len = unsafe { windows_sys::Win32::Globalization::lstrlenW(w_str) } as usize;
let wchar_slice = unsafe { std::slice::from_raw_parts(wchar, len) }; let w_str_slice = unsafe { std::slice::from_raw_parts(w_str, len) };
String::from_utf16_lossy(wchar_slice) String::from_utf16_lossy(w_str_slice)
} }