FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ReportImportHelper.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015-2017 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 namespace Fossology\ReportImport;
8 
9 use EasyRdf\Graph;
10 
12 {
13  private static function getTokensFromlicenseExpression($licenseExpr) // TODO
14  {
15  return array_filter(explode(' ', str_replace(array("(",")"), " ", $licenseExpr)));
16  }
17 
18  public static function getShortnamesFromLicenseExpression($licenseExpr)
19  {
20  $licenseExprTokens = self::getTokensFromlicenseExpression($licenseExpr);
21  $shortnames = array();
22  $licenseRefPrefix = "LicenseRef-";
23  foreach($licenseExprTokens as $token){
24  if($token == "OR")
25  {
26  $shortnames[] = "Dual-license";
27  }
28  else if(substr($token, 0, strlen($licenseRefPrefix)) === $licenseRefPrefix)
29  {
30  $shortnames[] = urldecode(substr($token, strlen($licenseRefPrefix)));
31  }
32  else
33  {
34  $shortnames[] = urldecode($token);
35  }
36  }
37  return $shortnames;
38  }
39 
40  public static function stripPrefix($str)
41  {
42  $parts = explode('#', $str, 2);
43  if (sizeof($parts) === 2)
44  {
45  return $parts[1];
46  }
47  return "";
48  }
49 
50  public static function stripPrefixes($strs)
51  {
52  return array_map(array(__CLASS__, "stripPrefix"), $strs);
53  }
54 
55 }