Add U+dec and U+hex columns
This commit is contained in:
parent
1961443d1e
commit
dc87816baf
20
src/main.rs
20
src/main.rs
@ -11,8 +11,9 @@ struct StringDetail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct CharacterDetail {
|
struct CharacterDetail {
|
||||||
byte_index: usize,
|
|
||||||
character: Option<char>,
|
character: Option<char>,
|
||||||
|
unicode: Option<u32>,
|
||||||
|
byte_index: usize,
|
||||||
byte: u8,
|
byte: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ impl StringDetail{
|
|||||||
.push(CharacterDetail {
|
.push(CharacterDetail {
|
||||||
byte_index: self.len,
|
byte_index: self.len,
|
||||||
character,
|
character,
|
||||||
|
unicode: character.map(|c| c as u32),
|
||||||
byte,
|
byte,
|
||||||
});
|
});
|
||||||
self.len += 1;
|
self.len += 1;
|
||||||
@ -69,10 +71,22 @@ impl StringDetail{
|
|||||||
fn to_table_row(char_detail: &CharacterDetail) -> Vec<String> {
|
fn to_table_row(char_detail: &CharacterDetail) -> Vec<String> {
|
||||||
let character: String = match char_detail.character {
|
let character: String = match char_detail.character {
|
||||||
Some(x) => String::from(format!("{}", x)),
|
Some(x) => String::from(format!("{}", x)),
|
||||||
None => String::from("<..>"),
|
None => String::from("<->"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let unicode: String = match char_detail.unicode {
|
||||||
|
Some(x) => String::from(format!("{}", x)),
|
||||||
|
None => String::from("<->"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let unicode_hex: String = match char_detail.unicode {
|
||||||
|
Some(x) => String::from(format!("{:x}", x)),
|
||||||
|
None => String::from("<->"),
|
||||||
};
|
};
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
|
unicode,
|
||||||
|
unicode_hex,
|
||||||
character,
|
character,
|
||||||
format!("{}", char_detail.byte_index),
|
format!("{}", char_detail.byte_index),
|
||||||
format!("{:02x}", char_detail.byte),
|
format!("{:02x}", char_detail.byte),
|
||||||
@ -82,6 +96,8 @@ impl StringDetail{
|
|||||||
|
|
||||||
fn table_header() -> Vec<String> {
|
fn table_header() -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
|
String::from("U+dec"),
|
||||||
|
String::from("U+hex"),
|
||||||
String::from("character"),
|
String::from("character"),
|
||||||
String::from("byte"),
|
String::from("byte"),
|
||||||
String::from("hex"),
|
String::from("hex"),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user