FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
TextFragment.php
1 <?php
2 
3 /*
4 Copyright (C) 2014, Siemens AG
5 Author: Andreas Würl
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 namespace Fossology\Lib\Data;
22 
24 {
25 
26  private $startOffset;
27  private $text;
28 
29  public function __construct($startOffset, $text)
30  {
31 
32  $this->startOffset = $startOffset;
33  $this->text = $text;
34  }
35 
36  public function getStartOffset()
37  {
38  return $this->startOffset;
39  }
40 
41  public function getEndOffset()
42  {
43  return $this->startOffset + strlen($this->text);
44  }
45 
46  public function getSlice($startOffset, $endOffset = null)
47  {
48  $adjustedStartOffset = max($startOffset - $this->startOffset, 0);
49  if (isset($endOffset)) {
50  $adjustedEndOffset = max($endOffset - $this->startOffset, 0);
51  return substr($this->text, $adjustedStartOffset,
52  max($adjustedEndOffset - $adjustedStartOffset, 0));
53  } else {
54  return substr($this->text, $adjustedStartOffset);
55  }
56  }
57 }
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
Definition: libfossagent.c:309