FOSSology  4.4.0
Open Source License Compliance by Open Source Software
StringOperation.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 
9 namespace Fossology\Lib\Util;
10 
12 {
18  public static function getCommonHead($a, $b)
19  {
20  $headLength = 0;
21  $maxNumberOfCharsToCompare = min(strlen($a), strlen($b));
22  while ($headLength < $maxNumberOfCharsToCompare &&
23  $a[$headLength] === $b[$headLength]) {
24  $headLength += 1;
25  }
26  return substr($a,0,$headLength);
27  }
28 
35  public static function replaceUnicodeControlChar($input, $replace="")
36  {
37  // 'Non-printable' is ASCII < 0x20 (excluding \r, \n and tab) and
38  // 0x7F - 0x9F.
39  return preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', $replace,
40  $input);
41  }
42 
50  public static function stringStartsWith($haystack, $needle)
51  {
52  return strncmp($haystack, $needle, strlen($needle)) === 0;
53  }
54 }
static replaceUnicodeControlChar($input, $replace="")
static stringStartsWith($haystack, $needle)
FUNCTION int min(int user_perm, int permExternal)
Get the minimum permission level required.
Definition: libfossagent.c:306