ZonyLrcToolsX/src/ZonyLrcTools.Cli/Infrastructure/Lyric/LyricItemCollectionFactory.cs
real-zony 6ec03d0ec3 docs: Improve the comment of the code.
改进代码的注释。
2021-05-07 10:57:08 +08:00

37 lines
1.1 KiB
C#

using System.Text.RegularExpressions;
using Microsoft.Extensions.Options;
using ZonyLrcTools.Cli.Config;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
namespace ZonyLrcTools.Cli.Infrastructure.Lyric
{
/// <summary>
/// <see cref="ILyricItemCollectionFactory"/> 的默认实现。
/// </summary>
public class LyricItemCollectionFactory : ILyricItemCollectionFactory, ITransientDependency
{
private readonly ToolOptions _options;
public LyricItemCollectionFactory(IOptions<ToolOptions> options)
{
_options = options.Value;
}
public LyricItemCollection Build(string sourceLyric, string translateLyric = null)
{
var items = new LyricItemCollection(_options.LyricOption);
if (string.IsNullOrEmpty(sourceLyric))
{
return items;
}
var regex = new Regex(@"\[\d+:\d+.\d+\].+\n?");
foreach (Match match in regex.Matches(sourceLyric))
{
items.Add(new LyricItem(match.Value));
}
return items;
}
}
}