Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
ac235ef8
Commit
ac235ef8
authored
Oct 17, 2013
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2043757
by dawehner, Alan D.: Remove drupal_(string) methods out of diffengine.
parent
c49e5c80
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/lib/Drupal/Component/Diff/DiffEngine.php
+7
-142
7 additions, 142 deletions
core/lib/Drupal/Component/Diff/DiffEngine.php
with
7 additions
and
142 deletions
core/lib/Drupal/Component/Diff/DiffEngine.php
+
7
−
142
View file @
ac235ef8
...
@@ -8,9 +8,11 @@
...
@@ -8,9 +8,11 @@
* You may copy this code freely under the conditions of the GPL.
* You may copy this code freely under the conditions of the GPL.
*/
*/
define
(
'USE_ASSERTS'
,
FALSE
);
use
Drupal\Component\Utility\Settings
;
use
Drupal\Component\Utility\Settings
;
use
Drupal\Component\Utility\String
;
use
Drupal\Component\Utility\Unicode
;
define
(
'USE_ASSERTS'
,
FALSE
);
/**
/**
* @todo document
* @todo document
...
@@ -240,7 +242,7 @@ function diff($from_lines, $to_lines) {
...
@@ -240,7 +242,7 @@ function diff($from_lines, $to_lines) {
* Returns the whole line if it's small enough, or the MD5 hash otherwise.
* Returns the whole line if it's small enough, or the MD5 hash otherwise.
*/
*/
function
_line_hash
(
$line
)
{
function
_line_hash
(
$line
)
{
if
(
drupal_
strlen
(
$line
)
>
$this
->
MAX_XREF_LENGTH
())
{
if
(
Unicode
::
strlen
(
$line
)
>
$this
->
MAX_XREF_LENGTH
())
{
return
md5
(
$line
);
return
md5
(
$line
);
}
}
else
{
else
{
...
@@ -995,7 +997,7 @@ function addWords($words, $tag = '') {
...
@@ -995,7 +997,7 @@ function addWords($words, $tag = '') {
}
}
if
(
$word
[
0
]
==
"
\n
"
)
{
if
(
$word
[
0
]
==
"
\n
"
)
{
$this
->
_flushLine
(
$tag
);
$this
->
_flushLine
(
$tag
);
$word
=
drupal_
substr
(
$word
,
1
);
$word
=
Unicode
::
substr
(
$word
,
1
);
}
}
assert
(
!
strstr
(
$word
,
"
\n
"
));
assert
(
!
strstr
(
$word
,
"
\n
"
));
$this
->
_group
.
=
$word
;
$this
->
_group
.
=
$word
;
...
@@ -1039,7 +1041,7 @@ function _split($lines) {
...
@@ -1039,7 +1041,7 @@ function _split($lines) {
$words
[]
=
"
\n
"
;
$words
[]
=
"
\n
"
;
$stripped
[]
=
"
\n
"
;
$stripped
[]
=
"
\n
"
;
}
}
if
(
drupal_
strlen
(
$line
)
>
$this
->
MAX_LINE_LENGTH
()
)
{
if
(
Unicode
::
strlen
(
$line
)
>
$this
->
MAX_LINE_LENGTH
()
)
{
$words
[]
=
$line
;
$words
[]
=
$line
;
$stripped
[]
=
$line
;
$stripped
[]
=
$line
;
}
}
...
@@ -1222,140 +1224,3 @@ function _changed($orig, $closing) {
...
@@ -1222,140 +1224,3 @@ function _changed($orig, $closing) {
}
}
}
}
}
}
/**
* Drupal inline Diff formatter.
* @private
* @subpackage DifferenceEngine
*/
class
DrupalDiffInline
{
var
$a
;
var
$b
;
/**
* Constructor.
*/
function
__construct
(
$a
,
$b
)
{
$this
->
a
=
$a
;
$this
->
b
=
$b
;
}
/**
* Render differences inline using HTML markup.
*/
function
render
()
{
$a
=
preg_split
(
'/(<[^>]+?>| )/'
,
$this
->
a
,
-
1
,
PREG_SPLIT_DELIM_CAPTURE
);
$b
=
preg_split
(
'/(<[^>]+?>| )/'
,
$this
->
b
,
-
1
,
PREG_SPLIT_DELIM_CAPTURE
);
$diff
=
new
Diff
(
$a
,
$b
);
$diff
->
edits
=
$this
->
process_edits
(
$diff
->
edits
);
// Assemble highlighted output
$output
=
''
;
foreach
(
$diff
->
edits
as
$chunk
)
{
switch
(
$chunk
->
type
)
{
case
'copy'
:
$output
.
=
implode
(
''
,
$chunk
->
closing
);
break
;
case
'delete'
:
foreach
(
$chunk
->
orig
as
$i
=>
$piece
)
{
if
(
strpos
(
$piece
,
'<'
)
===
0
&&
drupal_substr
(
$piece
,
drupal_strlen
(
$piece
)
-
1
)
===
'>'
)
{
$output
.
=
$piece
;
}
else
{
$diff_inline_chunk
=
array
(
'#theme'
=>
'diff_inline_chunk'
,
'#text'
=>
$piece
,
'#type'
=>
$chunk
->
type
,
);
$output
.
=
drupal_render
(
$diff_inline_chunk
);
}
}
break
;
default
:
$chunk
->
closing
=
$this
->
process_chunk
(
$chunk
->
closing
);
foreach
(
$chunk
->
closing
as
$i
=>
$piece
)
{
if
(
$piece
===
' '
||
(
strpos
(
$piece
,
'<'
)
===
0
&&
drupal_substr
(
$piece
,
drupal_strlen
(
$piece
)
-
1
)
===
'>'
&&
drupal_strtolower
(
drupal_substr
(
$piece
,
1
,
3
))
!=
'img'
))
{
$output
.
=
$piece
;
}
else
{
$diff_inline_chunk
=
array
(
'#theme'
=>
'diff_inline_chunk'
,
'#text'
=>
$piece
,
'#type'
=>
$chunk
->
type
,
);
$output
.
=
drupal_render
(
$diff_inline_chunk
);
}
}
break
;
}
}
return
$output
;
}
/**
* Merge chunk segments between tag delimiters.
*/
function
process_chunk
(
$chunk
)
{
$processed
=
array
();
$j
=
0
;
foreach
(
$chunk
as
$i
=>
$piece
)
{
$next
=
isset
(
$chunk
[
$i
+
1
])
?
$chunk
[
$i
+
1
]
:
NULL
;
if
(
!
isset
(
$processed
[
$j
]))
{
$processed
[
$j
]
=
''
;
}
if
(
strpos
(
$piece
,
'<'
)
===
0
&&
drupal_substr
(
$piece
,
drupal_strlen
(
$piece
)
-
1
)
===
'>'
)
{
$processed
[
$j
]
=
$piece
;
$j
++
;
}
elseif
(
isset
(
$next
)
&&
strpos
(
$next
,
'<'
)
===
0
&&
drupal_substr
(
$next
,
drupal_strlen
(
$next
)
-
1
)
===
'>'
)
{
$processed
[
$j
]
.
=
$piece
;
$j
++
;
}
else
{
$processed
[
$j
]
.
=
$piece
;
}
}
return
$processed
;
}
/**
* Merge copy and equivalent edits into intelligible chunks.
*/
function
process_edits
(
$edits
)
{
$processed
=
array
();
$current
=
array_shift
(
$edits
);
// Make two passes -- first merge space delimiter copies back into their originals.
while
(
$chunk
=
array_shift
(
$edits
))
{
if
(
$chunk
->
type
==
'copy'
&&
$chunk
->
orig
===
array
(
' '
))
{
$current
->
orig
=
array_merge
((
array
)
$current
->
orig
,
(
array
)
$chunk
->
orig
);
$current
->
closing
=
array_merge
((
array
)
$current
->
closing
,
(
array
)
$chunk
->
closing
);
}
else
{
$processed
[]
=
$current
;
$current
=
$chunk
;
}
}
$processed
[]
=
$current
;
// Initial setup
$edits
=
$processed
;
$processed
=
array
();
$current
=
array_shift
(
$edits
);
// Second, merge equivalent chunks into each other.
while
(
$chunk
=
array_shift
(
$edits
))
{
if
(
$current
->
type
==
$chunk
->
type
)
{
$current
->
orig
=
array_merge
((
array
)
$current
->
orig
,
(
array
)
$chunk
->
orig
);
$current
->
closing
=
array_merge
((
array
)
$current
->
closing
,
(
array
)
$chunk
->
closing
);
}
else
{
$processed
[]
=
$current
;
$current
=
$chunk
;
}
}
$processed
[]
=
$current
;
return
$processed
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment