Quantcast WoWInterface - View Single Post - Things I've noticed
View Single Post
12-02-14, 07:17 AM   #12
A Flamescale Wyrmkin
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Originally Posted by Dridzt View Post
This would be a nice opportunity for some community effort in coming up with a sane pattern for version checking.


Test version strings (eg. 'v2.08-3a') here and submit pattern proposals
some php code that should parse most versions - including the example.
only reason why php, is that it's quicker to play with - as opposed to compiling and UI stuff.

//pattern - checks for the presence of a "v", with or without space,
//then checks for numbers, dashes and dots - and captures those. 
//and finally, recognizes the posibility of whitespace, and looks for any letters following it. 
$pat = '/[vV\s]*([0-9\-\.]+)[\s]*([a-zA-Z]?)/';
//test string
//do the match
//replace dashes with dots
$newstr = str_replace("-",".",$match[1]);
//split it by the dots
$sstring = explode(".",$newstr);
//init vars
$ver ="0";
$subver ="0";
//test if there are actually any dots
	//if so, combine the first two (i.e. 2.08)
	//check for moar dots!
		//loop through the rest, appending any additional parts
		for($i=2; $i < count($sstring);$i++)
	//otherwise, just set it to the first value. 
//check if we have a letter;
	//if so, drop it low, then get the char value of it - 97 in this case
	//char values go up in alphabetical order, but 'A' and 'a' need to be treated the same. 

//and output the version (2.083) and the subversion (97)
echo "Version: ".$ver."<br>";
echo "SubVersion: ".$subver;
// 2.08.4 will be a newer version, as will 2.08.3b, and so forth.

I'd be willing to take on more "challenges" to put it to the test of course.

Last edited by Digital_Utopia : 12-02-14 at 07:22 AM.
  Reply With Quote