[−][src]Trait ptero::method::trailing_unicode::UnicodeSet
This trait is used for reading unicode set data.
New sets should implement get_set which provides the array with
unicode characters used by the method.
Required methods
pub fn get_set(&self) -> &[char][src]
Returns the array of characters representing the Unicode characters that should be used by the method. The size of the array should be a power od 2. This is a requirement to be able to encode integer amount of bits.
Provided methods
pub fn size(&self) -> usize[src]
pub fn get_character(&self, index: u32) -> Option<&char>[src]
Maps index (in other words, the value) to the character in the set.
Arguments
index- the value which will be mapped (i.e. index of the character in the set)
Examples
Gets character which is in the set
use ptero::method::trailing_unicode::{UnicodeSet, FullUnicodeSet}; let set = FullUnicodeSet; assert_eq!(set.get_character(1), Some(&'\u{0020}')); assert_eq!(set.get_character(2), Some(&'\u{2000}')); assert_eq!(set.get_character(31), Some(&'\u{FEFF}'));
Returns None if value cannot be mapped
use ptero::method::trailing_unicode::{UnicodeSet, FullUnicodeSet}; let set = FullUnicodeSet; assert_eq!(set.get_character(0), None);
Panics
The method panics if the provided value is larger than the set size.
Panics if index exceeds the size of the set
ⓘ
use ptero::method::trailing_unicode::{UnicodeSet, FullUnicodeSet}; let set = FullUnicodeSet; set.get_character(100);
pub fn character_to_bits(&self, chr: &char) -> u32[src]
Returns the number represented by the character. The number is the bit representation of the character - or in other words the index. If the character is not recognized it returns 0 by default.
Arguments
chr- character which will be converted
Examples
Converts recognized character
use ptero::method::trailing_unicode::{UnicodeSet, FullUnicodeSet}; let set = FullUnicodeSet {}; let value = set.character_to_bits(&'\u{200A}'); assert_eq!(value, 11);
Converts unrecognized character to 0
use ptero::method::trailing_unicode::{UnicodeSet, FullUnicodeSet}; let set = FullUnicodeSet {}; let value = set.character_to_bits(&'A'); assert_eq!(value, 0);