Core Function StrVersCmp
m (1 revision) |
(→Return Value) |
||
Line 35: | Line 35: | ||
=== Return Value === | === Return Value === | ||
− | + | Returns an integer less than, equal to, or greater than zero if str1 is found, respectively, to be earlier than, equal to, or later than str2. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
=== Remarks === | === Remarks === |
Revision as of 18:30, 19 September 2015
StrVersCmp( <str1>, <str2>, <ignoreCase> )
Contents |
Description
String comparison holding name and indices/version numbers.
The strversmp() function shall compare two strings in a similar manner to strcmp(). If s1 and s2 contain no digits, strversmp() shall behave as strcmp().
The strings are compared by scanning from left to right. If a digit or sequence of digits is encountered in both strings at the same position, the digit sequence is specially compared, as described below. If the digit sequences compared equal, the string comparison resumes in both s1 and s2 after the digit sequence.
Digit sequences are classified as either "integral" or "fractional". A fractional digit sequence begins with a '0'; otherwise the digit sequence shall be treated as an integral digit sequence.
If two integral digit sequences are encountered, they shall be compared as integers for equality. A fractional digit sequence shall always compare less than an integral digit sequence. If two fractional digit sequences are being compared, then if the common prefix contains only leading zeroes, the longer part shall compare less than the shorter; otherwise the comparison shall be strictly numeric.
Parameters
str1
The first string.
str2
The second string.
ignoreCase
Optional; Do case insensitive match
true = Ignore case and match case insensitively
false = Case must be an exact match
Return Value
Returns an integer less than, equal to, or greater than zero if str1 is found, respectively, to be earlier than, equal to, or later than str2.
Remarks
None.
Example
say strverscmp( "no digit", "no digit"); // 0 /* same behavior as strcmp */ say strverscmp( "item#99", "item#100"); // < 0 /* same prefix, but 99 < 100 */ say strverscmp( "alpha1", "alpha001"); // > 0 /* fractional part inferior to integral */ say strverscmp( "part1_f012", "part1_f01"); // > 0 /* two fractional parts */ say strverscmp( "foo.009", "foo.0"); // < 0 /* two fractional parts but with leading zeroes only */