Function uu_numfmt::extract_field[][src]

pub fn extract_field(line: &str) -> Result<(&str, &str, &str), String>

Extract the field to convert from line.

The field is the first sequence of non-whitespace characters in line.

Returns a [Result] of (prefix: &str, field: &str, suffix: &str), where prefix contains any leading whitespace, field is the field to convert, and suffix is everything after the field. prefix and suffix may be empty.

Returns an Err if line is empty or consists only of whitespace.

Examples:

use uu_numfmt::extract_field;

assert_eq!("1K", extract_field("1K").unwrap().1);

let (prefix, field, suffix) = extract_field("   1K qux").unwrap();
assert_eq!("   ", prefix);
assert_eq!("1K", field);
assert_eq!(" qux", suffix);

assert!(extract_field("").is_err());