Skip to content

Fix LocaleIterator for platforms where c_char is u8 (better fix?) #1479

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/sdl2/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ unsafe fn get_locale(ptr: *const sys::SDL_Locale) -> Option<Locale> {
.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<String> {
if ptr.is_null() {
None
} else {
Some(std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
Loading