pub fn dupstring(s: &str) -> String {
s.to_string()
}
pub fn dupstring_wlen(s: &str, len: usize) -> String {
s[..len.min(s.len())].to_string()
}
pub fn ztrdup(s: &str) -> String {
s.to_string()
}
pub fn wcs_ztrdup(s: &str) -> String {
s.to_string()
}
pub fn tricat(s1: &str, s2: &str, s3: &str) -> String {
let mut result = String::with_capacity(s1.len() + s2.len() + s3.len());
result.push_str(s1);
result.push_str(s2);
result.push_str(s3);
result
}
pub fn zhtricat(s1: &str, s2: &str, s3: &str) -> String {
tricat(s1, s2, s3)
}
pub fn dyncat(s1: &str, s2: &str) -> String {
format!("{}{}", s1, s2)
}
pub fn bicat(s1: &str, s2: &str) -> String {
format!("{}{}", s1, s2)
}
pub fn dupstrpfx(s: &str, len: usize) -> String {
s[..len.min(s.len())].to_string()
}
pub fn ztrduppfx(s: &str, len: usize) -> String {
dupstrpfx(s, len)
}
pub fn appstr(base: &mut String, append: &str) {
base.push_str(append);
}
pub fn strend(s: &str) -> Option<char> {
s.chars().next_back()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_dupstring() {
assert_eq!(dupstring("hello"), "hello");
}
#[test]
fn test_dupstring_wlen() {
assert_eq!(dupstring_wlen("hello world", 5), "hello");
}
#[test]
fn test_tricat() {
assert_eq!(tricat("a", "b", "c"), "abc");
}
#[test]
fn test_bicat() {
assert_eq!(bicat("hello", " world"), "hello world");
}
#[test]
fn test_dyncat() {
assert_eq!(dyncat("foo", "bar"), "foobar");
}
#[test]
fn test_appstr() {
let mut s = "hello".to_string();
appstr(&mut s, " world");
assert_eq!(s, "hello world");
}
#[test]
fn test_strend() {
assert_eq!(strend("hello"), Some('o'));
assert_eq!(strend(""), None);
}
#[test]
fn test_dupstrpfx() {
assert_eq!(dupstrpfx("hello world", 5), "hello");
}
}