control_code/csi/
tabulation.rs

1//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2//                    Version 2, December 2004
3//
4// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
5//
6// Everyone is permitted to copy and distribute verbatim or modified
7// copies of this license document, and changing it is allowed as long
8// as the name is changed.
9//
10//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12//
13//  0. You just DO WHAT THE FUCK YOU WANT TO.
14
15use nom;
16
17#[derive(Eq, PartialEq, Copy, Clone, Debug)]
18pub enum Tabulation {
19	Character,
20	Line,
21	Characters,
22	AllCharacters,
23	AllLines,
24	All,
25}
26
27impl Tabulation {
28	#[inline]
29	pub fn parse<'a>(value: u32) -> Result<Self, nom::ErrorKind> {
30		match value {
31			0 => Ok(Tabulation::Character),
32			1 => Ok(Tabulation::Line),
33			2 => Ok(Tabulation::Characters),
34			3 => Ok(Tabulation::AllCharacters),
35			4 => Ok(Tabulation::AllLines),
36			5 => Ok(Tabulation::All),
37			_ => Err(nom::ErrorKind::Custom(9003)),
38		}
39	}
40}
41
42impl Into<u32> for Tabulation {
43	#[inline]
44	fn into(self) -> u32 {
45		match self {
46			Tabulation::Character     => 0,
47			Tabulation::Line          => 1,
48			Tabulation::Characters    => 2,
49			Tabulation::AllCharacters => 3,
50			Tabulation::AllLines      => 4,
51			Tabulation::All           => 5,
52		}
53	}
54}