diff --git a/changelog.md b/changelog.md index 80c052d7b4..da01db952f 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,8 @@ when upgrading from a version of rust-sdl2 to another. [PR #1427](https://github.com/Rust-SDL2/rust-sdl2/pull/1427) **BREAKING CHANGE** Add system locale support. A new event type `Event::LocaleChanged` has been added. +[PR #1479](https://github.com/Rust-SDL2/rust-sdl2/pull/1479) Fix get_locale in locale.rs for platforms where c_char is u8. + ### v0.37.0 [PR #1406](https://github.com/Rust-SDL2/rust-sdl2/pull/1406) Update bindings to SDL 2.0.26, add Event.is\_touch() for mouse events, upgrade wgpu to 0.20 in examples diff --git a/src/sdl2/locale.rs b/src/sdl2/locale.rs index d879d7608d..d072f6b12f 100644 --- a/src/sdl2/locale.rs +++ b/src/sdl2/locale.rs @@ -75,18 +75,18 @@ unsafe fn get_locale(ptr: *const sys::SDL_Locale) -> Option { .to_string_lossy() .into_owned(); - let region = try_get_string(sdl_locale.country); + let region = if sdl_locale.country.is_null() { + None + } else { + Some( + std::ffi::CStr::from_ptr(sdl_locale.country) + .to_string_lossy() + .into_owned(), + ) + }; Some(Locale { lang, country: region, }) } - -unsafe fn try_get_string(ptr: *const i8) -> Option { - if ptr.is_null() { - None - } else { - Some(std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned()) - } -}