arr_rs/alphanumeric/types/
char.rs1use crate::{
2 alphanumeric::prelude::*,
3 core::prelude::*,
4};
5use crate::prelude::Numeric;
6
7impl ArrayElement for char {
8
9 fn zero() -> Self {
10 '0'
11 }
12
13 fn one() -> Self {
14 '1'
15 }
16
17 fn is_nan(&self) -> bool {
18 false
19 }
20}
21
22impl Alphanumeric for char {
23
24 fn from_str(str: &str) -> Self {
25 str.chars().next().unwrap_or('0')
26 }
27
28 fn _append(&self, _: Self) -> Self {
29 *self
30 }
31
32 fn _multiply(&self, _: usize) -> Self {
33 *self
34 }
35
36 fn _capitalize(&self) -> Self {
37 self.to_string()._capitalize().chars().next().unwrap_or('0')
38 }
39
40 fn _lower(&self) -> Self {
41 self.to_string()._lower().chars().next().unwrap_or('0')
42 }
43
44 fn _upper(&self) -> Self {
45 self.to_string()._upper().chars().next().unwrap_or('0')
46 }
47
48 fn _swapcase(&self) -> Self {
49 self.to_string()._swapcase().chars().next().unwrap_or('0')
50 }
51
52 fn _center(&self, _: usize, _: char) -> Self {
53 *self
54 }
55
56 fn _join(&self, _: Self) -> Self {
57 *self
58 }
59
60 fn _partition(&self, sep: Self) -> Tuple3<Self, Self, Self> {
61 Tuple3(*self, sep, ' ')
62 }
63
64 fn _rpartition(&self, sep: Self) -> Tuple3<Self, Self, Self> {
65 Tuple3(*self, sep, ' ')
66 }
67
68 fn _split(&self, sep: Self, _: Option<usize>) -> List<Self> {
69 List(vec![*self, sep, ' '])
70 }
71
72 fn _rsplit(&self, sep: Self, _: Option<usize>) -> List<Self> {
73 List(vec![' ', sep, *self])
74 }
75
76 fn _splitlines(&self, _: bool) -> List<Self> {
77 List(vec![*self])
78 }
79
80 fn _replace(&self, old: Self, new: Self, _: Option<usize>) -> Self {
81 if *self == old { new }
82 else { old }
83 }
84
85 fn _strip(&self, chars: Self) -> Self {
86 if *self == chars { ' ' }
87 else { *self }
88 }
89
90 fn _ljust(&self, _: usize, _: char) -> Self {
91 *self
92 }
93
94 fn _lstrip(&self, chars: Self) -> Self {
95 if *self == chars { ' ' }
96 else { *self }
97 }
98
99 fn _rjust(&self, _: usize, _: char) -> Self {
100 *self
101 }
102
103 fn _rstrip(&self, chars: Self) -> Self {
104 if *self == chars { ' ' }
105 else { *self }
106 }
107
108 fn _equal(&self, other: Self) -> bool {
109 *self == other
110 }
111
112 fn _not_equal(&self, other: Self) -> bool {
113 !self._equal(other)
114 }
115
116 fn _greater_equal(&self, other: Self) -> bool {
117 *self >= other
118 }
119
120 fn _less_equal(&self, other: Self) -> bool {
121 *self <= other
122 }
123
124 fn _greater(&self, other: Self) -> bool {
125 *self > other
126 }
127
128 fn _less(&self, other: Self) -> bool {
129 *self < other
130 }
131
132 fn _count(&self, sub: &str) -> usize {
133 (*self == sub.chars().next().unwrap_or(' ')).to_usize()
134 }
135}