Struct brainfoamkit_lib::AsciiChar
source · pub struct AsciiChar { /* private fields */ }
Expand description
A struct representing an ASCII character.
This struct is used to represent an ASCII character in terms of a
Byte
value. This struct allows for interrogating the
character in terms of its binary, decimal, and hexadecimal values, as well
as its character code, character description, and character value.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.binary_value(), Byte::from(97));
assert_eq!(ascii_char.decimal_value(), 97);
assert_eq!(ascii_char.hexadecimal_value(), "0x61");
assert_eq!(ascii_char.character_code(), "LCA");
assert_eq!(ascii_char.character_description(), "Lowercase letter a");
assert_eq!(ascii_char.character_value(), "a");
ASCII Character Types
The following ASCII character types are available:
- Control characters
- Printable characters
- Whitespace characters
- Digit characters
- Letter characters
- Uppercase characters
- Lowercase characters
- Symbol characters
ASCII Character Type Examples
Control Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(0), "NUL", "Null character", "\0");
assert_eq!(ascii_char.is_control(), true);
Printable Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.is_printable(), true);
Whitespace Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(9), "CTAB", "Horizontal tab", "\t");
assert_eq!(ascii_char.is_whitespace(), true);
Digit Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");
assert_eq!(ascii_char.is_digit(), true);
Letter Characters
Uppercase Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");
assert_eq!(ascii_char.is_uppercase(), true);
assert_eq!(ascii_char.is_lowercase(), false);
assert_eq!(ascii_char.is_letter(), true);
Lowercase Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.is_lowercase(), true);
assert_eq!(ascii_char.is_uppercase(), false);
assert_eq!(ascii_char.is_letter(), true);
Symbol Characters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(64), "AT", "At Symbol", "@");
assert_eq!(ascii_char.is_symbol(), true);
References
Implementations§
source§impl AsciiChar
impl AsciiChar
sourcepub fn new(
byte: Byte,
character_code: &str,
character_description: &str,
character_value: &str
) -> Self
pub fn new( byte: Byte, character_code: &str, character_description: &str, character_value: &str ) -> Self
Create a new AsciiChar
instance.
This function creates a new AsciiChar
instance from the given
Byte
value, character code, character
description, and character value.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.binary_value(), Byte::from(97));
assert_eq!(ascii_char.decimal_value(), 97);
assert_eq!(ascii_char.hexadecimal_value(), "0x61");
assert_eq!(ascii_char.character_code(), "LCA");
assert_eq!(ascii_char.character_description(), "Lowercase letter a");
sourcepub fn is_control(&self) -> bool
pub fn is_control(&self) -> bool
Returns true
if the AsciiChar
instance is a control character.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(0), "NUL", "Null character", "\0");
assert_eq!(ascii_char.is_control(), true);
Control Characters
- NUL (Null character)
- SOH (Start of heading)
- STX (Start of text)
- ETX (End of text)
- EOT (End of transmission)
- ENQ (Enquiry)
- ACK (Acknowledgement)
- BEL (Bell)
- BS (Backspace)
- HT (Horizontal tab)
- LF (Line feed)
- VT (Vertical tab)
- FF (Form feed)
- CR (Carriage return)
- SO (Shift out)
- SI (Shift in)
- DLE (Data link escape)
- DC1 (Device control 1)
- DC2 (Device control 2)
- DC3 (Device control 3)
- DC4 (Device control 4)
- NAK (Negative acknowledgement)
- SYN (Synchronous idle)
- ETB (End of transmission block)
- CAN (Cancel)
- EM (End of medium)
- SUB (Substitute)
- ESC (Escape)
- FS (File separator)
- GS (Group separator)
- RS (Record separator)
- US (Unit separator)
- DEL (Delete)
References
sourcepub fn is_printable(&self) -> bool
pub fn is_printable(&self) -> bool
Returns true
if the AsciiChar
instance is a printable character.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let lca: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
let uca: AsciiChar =
AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");
let symat: AsciiChar =
AsciiChar::new(Byte::from(64), "SYMAT", "Symbol At", "@");
let dig1: AsciiChar =
AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");
let sp: AsciiChar = AsciiChar::new(Byte::from(32), "SP", "Space", " ");
assert_eq!(lca.is_printable(), true);
assert_eq!(uca.is_printable(), true);
assert_eq!(symat.is_printable(), true);
assert_eq!(dig1.is_printable(), true);
assert_eq!(sp.is_printable(), true);
Printable Characters
- All uppercase letters
- All lowercase letters
- All digit characters
- All symbol characters
- All whitespace characters
References
sourcepub fn is_whitespace(&self) -> bool
pub fn is_whitespace(&self) -> bool
Returns true
if the AsciiChar
instance is a whitespace character.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(9), "CTAB", "Horizontal tab", "\t");
assert_eq!(ascii_char.is_whitespace(), true);
Whitespace Characters
- SP (Space)
- HT (Horizontal tab)
- LF (Line feed)
- VT (Vertical tab)
- FF (Form feed)
- CR (Carriage return)
References
sourcepub fn is_digit(&self) -> bool
pub fn is_digit(&self) -> bool
Returns true
if the AsciiChar
instance is a digit character.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(49), "DIG1", "Digit one", "1");
assert_eq!(ascii_char.is_digit(), true);
Digit Characters
- All digit characters from 0 to 9
References
sourcepub fn is_letter(&self) -> bool
pub fn is_letter(&self) -> bool
Returns true
if the AsciiChar
instance is a letter character.
Examples
Lowercase Letters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.is_letter(), true);
Uppercase Letters
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let lca: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
let uca: AsciiChar =
AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter a", "A");
assert_eq!(lca.is_letter(), true);
assert_eq!(uca.is_letter(), true);
Letter Characters
References
sourcepub fn is_uppercase(&self) -> bool
pub fn is_uppercase(&self) -> bool
Returns true
if the AsciiChar
instance is an uppercase letter
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(65), "UCA", "Uppercase letter A", "A");
assert_eq!(ascii_char.is_uppercase(), true);
Uppercase Letters
- All uppercase letters from A to Z
References
sourcepub fn is_lowercase(&self) -> bool
pub fn is_lowercase(&self) -> bool
Returns true
if the AsciiChar
instance is a lowercase letter
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.is_lowercase(), true);
Lowercase Letters
- All lowercase letters from a to z
References
sourcepub fn is_symbol(&self) -> bool
pub fn is_symbol(&self) -> bool
Returns true
if the AsciiChar
instance is a symbol character.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(64), "SYMAT", "Symbol at", "@");
assert_eq!(ascii_char.is_symbol(), true);
Symbol Characters
- All symbol characters from ! to /
- All symbol characters from : to @
- All symbol characters from [ to `
- All symbol characters from { to ~
References
sourcepub const fn binary_value(&self) -> Byte
pub const fn binary_value(&self) -> Byte
Returns the AsciiChar
instance’s binary value.
This function returns the AsciiChar
instance’s binary value as a
Byte
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.binary_value(), Byte::from(97));
sourcepub fn decimal_value(&self) -> u8
pub fn decimal_value(&self) -> u8
Returns the AsciiChar
instance’s decimal value.
This function returns the AsciiChar
instance’s decimal value as a
u8
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.decimal_value(), 97);
sourcepub fn hexadecimal_value(&self) -> String
pub fn hexadecimal_value(&self) -> String
Returns the AsciiChar
instance’s hexadecimal value.
This function returns the AsciiChar
instance’s hexadecimal value as a
String
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.hexadecimal_value(), "0x61");
sourcepub fn character_code(&self) -> String
pub fn character_code(&self) -> String
Returns the AsciiChar
instance’s character code.
This function returns the AsciiChar
instance’s character code as a
String
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.character_code(), "LCA");
sourcepub fn character_description(&self) -> String
pub fn character_description(&self) -> String
Returns the AsciiChar
instance’s character description.
This function returns the AsciiChar
instance’s character description
as a String
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.character_description(), "Lowercase letter a");
sourcepub fn character_value(&self) -> String
pub fn character_value(&self) -> String
Returns the AsciiChar
instance’s character value.
This function returns the AsciiChar
instance’s character value as a
String
.
Examples
use brainfoamkit_lib::{
AsciiChar,
Byte,
};
let ascii_char: AsciiChar =
AsciiChar::new(Byte::from(97), "LCA", "Lowercase letter a", "a");
assert_eq!(ascii_char.character_value(), "a");