workflow_terminal/
unicode.rs1#[derive(Default, Debug, Clone)]
2pub struct UnicodeString(pub Vec<char>);
3
4impl std::fmt::Display for UnicodeString {
5 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6 let s: String = self.0.iter().collect();
7 write!(f, "{}", s)
8 }
9}
10
11impl UnicodeString {
12 pub fn clear(&mut self) {
13 self.0.clear();
14 }
15
16 pub fn pop(&mut self) -> Option<char> {
17 self.0.pop()
18 }
19
20 pub fn remove(&mut self, index: usize) -> char {
21 self.0.remove(index)
22 }
23
24 pub fn len(&self) -> usize {
25 self.0.len()
26 }
27
28 pub fn is_empty(&self) -> bool {
29 self.0.is_empty()
30 }
31
32 pub fn is_not_empty(&self) -> bool {
33 !self.0.is_empty()
34 }
35
36 pub fn push(&mut self, c: char) {
37 self.0.push(c);
38 }
39
40 pub fn insert_char(&mut self, index: usize, c: char) {
41 self.0.insert(index, c);
42 }
43
44 pub fn insert(&mut self, index: usize, us: UnicodeString) {
45 self.0.splice(index..index, us.0);
46 }
47
48 pub fn extend(&mut self, us: UnicodeString) {
49 self.0.extend(us.0);
50 }
51
52 pub fn iter(&self) -> impl Iterator<Item = &char> {
53 self.0.iter()
54 }
55}
56
57impl From<Vec<char>> for UnicodeString {
58 fn from(v: Vec<char>) -> Self {
59 Self(v)
60 }
61}
62
63impl From<&[char]> for UnicodeString {
64 fn from(v: &[char]) -> Self {
65 Self(v.to_vec())
66 }
67}
68
69impl From<&str> for UnicodeString {
70 fn from(s: &str) -> Self {
71 Self(s.chars().collect())
72 }
73}
74
75impl From<String> for UnicodeString {
76 fn from(s: String) -> Self {
77 Self(s.chars().collect())
78 }
79}