Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
glib/functions: fix get_charset logic
Browse files Browse the repository at this point in the history
This tweaks `get_charset()` signature and logic to properly return
both the charset label and the UTF-8 boolean.
  • Loading branch information
lucab committed Oct 29, 2020
1 parent 0a53cc0 commit cda1c2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions glib/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ status = "generate"
# unusable
ignore = true
[[object.function]]
name = "get_charset"
# boolean return value
ignore = true
[[object.function]]
name = "get_environ"
[object.function.return]
string_type = "os_string"
Expand Down
12 changes: 0 additions & 12 deletions glib/src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,6 @@ pub fn get_application_name() -> Option<GString> {
unsafe { from_glib_none(glib_sys::g_get_application_name()) }
}

pub fn get_charset() -> Option<GString> {
unsafe {
let mut charset = ptr::null();
let ret = from_glib(glib_sys::g_get_charset(&mut charset));
if ret {
Some(from_glib_none(charset))
} else {
None
}
}
}

pub fn get_codeset() -> GString {
unsafe { from_glib_full(glib_sys::g_get_codeset()) }
}
Expand Down
18 changes: 15 additions & 3 deletions glib/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(not(windows))]
use glib_sys;
#[cfg(any(feature = "v2_58", feature = "dox"))]
#[cfg(not(windows))]
Expand All @@ -15,12 +14,11 @@ use std::os::unix::io::FromRawFd;
// #[cfg(windows)]
// #[cfg(any(feature = "v2_58", feature = "dox"))]
// use std::os::windows::io::AsRawHandle;
#[cfg(not(windows))]
use std::ptr;
#[cfg(not(windows))]
use translate::*;
#[cfg(not(windows))]
use Error;
use GString;
#[cfg(not(windows))]
use Pid;
#[cfg(not(windows))]
Expand Down Expand Up @@ -212,3 +210,17 @@ pub fn spawn_async_with_pipes<
}
}
}

/// Obtain the character set for the current locale.
///
/// This returns whether the locale's encoding is UTF-8, and the current
/// charset if available.
pub fn get_charset() -> (bool, Option<GString>) {
let (is_utf8, charset);
let mut out_charset = ptr::null();
unsafe {
is_utf8 = from_glib(glib_sys::g_get_charset(&mut out_charset));
charset = from_glib_none(out_charset);
};
(is_utf8, charset)
}

0 comments on commit cda1c2d

Please # to comment.