mirror of
git://git.proxmox.com/git/perlmod.git
synced 2025-01-31 09:47:02 +03:00
set utf8 flag as needed when serializing strings
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
726fa9b484
commit
3f7917309b
@ -60,6 +60,7 @@ extern "C" {
|
||||
pub fn RSPL_newSVuv(v: usize) -> *mut SV;
|
||||
pub fn RSPL_newSVnv(v: f64) -> *mut SV;
|
||||
pub fn RSPL_newSVpvn(v: *const libc::c_char, len: libc::size_t) -> *mut SV;
|
||||
pub fn RSPL_newSVpvn_utf8(v: *const libc::c_char, len: libc::size_t) -> *mut SV;
|
||||
pub fn RSPL_SvREFCNT_inc(sv: *mut SV) -> *mut SV;
|
||||
pub fn RSPL_SvREFCNT_dec(sv: *mut SV);
|
||||
pub fn RSPL_is_reference(sv: *mut SV) -> bool;
|
||||
|
@ -127,6 +127,10 @@ extern SV* RSPL_newSVpvn(const char *v, size_t len) {
|
||||
return newSVpvn(v, len);
|
||||
}
|
||||
|
||||
extern SV* RSPL_newSVpvn_utf8(const char *v, size_t len) {
|
||||
return newSVpvn_utf8(v, len, 1);
|
||||
}
|
||||
|
||||
extern SV* RSPL_SvREFCNT_inc(SV *sv) {
|
||||
return SvREFCNT_inc(sv);
|
||||
}
|
||||
|
@ -88,7 +88,16 @@ impl Scalar {
|
||||
|
||||
/// Create a new string value.
|
||||
pub fn new_string(s: &str) -> Self {
|
||||
Self::new_bytes(s.as_bytes())
|
||||
if s.as_bytes().iter().any(|&b| b >= 0x80) {
|
||||
unsafe {
|
||||
Self::from_raw_move(ffi::RSPL_newSVpvn_utf8(
|
||||
s.as_bytes().as_ptr() as *const libc::c_char,
|
||||
s.as_bytes().len() as libc::size_t,
|
||||
))
|
||||
}
|
||||
} else {
|
||||
Self::new_bytes(s.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new byte string.
|
||||
|
Loading…
x
Reference in New Issue
Block a user