Merge pull request #390 from deltachat/remove-dead-code

remove dead code
This commit is contained in:
Friedel Ziegelmayer
2019-08-17 14:02:00 +02:00
committed by GitHub

View File

@@ -167,12 +167,6 @@ pub unsafe fn dc_trim(buf: *mut libc::c_char) {
dc_rtrim(buf);
}
pub unsafe fn dc_strlower_in_place(in_0: *mut libc::c_char) {
let raw = CString::yolo(to_string(in_0).to_lowercase());
assert_eq!(strlen(in_0), strlen(raw.as_ptr()));
memcpy(in_0 as *mut _, raw.as_ptr() as *const _, strlen(in_0));
}
/* the result must be free()'d */
pub unsafe fn dc_null_terminate(
in_0: *const libc::c_char,
@@ -188,17 +182,6 @@ pub unsafe fn dc_null_terminate(
out
}
#[cfg(test)]
unsafe fn dc_binary_to_uc_hex(buf: *const uint8_t, bytes: size_t) -> *mut libc::c_char {
if buf.is_null() || bytes == 0 {
return std::ptr::null_mut();
}
let buf = std::slice::from_raw_parts(buf, bytes);
let raw = hex::encode_upper(buf);
raw.strdup()
}
/* remove all \r characters from string */
pub unsafe fn dc_remove_cr_chars(buf: *mut libc::c_char) {
/* search for first `\r` */
@@ -287,25 +270,6 @@ pub unsafe fn dc_replace_bad_utf8_chars(buf: *mut libc::c_char) {
}
}
#[cfg(test)]
unsafe fn dc_utf8_strlen(s: *const libc::c_char) -> size_t {
if s.is_null() {
return 0;
}
let mut i = 0;
let mut j: size_t = 0;
while 0 != *s.add(i) {
if *s.offset(i as isize) as libc::c_int & 0xc0 != 0x80 {
j = j.wrapping_add(1)
}
i += 1;
}
j
}
/// Shortens a string to a specified length and adds "..." or "[...]" to the end of
/// the shortened string.
///
@@ -418,44 +382,6 @@ pub unsafe fn dc_free_splitted_lines(lines: Vec<*mut libc::c_char>) {
}
}
/* insert a break every n characters, the return must be free()'d */
#[cfg(test)]
unsafe fn dc_insert_breaks(
in_0: *const libc::c_char,
break_every: libc::c_int,
break_chars: *const libc::c_char,
) -> *mut libc::c_char {
if in_0.is_null() || break_every <= 0 || break_chars.is_null() {
return dc_strdup(in_0);
}
let mut out_len = strlen(in_0);
let mut chars_added = 0;
let break_chars_len = strlen(break_chars);
out_len += (out_len / break_every as usize + 1) * break_chars_len + 1;
let out: *mut libc::c_char = malloc(out_len) as *mut libc::c_char;
if out.is_null() {
return ptr::null_mut();
}
let mut i: *const libc::c_char = in_0;
let mut o: *mut libc::c_char = out;
while 0 != *i {
let fresh1 = o;
o = o.offset(1);
let fresh0 = i;
i = i.offset(1);
*fresh1 = *fresh0;
chars_added += 1;
if chars_added == break_every && 0 != *i as libc::c_int {
strcpy(o, break_chars);
o = o.add(break_chars_len);
chars_added = 0
}
}
*o = 0 as libc::c_char;
out
}
pub unsafe fn dc_str_from_clist(
list: *const clist,
delimiter: *const libc::c_char,
@@ -1636,70 +1562,6 @@ mod tests {
assert_eq!(dc_truncate("123456", 4, true), "123456");
}
#[test]
fn test_dc_insert_breaks_1() {
unsafe {
let str = dc_insert_breaks(
b"just1234test\x00" as *const u8 as *const libc::c_char,
4,
b" \x00" as *const u8 as *const libc::c_char,
);
assert_eq!(
CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(),
"just 1234 test"
);
free(str as *mut libc::c_void);
}
}
#[test]
fn test_dc_insert_breaks_2() {
unsafe {
let str: *mut libc::c_char = dc_insert_breaks(
b"just1234tes\x00" as *const u8 as *const libc::c_char,
4,
b"--\x00" as *const u8 as *const libc::c_char,
);
assert_eq!(
CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(),
"just--1234--tes"
);
free(str as *mut libc::c_void);
}
}
#[test]
fn test_dc_insert_breaks_3() {
unsafe {
let str: *mut libc::c_char = dc_insert_breaks(
b"just1234t\x00" as *const u8 as *const libc::c_char,
4,
b"\x00" as *const u8 as *const libc::c_char,
);
assert_eq!(
CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(),
"just1234t"
);
free(str as *mut libc::c_void);
}
}
#[test]
fn test_dc_insert_breaks_4() {
unsafe {
let str: *mut libc::c_char = dc_insert_breaks(
b"\x00" as *const u8 as *const libc::c_char,
4,
b"---\x00" as *const u8 as *const libc::c_char,
);
assert_eq!(
CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(),
""
);
free(str as *mut libc::c_void);
}
}
#[test]
fn test_dc_null_terminate_1() {
unsafe {
@@ -1797,17 +1659,6 @@ mod tests {
}
}
#[test]
fn test_dc_binary_to_uc_hex() {
let buf = vec![0, 1, 2, 3, 255];
let raw = unsafe { dc_binary_to_uc_hex(buf.as_ptr(), buf.len()) };
let res = to_string(raw);
assert_eq!(res, "00010203FF");
unsafe { free(raw as *mut _) };
}
#[test]
fn test_dc_replace_bad_utf8_chars_1() {
unsafe {
@@ -1891,20 +1742,6 @@ mod tests {
);
}
#[test]
fn test_dc_utf8_strlen() {
unsafe {
assert_eq!(
dc_utf8_strlen(b"c\x00" as *const u8 as *const libc::c_char),
1
);
assert_eq!(
dc_utf8_strlen(b"\xc3\xa4\x00" as *const u8 as *const libc::c_char),
1
);
}
}
#[test]
fn test_os_str_to_c_string_cwd() {
let some_dir = std::env::current_dir().unwrap();