windjammer_runtime/
strings.rs1pub fn to_upper(s: &str) -> String {
7 s.to_uppercase()
8}
9
10pub fn to_lower(s: &str) -> String {
12 s.to_lowercase()
13}
14
15pub fn trim(s: &str) -> String {
17 s.trim().to_string()
18}
19
20pub fn split(s: &str, delimiter: &str) -> Vec<String> {
22 s.split(delimiter).map(|s| s.to_string()).collect()
23}
24
25pub fn join(parts: &[String], delimiter: &str) -> String {
27 parts.join(delimiter)
28}
29
30pub fn contains(s: &str, substring: &str) -> bool {
32 s.contains(substring)
33}
34
35pub fn starts_with(s: &str, prefix: &str) -> bool {
37 s.starts_with(prefix)
38}
39
40pub fn ends_with(s: &str, suffix: &str) -> bool {
42 s.ends_with(suffix)
43}
44
45pub fn replace(s: &str, from: &str, to: &str) -> String {
47 s.replace(from, to)
48}
49
50pub fn substring(s: &str, start: usize, end: usize) -> String {
52 s.chars()
53 .skip(start)
54 .take(end.saturating_sub(start))
55 .collect()
56}
57
58pub fn len(s: &str) -> usize {
60 s.len()
61}
62
63pub fn is_empty(s: &str) -> bool {
65 s.is_empty()
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_case_conversion() {
74 assert_eq!(to_upper("hello"), "HELLO");
75 assert_eq!(to_lower("WORLD"), "world");
76 }
77
78 #[test]
79 fn test_trim() {
80 assert_eq!(trim(" hello "), "hello");
81 }
82
83 #[test]
84 fn test_split_join() {
85 let parts = split("a,b,c", ",");
86 assert_eq!(parts, vec!["a", "b", "c"]);
87 assert_eq!(join(&parts, "-"), "a-b-c");
88 }
89
90 #[test]
91 fn test_contains() {
92 assert!(contains("hello world", "world"));
93 assert!(!contains("hello", "goodbye"));
94 }
95
96 #[test]
97 fn test_replace() {
98 assert_eq!(replace("hello world", "world", "rust"), "hello rust");
99 }
100}