This module, fnNumberStringUtil
contains procedures for validating and comparing numerical strings.
For comparing numerical strings, this module has some very powerful and flexible procedures that can compare numerical strings of unlimited length. These procedures, assumeCompare, assumeCompareAllBase, fnStringCompare, and fnStringCompareAsBase can compare numerical strings without needing to parse the strings to values of a data type. Under the best case scenario, the mentioned procedures can be extremely fast.
Note
Unless stated otherwise, procedures of this module are pure procedures.
Uses
Functions
public pure function isInteger(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid signed decimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isUnsignedInteger(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid unsigned decimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isBinary(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid signed binary integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isUnsignedBinary(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid unsigned binary integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isOctal(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid signed octal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isUnsignedOctal(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid unsigned octal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isHex(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid signed hexadecimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function isUnsignedHex(input) result(lOut)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid unsigned hexadecimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. |
Return Value logical
public pure function assumeCompare(firstString, secondString) result(int32Out)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Compare two strings with the assumption that both strings are valid decimal integers.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | firstString | A string to be compared to the string | ||
character(len=*), | intent(in) | :: | secondString | A string to be compared to the string |
Return Value integer(kind=k_int32)
public pure function assumeCompareAllBase(firstString, secondString) result(int32Out)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Compare two strings with the assumption that both strings are valid integers of any radix between 2 and 36.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | firstString | A string to be compared to the string | ||
character(len=*), | intent(in) | :: | secondString | A string to be compared to the string |
Return Value integer(kind=k_int32)
Subroutines
public pure subroutine isBase(input, base, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid signed integer string of the numbering system with the radix that is defined by the value of the argument base
.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. | ||
integer(kind=k_int32), | intent(in) | :: | base | An int32 value that define the radix. | ||
logical, | intent(out) | :: | output |
| ||
logical, | intent(out) | :: | error | A value of |
public pure subroutine isUnsignedBase(input, base, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check if the input
string is a valid unsigned integer string of the numbering system with the radix that is defined by the value of the argument base
.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. | ||
integer(kind=k_int32), | intent(in) | :: | base | An int32 value that define the radix. | ||
logical, | intent(out) | :: | output |
| ||
logical, | intent(out) | :: | error | A value of |
public pure subroutine assumeIsOdd(input, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check the input
string to see if it holds an odd value with the assumption that the string is a valid decimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. | ||
logical, | intent(out) | :: | output |
| ||
logical, | intent(out) | :: | error | A value of |
public pure subroutine assumeIsEven(input, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Check the input
string to see if it holds an even value with the assumption that the string is a valid decimal integer string.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | input | A string. | ||
logical, | intent(out) | :: | output |
| ||
logical, | intent(out) | :: | error | A value of |
public pure subroutine fnStringCompare(firstString, secondString, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Compare two strings as decimal integers. This subroutine evaluates both, negative and positive values. There isn't a maximum length for the strings. Nonetheless, the strings can't be empty.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | firstString | A string to be compared to the string | ||
character(len=*), | intent(in) | :: | secondString | A string to be compared to the string | ||
integer(kind=k_int32), | intent(out) | :: | output | An int32 value of 1 if the | ||
integer(kind=k_int32), | intent(out) | :: | error | An int32 value of 0 if no error was encountered. Otherwise, a true error code. |
public pure subroutine fnStringCompareAsBase(firstString, secondString, base, output, error)
- Author
- Khang Hoang Nguyen
- Since
- 1.0.0.f
Compare two strings as integer strings of a numbering system with the radix that is defined by the value of the argument base
. There isn't a maximum length for the strings. Nonetheless, the strings can't be empty.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | firstString | A string to be compared to the string | ||
character(len=*), | intent(in) | :: | secondString | A string to be compared to the string | ||
integer(kind=k_int32), | intent(in) | :: | base | An int32 value that define the radix. | ||
integer(kind=k_int32), | intent(out) | :: | output | An int32 value of 1 if the | ||
integer(kind=k_int32), | intent(out) | :: | error | An int32 value of 0 if no error was encountered. Otherwise, a true error code. |