1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::num::ParseIntError;
#[cfg(test)]
#[path = "./string_test.rs"]
mod string_test;
pub fn right_pad(s: &str, len: usize) -> String {
let mut res = String::new();
res.push_str(s);
if s.len() < len {
let padding_len = len - s.len();
for _ in 0..padding_len {
res.push_str(" ");
}
}
res
}
pub fn parse_number_string(s: &str) -> Result<u32, ParseIntError> {
let x = &s.replace("_", "");
if x.len() >= 2 && &x[0..2] == "0x" {
u32::from_str_radix(&x[2..], 16)
} else {
x.parse::<u32>()
}
}