Use nullable

This commit is contained in:
Alexey Golub
2019-11-13 19:19:36 +02:00
parent 1bf9d9e2e2
commit e5a2852165
42 changed files with 195 additions and 196 deletions

View File

@@ -2,10 +2,11 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.3" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
</ItemGroup>
</Project>

View File

@@ -16,9 +16,9 @@ namespace DiscordChatExporter.Core.Markdown.Internal
{
}
public ParsedMatch<T> Match(StringPart stringPart)
public ParsedMatch<T>? Match(StringPart stringPart)
{
ParsedMatch<T> earliestMatch = null;
ParsedMatch<T>? earliestMatch = null;
// Try to match the input with each matcher and get the match with the lowest start index
foreach (var matcher in _matchers)

View File

@@ -2,6 +2,6 @@
{
internal interface IMatcher<T>
{
ParsedMatch<T> Match(StringPart stringPart);
ParsedMatch<T>? Match(StringPart stringPart);
}
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
namespace DiscordChatExporter.Core.Markdown.Internal
@@ -23,7 +19,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal
{
}
public ParsedMatch<T> Match(StringPart stringPart)
public ParsedMatch<T>? Match(StringPart stringPart)
{
var match = _regex.Match(stringPart.Target, stringPart.StartIndex, stringPart.Length);
if (!match.Success)

View File

@@ -20,7 +20,7 @@ namespace DiscordChatExporter.Core.Markdown.Internal
{
}
public ParsedMatch<T> Match(StringPart stringPart)
public ParsedMatch<T>? Match(StringPart stringPart)
{
var index = stringPart.Target.IndexOf(_needle, stringPart.StartIndex, stringPart.Length, _comparison);

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using DiscordChatExporter.Core.Markdown.Internal;
using DiscordChatExporter.Core.Markdown.Nodes;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Markdown
{
@@ -125,7 +124,7 @@ namespace DiscordChatExporter.Core.Markdown
// Capture <:lul:123456> or <a:lul:123456>
private static readonly IMatcher<Node> CustomEmojiNodeMatcher = new RegexMatcher<Node>(
new Regex("<(a)?:(.+?):(\\d+?)>", DefaultRegexOptions),
m => new EmojiNode(m.Groups[3].Value, m.Groups[2].Value, !m.Groups[1].Value.IsNullOrWhiteSpace()));
m => new EmojiNode(m.Groups[3].Value, m.Groups[2].Value, !string.IsNullOrWhiteSpace(m.Groups[1].Value)));
/* Links */

View File

@@ -1,18 +1,16 @@
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Markdown.Nodes
namespace DiscordChatExporter.Core.Markdown.Nodes
{
public class EmojiNode : Node
{
public string Id { get; }
public string? Id { get; }
public string Name { get; }
public bool IsAnimated { get; }
public bool IsCustomEmoji => !Id.IsNullOrWhiteSpace();
public bool IsCustomEmoji => !string.IsNullOrWhiteSpace(Id);
public EmojiNode(string id, string name, bool isAnimated)
public EmojiNode(string? id, string name, bool isAnimated)
{
Id = id;
Name = name;