> zlib vars
Checking for updates (running ZLib ver. : 21)...
_version_zlib => : 22
New Version of ZLib Available: : 22
Group 1 requested, but pattern only has 0 groups (zlib.ash, line 164)
> ash import <zlib.ash>; string test = rnum(12.2548,2); print(test)
Value expected (zlib.ash, line 90)
Returned: void
> ash import <zlib.ash>; string test = rnum(12.2548,2); print(test)
_version_zlib => : 22
12.25
Returned: void
normalized("panda, cove, giant","list of location")
// returns "Pandamonium Slums, Pirate Cove, Giant's Castle"
normalized("tick, dancing, wegjewrgjophg","list of familiar")
// returns "Ghost Pickle on a Stick, Dancing Frog, none"
But if I break it, you couldn't implement your own string.equals.
PHP:boolean equals( string arg1, string arg2 ) { return arg1.length() == arg2.length() && arg1.contains_text(arg2); }
string compare_versions(string verA, string verB) {
matcher m; string numA; string numB; string otherA; string otherB;
m = create_matcher("\\d+(?:\\.\\d+|\\s\\d+|:\\d+|-\\d+|_\\d+)*", verA);
if (m.find()) { numA = m.group(); otherA = replace_first(m, " "); } else return "error";
m = create_matcher("\\d+(?:\\.\\d+|\\s\\d+|:\\d+|-\\d+|_\\d+)*", verB);
if (m.find()) { numB= m.group(); otherB = replace_first(m, " "); } else return "error";
string [int] splitA; string [int] splitB; int secA; int secB;
splitA = split_string(numA, "(?:\\.|\\s|:|-|_)");
splitB = split_string(numB, "(?:\\.|\\s|:|-|_)");
for i from 0 to max(count(splitA) - 1,count(splitB) - 1) {
if (i > count(splitA) - 1) secA = 0; else secA = splitA[i].to_int();
if (i > count(splitB) - 1) secB = 0; else secB = splitB[i].to_int();
if (secA != secB) return (secA > secB) ? verA: verB;
}
if (otherA == otherB) return "";
int statusA; int statusB; //0-4 for d,a,b,rc,final
switch {
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?d(?:(?:ev)?elopment)?(?:\\.|\\s|:|-|_)?\\b", otherA))):
statusA = 0;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?a(?:lpha)?(?:\\.|\\s|:|-|_)?\\b", otherA))):
statusA = 1;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?b(?:eta)?(?:\\.|\\s|:|-|_)?\\b", otherA))):
statusA = 2;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?r(?:c|elease candidate)(?:\\.|\\s|:|-|_)?\\b", otherA))):
statusA = 3;
break;
default: statusA = 4;
}
switch {
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?d(?:(?:ev)?elopment)?(?:\\.|\\s|:|-|_)?\\b", otherB))):
statusB = 0;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?a(?:lpha)?(?:\\.|\\s|:|-|_)?\\b", otherB))):
statusB = 1;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?b(?:eta)?(?:\\.|\\s|:|-|_)?\\b", otherB))):
statusB = 2;
break;
case (find(create_matcher(
"\\b(?:\\.|\\s|:|-|_)?r(?:c|elease candidate)(?:\\.|\\s|:|-|_)?\\b)", otherB))):
statusB = 3;
break;
default: statusB = 4;
}
if (statusA != statusB) return (statusA > statusB) ? verA : verB;
int otherNumA = 0; int otherNumB = 0;
m = create_matcher("\\d+", otherA);
if (m.find()) otherNumA = m.group().to_int();
m = create_matcher("\\d+", otherB);
if (m.find()) otherNumB = m.group().to_int();
return (otherNumA == otherNumB) ? "" : (otherNumA > otherNumB) ? verA : verB;
}
Fairly robust comparisson of two strings as software revisions
returns the HIGHER or the two, or "" if they are equal
First, all numbers are compared (numerically, not as strings)
Possible separators are:
. (space) - : _ (nothing: single number)
Only a single char. of the above between numbers will be recognized between each set of number(s)
The first numbers in your string will be matched as the most "important" part of your versioning
don't start your string with "rc1" then follow with the major/minor/bug or alt. numbering
if you use sep. numbering for dev/alpha/beta/rc/(final), it must FOLLOW the other versioning
At each "level" from left to right, any numbers present in one string and not the other will have 0 substituted
ie comparing 14.2 to 14.2.1 compares as 14.2.0 to 14.2.1
If version numbers as above are equal, next look for status and compare
The following are looked for in the strings (either the full word OR abbreviation, given in parentheses)
Note that if none are found, "final" is assumed
dev OR development (d) < alpha (a) < beta(b) < release candidate (rc) < final (no suffix)
Any leftover text is ignored: feel free to use "v" or "r" (but not rc!) in your version strings
you can't use a single d, a, b (or "rc") in the rest of the string, or it will be treated as a status
by single I mean by itself, with blank or version at the boundaries
ie "u b ready? v1.0.2" would parse the "b" as "beta"
ie "this is really cool, yah? 12-2-0_dev" will properly see "dev" and not fire on the "r" in "really"
After the above checks, it will search for any remaining consecutive numbers that weren't part of the first number / separator sect.
if either is not found, it is assumed to be 0
these remaining numbers are compared, highest being newest
If all of the above has been checked and evaluates as equal, "" is returned
If matching fails (for example, the function can't parse at least one number string from both versions, "error" is returned
obviously, this means it would muck things up to use "error" in any version name passed to this function
compare_revisions("1.0", "0.9") -> "1.0"
compare_revisions("1.0.0", "1.0.0dev") -> "1.0.0"
compare_revisions("14.2.8", "v14.2.9") -> "v14.2.9"
compare_revisions("rev11.0.1", "12 dev") -> "12 dev"
compare_revisions("13.0", "12.8.4.6.99.2 release candidate") -> "13.0"
compare_revisions("11.1d", "11.1_d3") -> "11.1_d3"
compare_revisions("beta 3 1.1.1", "1.2") -> "beta 3 1.1"
this is because the 3 is matched first, and taken as the 'major' revision
a numbered status currently needs to follow the main numbering
compare_revisions("1.5", "1.41") -> "1.41"
you need to use a separator between all levels of differentiation;
".41" is treated as 41, which is > 5
you CAN use a different separator for a normally-unused bugfix level
compare_revisions("1.4", "1.4:2") -> "1.4:2"
return (statusA == statusB) ? "" : (statusA > statusB) ? verA : verB;
if (secA != secB) return (secA > secB) ? verA: verB;
why not return either one?
fixed the spelling of "candidate."
case (find(create_matcher("release cantidate",otherA))): statusA = 3; break;
b[eta]?
case (find(create_matcher("d[ev]?[elopment]?",otherA))): statusA = 0; break;
case (find(create_matcher("rc",otherB))): statusB = 3; break;
case (find(create_matcher("release candidate",otherB))): statusB = 3; break;