Some cleanup

This commit is contained in:
2023-04-07 22:10:03 -04:00
parent 49842a1663
commit 96d327270f
14 changed files with 64 additions and 97 deletions

View File

@@ -60,7 +60,7 @@ namespace FeedCenter
#endregion
public class Feed : RealmObject
public partial class Feed : RealmObject
{
[PrimaryKey]
[MapTo("ID")]
@@ -140,11 +140,11 @@ namespace FeedCenter
#region Reading
public FeedReadResult Read(FeedCenterEntities database, bool forceRead = false)
public FeedReadResult Read(bool forceRead = false)
{
Log.Logger.Information("Reading feed: {0}", Source);
var result = ReadFeed(database, forceRead);
var result = ReadFeed(forceRead);
// Handle the result
switch (result)
@@ -224,7 +224,7 @@ namespace FeedCenter
feedText = feedText.Replace(" ", " ");
// Find ampersands that aren't properly escaped and replace them with escaped versions
var r = new Regex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)");
var r = UnescapedAmpersandRegex();
feedText = r.Replace(feedText, "&");
return Tuple.Create(FeedReadResult.Success, feedText);
@@ -291,7 +291,7 @@ namespace FeedCenter
}
}
private FeedReadResult ReadFeed(FeedCenterEntities database, bool forceRead)
private FeedReadResult ReadFeed(bool forceRead)
{
try
{
@@ -364,6 +364,9 @@ namespace FeedCenter
}
}
[GeneratedRegex("&(?!(?:[a-z]+|#[0-9]+|#x[0-9a-f]+);)")]
private static partial Regex UnescapedAmpersandRegex();
#endregion
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Text.RegularExpressions;
using FeedCenter.Options;
using FeedCenter.Options;
using Realms;
using System;
using System.Text.RegularExpressions;
namespace FeedCenter
{
public class FeedItem : RealmObject
public partial class FeedItem : RealmObject
{
[PrimaryKey]
[MapTo("ID")]
@@ -30,22 +30,20 @@ namespace FeedCenter
return new FeedItem { Id = System.Guid.NewGuid() };
}
#region Methods
public override string ToString()
{
var title = Title;
switch (Properties.Settings.Default.MultipleLineDisplay)
{
case Options.MultipleLineDisplay.SingleLine:
case MultipleLineDisplay.SingleLine:
// Strip any newlines from the title
title = Regex.Replace(title, @"\n", " ");
title = NewlineRegex().Replace(title, " ");
break;
case Options.MultipleLineDisplay.FirstLine:
case MultipleLineDisplay.FirstLine:
// Find the first newline
var newlineIndex = title.IndexOf("\n", StringComparison.Ordinal);
@@ -62,10 +60,10 @@ namespace FeedCenter
}
// Condense multiple spaces to one space
title = Regex.Replace(title, @"[ ]{2,}", " ");
title = MultipleSpaceRegex().Replace(title, " ");
// Condense tabs to one space
title = Regex.Replace(title, @"\t", " ");
title = TabRegex().Replace(title, " ");
// If the title is blank then put in the "no title" title
if (title.Length == 0)
@@ -74,20 +72,13 @@ namespace FeedCenter
return title;
}
//public void ProcessActions(IEnumerable<FeedAction> feedActions)
//{
// foreach (FeedAction feedAction in feedActions)
// {
// switch (feedAction.Field)
// {
// case 1:
[GeneratedRegex("\\n")]
private static partial Regex NewlineRegex();
// Title = Regex.Replace(Title, feedAction.Search, feedAction.Replace);
// break;
// }
// }
//}
[GeneratedRegex("[ ]{2,}")]
private static partial Regex MultipleSpaceRegex();
#endregion
[GeneratedRegex("\\t")]
private static partial Regex TabRegex();
}
}
}