@@ -12,6 +12,8 @@ public class HtmlDiff
12
12
/// This value defines balance between speed and memory utilization. The higher it is the faster it works and more memory consumes.
13
13
/// </summary>
14
14
private const int MatchGranularityMaximum = 4 ;
15
+ private const string DelTag = "del" ;
16
+ private const string InsTag = "ins" ;
15
17
16
18
private readonly StringBuilder _content ;
17
19
private string _newText ;
@@ -188,13 +190,13 @@ private void ProcessReplaceOperation(Operation operation)
188
190
private void ProcessInsertOperation ( Operation operation , string cssClass )
189
191
{
190
192
var text = _newWords . Where ( ( s , pos ) => pos >= operation . StartInNew && pos < operation . EndInNew ) . ToList ( ) ;
191
- InsertTag ( "ins" , cssClass , text ) ;
193
+ InsertTag ( InsTag , cssClass , text ) ;
192
194
}
193
195
194
196
private void ProcessDeleteOperation ( Operation operation , string cssClass )
195
197
{
196
198
var text = _oldWords . Where ( ( s , pos ) => pos >= operation . StartInOld && pos < operation . EndInOld ) . ToList ( ) ;
197
- InsertTag ( "del" , cssClass , text ) ;
199
+ InsertTag ( DelTag , cssClass , text ) ;
198
200
}
199
201
200
202
private void ProcessEqualOperation ( Operation operation )
@@ -247,12 +249,11 @@ private void InsertTag(string tag, string cssClass, List<string> words)
247
249
}
248
250
else
249
251
{
250
- // Check if the tag is a special case
251
252
if ( SpecialCaseOpeningTagRegex . IsMatch ( words [ 0 ] ) )
252
253
{
253
254
_specialTagDiffStack . Push ( words [ 0 ] ) ;
254
255
specialCaseTagInjection = "<ins class='mod'>" ;
255
- if ( tag == "del" )
256
+ if ( tag == DelTag )
256
257
{
257
258
words . RemoveAt ( 0 ) ;
258
259
@@ -263,23 +264,18 @@ private void InsertTag(string tag, string cssClass, List<string> words)
263
264
}
264
265
}
265
266
}
266
-
267
267
else if ( _specialCaseClosingTags . ContainsKey ( words [ 0 ] ) )
268
268
{
269
269
var openingTag = _specialTagDiffStack . Count == 0 ? null : _specialTagDiffStack . Pop ( ) ;
270
-
271
- // If we didn't have an opening tag, and we don't have a match with the previous tag used
272
- if ( openingTag == null || Utils . GetTagName ( openingTag ) != Utils . GetTagName ( words . Last ( ) ) )
273
- {
274
- // do nothing
275
- }
276
- else
270
+ var hasOpeningTag = ! ( openingTag is null ) ;
271
+ var openingAndClosingTagsMatch = Utils . GetTagName ( openingTag ) == Utils . GetTagName ( words . Last ( ) ) ;
272
+ if ( hasOpeningTag && openingAndClosingTagsMatch )
277
273
{
278
274
specialCaseTagInjection = "</ins>" ;
279
275
specialCaseTagInjectionIsBefore = true ;
280
276
}
281
277
282
- if ( tag == "del" )
278
+ if ( tag == DelTag )
283
279
{
284
280
words . RemoveAt ( 0 ) ;
285
281
0 commit comments