Whether arg is a negative number rather than an option.
Only the shape is tested, not whether it parses: -5, -1.5 and
-.5 are numbers, -s and -verbose are not. Getting this wrong in
the permissive direction would let a mistyped option through as a
positional, which is the bug this guards.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | arg |
Token to classify; known to start with |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=1), | private | :: | c |
pure function looks_numeric(arg) result(r) !! Whether `arg` is a negative number rather than an option. !! !! Only the shape is tested, not whether it parses: `-5`, `-1.5` and !! `-.5` are numbers, `-s` and `-verbose` are not. Getting this wrong in !! the permissive direction would let a mistyped option through as a !! positional, which is the bug this guards. character(len=*), intent(in) :: arg !! Token to classify; known to start with `-` and be longer than one. logical :: r character(len=1) :: c r = .false. c = arg(2:2) if (c >= "0" .and. c <= "9") then r = .true. else if (c == "." .and. len(arg) > 2) then c = arg(3:3) r = c >= "0" .and. c <= "9" end if end function looks_numeric