Skip to content

Commit 8e453dd

Browse files
committed
Add additional characters to specialCaseChars and implement get/set/add/remove functions for specialCaseChars
1 parent c98f2a7 commit 8e453dd

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HtmlDiff
1414
private $specialCaseOpeningTags = array();
1515
private $specialCaseClosingTags = array();
1616
private $specialCaseTags = array('strong', 'b', 'i', 'big', 'small', 'u', 'sub', 'sup', 'strike', 's', 'p');
17-
private $specialCaseChars = array('.', ',');
17+
private $specialCaseChars = array('.', ',', '(', ')', '\'');
1818
private $groupDiffs = true;
1919

2020
public function __construct($oldText, $newText, $encoding = 'UTF-8', $specialCaseTags = array(), $groupDiffs = true)
@@ -27,6 +27,31 @@ public function __construct($oldText, $newText, $encoding = 'UTF-8', $specialCas
2727

2828
$this->setSpecialCaseTags($specialCaseTags);
2929
}
30+
31+
public function setSpecialCaseChars(array $chars)
32+
{
33+
$this->specialCaseChars = $chars;
34+
}
35+
36+
public function getSpecialCaseChars()
37+
{
38+
return $this->specialCaseChars;
39+
}
40+
41+
public function addSpecialCaseChar($char)
42+
{
43+
if (!in_array($char, $this->specialCaseChars)) {
44+
$this->specialCaseChars[] = $char;
45+
}
46+
}
47+
48+
public function removeSpecialCaseChar($char)
49+
{
50+
$key = array_search($char, $this->specialCaseChars);
51+
if ($key !== false) {
52+
unset($this->specialCaseChars[$key]);
53+
}
54+
}
3055

3156
public function setSpecialCaseTags(array $tags = array())
3257
{
@@ -175,7 +200,7 @@ private function splitInputsToWords()
175200
$this->newWords = $this->convertHtmlToListOfWords( $this->explode( $this->newText ) );
176201
}
177202

178-
private function isSingleWord($text)
203+
private function isPartOfWord($text)
179204
{
180205
return ctype_alnum(str_replace($this->specialCaseChars, '', $text));
181206
}
@@ -202,8 +227,8 @@ private function convertHtmlToListOfWords($characterString)
202227
$mode = 'whitespace';
203228
} else {
204229
if (
205-
(ctype_alnum($character) && (strlen($current_word) == 0 || $this->isSingleWord($current_word))) ||
206-
(in_array($character, $this->specialCaseChars) && isset($characterString[$i+1]) && $this->isSingleWord($characterString[$i+1]))
230+
(ctype_alnum($character) && (strlen($current_word) == 0 || $this->isPartOfWord($current_word))) ||
231+
(in_array($character, $this->specialCaseChars) && isset($characterString[$i+1]) && $this->isPartOfWord($characterString[$i+1]))
207232
) {
208233
$current_word .= $character;
209234
} else {

0 commit comments

Comments
 (0)