TYPO3  7.6
Replace.php
Go to the documentation of this file.
1 <?php
2 
19 namespace cogpowered\FineDiff\Parser\Operations;
20 
21 class Replace implements OperationInterface
22 {
27  public function __construct($fromLen, $text)
28  {
29  $this->fromLen = $fromLen;
30  $this->text = $text;
31  }
32 
36  public function getFromLen()
37  {
38  return $this->fromLen;
39  }
40 
44  public function getToLen()
45  {
46  return strlen($this->text);
47  }
48 
54  public function getText()
55  {
56  return $this->text;
57  }
58 
62  public function getOpcode()
63  {
64  if ($this->fromLen === 1) {
65  $del_opcode = 'd';
66  } else {
67  $del_opcode = "d{$this->fromLen}";
68  }
69 
70  $to_len = strlen($this->text);
71 
72  if ($to_len === 1) {
73  return "{$del_opcode}i:{$this->text}";
74  }
75 
76  return "{$del_opcode}i{$to_len}:{$this->text}";
77  }
78 }