example utils: improve types
This commit is contained in:
parent
1448f31cf4
commit
042fc6353c
4 changed files with 86 additions and 77 deletions
math/str2int/src
|
@ -10,31 +10,51 @@ fn main() {
|
|||
eprintln!(" Parse MachineInt from String");
|
||||
nested::magic_header();
|
||||
|
||||
let mut f0 = unsafe { File::from_raw_fd(0) };
|
||||
eprintln!("
|
||||
> 0:
|
||||
$1: radix
|
||||
( ℕ )
|
||||
( Sequence (Digit 10) )
|
||||
( Sequence ASCII )
|
||||
( Sequence MachineSlab )
|
||||
( Pipe Shot (Sequence MachineSlab) )
|
||||
( PositionalInt 10 BigEndian )
|
||||
( Sequence ( Digit 10 ) )
|
||||
( Sequence UTF-8-Char )
|
||||
( Sequence MachineSyllab )
|
||||
");
|
||||
|
||||
let mut f1 = unsafe { File::from_raw_fd(1) };
|
||||
eprintln!("
|
||||
< 1:
|
||||
>0: n
|
||||
( ℕ )
|
||||
( PositionalInt $radix BigEndian )
|
||||
( Sequence ( Digit $radix ) )
|
||||
( Sequence UTF-8-Char )
|
||||
( Stream UTF-8-Char )
|
||||
( Stream MachineSyllab )
|
||||
");
|
||||
|
||||
eprintln!("
|
||||
<1: n
|
||||
( ℕ )
|
||||
( MachineInt )
|
||||
( MachineWord )
|
||||
( Array 8 MachineSlab )
|
||||
( Pipe Shot (Array 8 MachineSlab) )
|
||||
( Stream MachineSyllab )
|
||||
");
|
||||
|
||||
nested::magic_header();
|
||||
|
||||
let mut f0 = unsafe { File::from_raw_fd(0) };
|
||||
let mut f1 = unsafe { File::from_raw_fd(1) };
|
||||
|
||||
let mut args = std::env::args();
|
||||
args.next().expect("Arg $0 missing!");
|
||||
|
||||
let radix_str = args.next().expect("Arg $1 required!");
|
||||
|
||||
let radix = u32::from_str_radix(&radix_str, 10).expect("could not parse radix");
|
||||
if radix > 16 {
|
||||
panic!("invalid radix! (radix<=16 required)");
|
||||
}
|
||||
|
||||
let mut chars = Vec::new();
|
||||
f0.read_to_end(&mut chars);
|
||||
chars.retain(|c| (*c as char).is_numeric());
|
||||
f1.write(&u64::from_str_radix(&String::from_utf8_lossy(&chars), 10).unwrap().to_le_bytes());
|
||||
chars.retain(|c| (*c as char).is_alphanumeric());
|
||||
f1.write(&u64::from_str_radix(&String::from_utf8_lossy(&chars), radix).unwrap().to_le_bytes());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue