All pastes #246412 Raw Edit

Unnamed

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

HEAD
dev
DRUPAL-5
5.x-1.x-dev
DRUPAL-5--2
5.x-2.x-dev
DRUPAL-5--2-3
5.x-2-3
DRUPAL-5--23-32
5.x-23-32
DRUPAL-5--23-32-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);
}