FOSSology  4.4.0
Open Source License Compliance by Open Source Software
TextFragment.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4  Author: Andreas Würl
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\Data;
10 
12 {
13 
14  private $startOffset;
15  private $text;
16 
17  public function __construct($startOffset, $text)
18  {
19 
20  $this->startOffset = $startOffset;
21  $this->text = $text;
22  }
23 
24  public function getStartOffset()
25  {
26  return $this->startOffset;
27  }
28 
29  public function getEndOffset()
30  {
31  return $this->startOffset + strlen($this->text);
32  }
33 
34  public function getSlice($startOffset, $endOffset = null)
35  {
36  $adjustedStartOffset = max($startOffset - $this->startOffset, 0);
37  if (isset($endOffset)) {
38  $adjustedEndOffset = max($endOffset - $this->startOffset, 0);
39  return substr($this->text, $adjustedStartOffset,
40  max($adjustedEndOffset - $adjustedStartOffset, 0));
41  } else {
42  return substr($this->text, $adjustedStartOffset);
43  }
44  }
45 }
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
Definition: libfossagent.c:295