diff options
| author | Bond_009 <bond.009@outlook.com> | 2021-03-09 01:28:21 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2021-03-09 01:28:21 +0100 |
| commit | 5241bd41ef4917e0a3071f961f08dd2eeec5a5dd (patch) | |
| tree | 46ea0263532c56e088db31a85f40fbaedf9ea0e7 /Emby.Naming/Video | |
| parent | 3c46f10e3d120dd76f5d3455dae710a900d68bc1 (diff) | |
Add code analysis attributes where appropriate
Diffstat (limited to 'Emby.Naming/Video')
| -rw-r--r-- | Emby.Naming/Video/CleanStringParser.cs | 15 | ||||
| -rw-r--r-- | Emby.Naming/Video/VideoResolver.cs | 3 |
2 files changed, 10 insertions, 8 deletions
diff --git a/Emby.Naming/Video/CleanStringParser.cs b/Emby.Naming/Video/CleanStringParser.cs index bd7553a91..4eef3ebc5 100644 --- a/Emby.Naming/Video/CleanStringParser.cs +++ b/Emby.Naming/Video/CleanStringParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; namespace Emby.Naming.Video @@ -16,8 +17,14 @@ namespace Emby.Naming.Video /// <param name="expressions">List of regex to parse name and year from.</param> /// <param name="newName">Parsing result string.</param> /// <returns>True if parsing was successful.</returns> - public static bool TryClean(string name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName) + public static bool TryClean([NotNullWhen(true)] string? name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName) { + if (string.IsNullOrEmpty(name)) + { + newName = ReadOnlySpan<char>.Empty; + return false; + } + var len = expressions.Count; for (int i = 0; i < len; i++) { @@ -33,12 +40,6 @@ namespace Emby.Naming.Video private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName) { - if (string.IsNullOrEmpty(name)) - { - newName = ReadOnlySpan<char>.Empty; - return false; - } - var match = expression.Match(name); int index = match.Index; if (match.Success && index != 0) diff --git a/Emby.Naming/Video/VideoResolver.cs b/Emby.Naming/Video/VideoResolver.cs index 619d1520e..79a6da8f7 100644 --- a/Emby.Naming/Video/VideoResolver.cs +++ b/Emby.Naming/Video/VideoResolver.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using Emby.Naming.Common; @@ -146,7 +147,7 @@ namespace Emby.Naming.Video /// <param name="name">Raw name.</param> /// <param name="newName">Clean name.</param> /// <returns>True if cleaning of name was successful.</returns> - public bool TryCleanString(string name, out ReadOnlySpan<char> newName) + public bool TryCleanString([NotNullWhen(true)] string? name, out ReadOnlySpan<char> newName) { return CleanStringParser.TryClean(name, _options.CleanStringRegexes, out newName); } |
