All pastes #246411 Raw Edit

Miscellany

public text v1 · immutable
#246411 ·published 2006-11-12 04:38 UTC
rendered paste body
Output:

HEAD
dev
DRUPAL-5
Array ( [0] => DRUPAL-5 ) 5.x-1.x-dev
DRUPAL-5--2
Array ( [0] => DRUPAL-5--2 [major] => 2 [1] => 2 ) 5.x-2.x-dev
DRUPAL-5--2-3
Array ( [0] => DRUPAL-5--2-3 [major] => 2 [1] => 2 [minor] => 3 [2] => 3 ) 5.x-2-3
DRUPAL-5--23-32
Array ( [0] => DRUPAL-5--23-32 [major] => 23 [1] => 23 [minor] => 32 [2] => 32 ) 5.x-23-32
DRUPAL-5--23-32-BETA-SUPER-EXTENDED-1
Array ( [0] => DRUPAL-5--23-32-BETA-SUPER-EXTENDED-1 [major] => 23 [1] => 23 [minor] => 32 [2] => 32 [extra] => -BETA-SUPER-EXTENDED-1 [3] => -BETA-SUPER-EXTENDED-1 ) 5.x-23-32-beta-super-extended-1

Function:
function system_extract_version($version_string) {
  $core_version = substr(VERSION, 0, strpos(VERSION, '.'));
  $pattern =  '/DRUPAL-'. $core_version .'(?:--(?P<major>\d+)(?:-(?P<minor>\d+))?)?(?P<extra>-.+)?/';

  if (empty($version_string)) {
    // Module was checked out from HEAD.
    $version = t('dev');
  }
  elseif (preg_match($pattern, $version_string, $matches)) {
    if (!isset($matches['major'])) {
      // Module was checked out from a branch like DRUPAL-5
      $version = $core_version .'.x-1.x-dev';
    }
    elseif (!isset($matches['minor'])) {
      // Module was checked out from a branch like DRUPAL-5--2
      $version = $core_version .'.x-'. $matches['major'] .'.x-dev';
    }
    else {
      // Official release of a module that was tagged, ex. DRUPAL-5--1-2
      $version = $core_version .'.x-'. $matches['major'] .'-'. $matches['minor'] . drupal_strtolower($matches['extra']);
    }
  }

  return check_plain($version);

}