mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-29 16:40:05 +08:00
fix parse_size
This commit is contained in:
@@ -154,8 +154,11 @@ pub fn print_lastline(line: &str) {
|
|||||||
|
|
||||||
pub fn parse_size(size: &str) -> XResult<i64> {
|
pub fn parse_size(size: &str) -> XResult<i64> {
|
||||||
let lower_size = size.to_lowercase();
|
let lower_size = size.to_lowercase();
|
||||||
if lower_size.ends_with("b") {
|
let no_last_b_size = if lower_size.ends_with("b") {
|
||||||
let no_last_b_size = &lower_size[0..lower_size.len()-1];
|
&lower_size[0..lower_size.len()-1]
|
||||||
|
} else {
|
||||||
|
&lower_size
|
||||||
|
};
|
||||||
if no_last_b_size.ends_with("k") {
|
if no_last_b_size.ends_with("k") {
|
||||||
return Ok((SIZE_KB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
|
return Ok((SIZE_KB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
|
||||||
} else if no_last_b_size.ends_with("m") {
|
} else if no_last_b_size.ends_with("m") {
|
||||||
@@ -167,7 +170,6 @@ pub fn parse_size(size: &str) -> XResult<i64> {
|
|||||||
} else if no_last_b_size.ends_with("p") {
|
} else if no_last_b_size.ends_with("p") {
|
||||||
return Ok((SIZE_PB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
|
return Ok((SIZE_PB as f64 * no_last_b_size[0..no_last_b_size.len()-1].parse::<f64>()?) as i64);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Err(new_box_error(&format!("Cannot parse size: {}", size)))
|
Err(new_box_error(&format!("Cannot parse size: {}", size)))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user