1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#[derive(Default, Debug, Clone)]
pub struct UnicodeString(pub Vec<char>);

impl std::fmt::Display for UnicodeString {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s: String = self.0.iter().collect();
        write!(f, "{}", s)
    }
}

impl UnicodeString {
    pub fn clear(&mut self) {
        self.0.clear();
    }

    pub fn pop(&mut self) -> Option<char> {
        self.0.pop()
    }

    pub fn remove(&mut self, index: usize) -> char {
        self.0.remove(index)
    }

    pub fn len(&self) -> usize {
        self.0.len()
    }

    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    pub fn is_not_empty(&self) -> bool {
        !self.0.is_empty()
    }

    pub fn push(&mut self, c: char) {
        self.0.push(c);
    }

    pub fn insert_char(&mut self, index: usize, c: char) {
        self.0.insert(index, c);
    }

    pub fn insert(&mut self, index: usize, us: UnicodeString) {
        self.0.splice(index..index, us.0);
    }

    pub fn extend(&mut self, us: UnicodeString) {
        self.0.extend(us.0);
    }

    pub fn iter(&self) -> impl Iterator<Item = &char> {
        self.0.iter()
    }
}

impl From<Vec<char>> for UnicodeString {
    fn from(v: Vec<char>) -> Self {
        Self(v)
    }
}

impl From<&[char]> for UnicodeString {
    fn from(v: &[char]) -> Self {
        Self(v.to_vec())
    }
}

impl From<&str> for UnicodeString {
    fn from(s: &str) -> Self {
        Self(s.chars().collect())
    }
}

impl From<String> for UnicodeString {
    fn from(s: String) -> Self {
        Self(s.chars().collect())
    }
}