coded_chars/
shifts.rs

1//! All 7-bits and 8-bits shifts. 
2
3use crate::escape::{escape, EscapeSequence};
4
5/// # Shift in
6///
7/// SI is used for code extension purposes. It causes the meanings of the bit combinations following it in the
8/// data stream to be changed.  
9/// The use of SI is defined in Standard ECMA-35.
10///
11/// ### Note
12///
13/// SI is used in 7-bit environments only; in 8-bit environments LOCKING-SHIFT ZERO (LS0) is used
14/// instead.
15pub const SI: char = '\x0F';
16pub const LS0: char = SI;
17
18/// # Shift out
19///
20/// SO is used for code extension purposes. It causes the meanings of the bit combinations following it in
21/// the data stream to be changed.  
22/// The use of SO is defined in Standard ECMA-35.
23///
24/// ### Note
25///
26/// SO is used in 7-bit environments only; in 8-bit environments LOCKING-SHIFT ONE (LS1) is used
27/// instead.
28pub const SO: char = '\x0E';
29pub const LS1: char = SO;
30
31/// Locking-shift 1R
32pub const LS1R: EscapeSequence = escape('~');
33
34/// Locking-shift 2
35pub const LS2: EscapeSequence = escape('n');
36
37/// Locking-shift 2R
38pub const LS2R: EscapeSequence = escape('}');
39
40/// Locking-shift 3
41pub const LS3: EscapeSequence = escape('o');
42
43/// Locking-shift 3R
44pub const LS3R: EscapeSequence = escape('|');
45
46/// Single shift 2
47pub const SS2: EscapeSequence = escape('N');
48
49/// Single shift 3
50pub const SS3: EscapeSequence = escape('O');
51
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_si_constant() {
59        assert_eq!(SI, '\x0F');
60    }
61
62    #[test]
63    fn test_ls0_constant() {
64        assert_eq!(LS0, SI);
65    }
66
67    #[test]
68    fn test_so_constant() {
69        assert_eq!(SO, '\x0E');
70    }
71
72    #[test]
73    fn test_ls1_constant() {
74        assert_eq!(LS1, SO);
75    }
76
77    #[test]
78    fn test_ls1r_escape_sequence() {
79        assert_eq!(LS1R, escape('~'));
80    }
81
82    #[test]
83    fn test_ls2_escape_sequence() {
84        assert_eq!(LS2, escape('n'));
85    }
86
87    #[test]
88    fn test_ls2r_escape_sequence() {
89        assert_eq!(LS2R, escape('}'));
90    }
91
92    #[test]
93    fn test_ls3_escape_sequence() {
94        assert_eq!(LS3, escape('o'));
95    }
96
97    #[test]
98    fn test_ls3r_escape_sequence() {
99        assert_eq!(LS3R, escape('|'));
100    }
101
102    #[test]
103    fn test_ss2_escape_sequence() {
104        assert_eq!(SS2, escape('N'));
105    }
106
107    #[test]
108    fn test_ss3_escape_sequence() {
109        assert_eq!(SS3, escape('O'));
110    }
111}