3 define(CCRM_EXTENSIONVALIDATION_PAD, 7);
6 * Determine if a version is valid
10 function ccrm_extensionvalidation_version_isValid($ver) {
11 $parts = ccrm_extensionvalidation_version_split($ver);
12 foreach ($parts as $part) {
13 if (!preg_match('/^(z[0-9]+|pre[0-9]+)$/', $part)) {
21 * Normalize version, producing a code that can be correclty
26 function ccrm_extensionvalidation_version_normalize($ver) {
27 return implode('-', ccrm_extensionvalidation_version_split($ver));
32 * Clean version number:
33 * - Use consistent delimiter
34 * - Change revision #s (r456) to straight numbers (456)
35 * - Explode into numeric and alphabetic parts
36 * - Make numerals higher than alphas (1.2.0 > 1.2.alpha)
38 * @return array of version parts
40 function ccrm_extensionvalidation_version_split($ver, $pad = CCRM_EXTENSIONVALIDATION_PAD) {
41 $ver = strtolower($ver);
42 $ver = preg_replace('/-/', '.', $ver);
43 $ver = preg_replace('/^r/', '', $ver);
50 for ($i = 0; $i < $len; $i++) {
51 if ($ver{$i} == '.') {
53 } elseif (is_numeric($ver{$i})) {
56 $newCharType = 'ALPHA';
59 // printf("ver=[%s] state=%-5s newCharType=%-5s char=[%s] parts=[%-12s] buf=[%s]\n", $ver, $state, $newCharType, $ver{$i}, implode('/', $parts), $buf);
63 $state = $newCharType;
68 if ($state == $newCharType) {
70 } elseif ($newCharType == 'SEP') {
74 } elseif ($newCharType == 'NUM') {
77 $state = $newCharType;
78 } elseif ($newCharType == 'ALPHA') {
81 $state = $newCharType;
92 foreach ($parts as $i => &$part) {
93 if (is_numeric($part)) {
94 if (strlen($part) > $pad) {
97 $part = sprintf("z%0${pad}s", $part);
100 if (isset($codes[$part])) {
101 $part = $codes[$part];