Function parse

Source
pub fn parse(integer: &str) -> Result<i64, ParseEndfIntegerError>
Expand description

Parse ENDF integer.

§Format

ENDF integers can be read with FORTRAN77 I11 format specification.

ENDF integers have the following format: ±nnnnnnnnnn with:

  • zero or more leading blanks followed by
  • a leading sign '-' or '+' for negative or positive respectively (positive sign is optional)
  • n a digit between 0 and 9
  • full integer length is less than or equal to 11

§Preconditions

Following preconditions must hold or a ParseEndfIntegerError is returned:

  • integer is ASCII
  • integer is not empty
  • integer is not blank (combination of chars: ' ', '\t', '\n' and '\r')
  • integer is included in [ -9_999_999_999; +9_999_999_999 ]
  • integer length is less than or equal to 11
  • integer respect the ENDF integer format (see Format)

§Examples

§From &str

let x = endf_parser::primitive::integer::parse("1");
assert_eq!(1, x.unwrap());
let x = endf_parser::primitive::integer::parse("-1");
assert_eq!(-1, x.unwrap());
let x = endf_parser::primitive::integer::parse("+1");
assert_eq!(1, x.unwrap());
let x = endf_parser::primitive::integer::parse("+1234567890");
assert_eq!(1_234_567_890, x.unwrap());

§From String

let x = endf_parser::primitive::integer::parse(&String::from("+1234567890")[..]);
assert_eq!(1_234_567_890, x.unwrap())

§Errors

If parsing fails, ParseEndfIntegerError is returned.

§Regex

The input integer can be tested with the ENDF_INTEGER_REGEX regex.

§Reference

ENDF integer format is described in section 0.6.2 of ENDF-6 Formats Manual