| 1 | pub(crate) fn is_number(text: &str) -> bool { |
| 2 | text.parse::<usize>().is_ok() || text.parse::<isize>().is_ok() || text.parse::<f64>().is_ok() |
| 3 | } |
| 4 | |
| 5 | pub(crate) fn is_number_and_positive(text: &str) -> bool { |
| 6 | if text.parse::<usize>().is_ok() { |
| 7 | true |
| 8 | } else if let Ok(num) = text.parse::<isize>() { |
| 9 | num.is_positive() |
| 10 | } else if let Ok(num) = text.parse::<f64>() { |
| 11 | num.is_sign_positive() |
| 12 | } else { |
| 13 | false |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | pub(crate) fn usize_token(spec: &str, match_index: usize) -> Option<usize> { |
| 18 | let mut token = None; |
| 19 | let mut token_index = match_index + 1; |
| 20 | |
| 21 | while let Ok(token_suffixed) = spec |
| 22 | .get(match_index..token_index) |
| 23 | .unwrap_or("null") |
| 24 | .parse::<usize>() |
| 25 | { |
| 26 | token = Some(token_suffixed); |
| 27 | token_index += 1; |
| 28 | } |
| 29 | |
| 30 | token |
| 31 | } |