diff --git a/LrcParser.Tests/LrcParser.Tests.csproj b/LrcParser.Tests/LrcParser.Tests.csproj index 3718039..0cf3854 100644 --- a/LrcParser.Tests/LrcParser.Tests.csproj +++ b/LrcParser.Tests/LrcParser.Tests.csproj @@ -1,7 +1,8 @@ - net6.0 + net8.0 + 12.0 enable false diff --git a/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs b/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs index e51c364..27f42cd 100644 --- a/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs +++ b/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs @@ -19,9 +19,9 @@ public void TestDecode() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "帰り道は", TimeTags = new SortedDictionary @@ -33,7 +33,7 @@ public void TestDecode() { new TextIndex(3, IndexState.End), 19220 }, }, }, - }, + ], }; checkDecode(lrcText, song); @@ -52,9 +52,9 @@ public void TestDecodeWithRuby() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島", TimeTags = new SortedDictionary @@ -64,29 +64,29 @@ public void TestDecodeWithRuby() { new TextIndex(2), 3000 }, { new TextIndex(2, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "じま", StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "とう", StartCharIndex = 2, EndCharIndex = 2, }, - }, + ], }, - }, + ], }; checkDecode(lrcText, song); @@ -105,9 +105,9 @@ public void TestDecodeWithRubyAndRubyTimeTag() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島", TimeTags = new SortedDictionary @@ -117,9 +117,9 @@ public void TestDecodeWithRubyAndRubyTimeTag() { new TextIndex(2), 3000 }, { new TextIndex(2, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -129,7 +129,8 @@ public void TestDecodeWithRubyAndRubyTimeTag() StartCharIndex = 0, EndCharIndex = 0, }, - new() + + new RubyTag { Text = "じま", TimeTags = new SortedDictionary @@ -139,7 +140,8 @@ public void TestDecodeWithRubyAndRubyTimeTag() StartCharIndex = 1, EndCharIndex = 1, }, - new() + + new RubyTag { Text = "とう", TimeTags = new SortedDictionary @@ -149,9 +151,9 @@ public void TestDecodeWithRubyAndRubyTimeTag() StartCharIndex = 2, EndCharIndex = 2, }, - }, + ], }, - }, + ], }; checkDecode(lrcText, song); @@ -170,9 +172,9 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島", TimeTags = new SortedDictionary @@ -182,9 +184,9 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() { new TextIndex(2), 3000 }, { new TextIndex(2, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -194,7 +196,7 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -204,7 +206,7 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -214,9 +216,9 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 2, EndCharIndex = 2, }, - }, + ], }, - }, + ], }; checkDecode(lrcText, song); @@ -236,40 +238,40 @@ public void TestDecodeWithNoTimeRangeRuby() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "カラオケ", - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "か", StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "ら", StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "お", StartCharIndex = 2, EndCharIndex = 2, }, - new() + new RubyTag { Text = "け", StartCharIndex = 3, EndCharIndex = 3, }, - }, + ], }, - }, + ], }; checkDecode(lrcText, song); @@ -290,9 +292,9 @@ public void TestDecodeWithRubyInDifferentLine() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -300,17 +302,18 @@ public void TestDecodeWithRubyInDifferentLine() { new TextIndex(0), 1000 }, { new TextIndex(0, IndexState.End), 2000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - new() + + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -318,17 +321,18 @@ public void TestDecodeWithRubyInDifferentLine() { new TextIndex(0), 3000 }, { new TextIndex(0, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "じま", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - new() + + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -336,17 +340,17 @@ public void TestDecodeWithRubyInDifferentLine() { new TextIndex(0), 5000 }, { new TextIndex(0, IndexState.End), 6000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "とう", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - }, + ], }; checkDecode(lrcText, song); @@ -364,9 +368,9 @@ public void TestDecodeWithInvalid() var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -375,7 +379,7 @@ public void TestDecodeWithInvalid() { new TextIndex(0, IndexState.End), 2000 }, }, }, - }, + ], }; checkDecode(lrcText, song); @@ -386,9 +390,9 @@ public void TestEncode() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "帰り道は", TimeTags = new SortedDictionary @@ -400,7 +404,7 @@ public void TestEncode() { new TextIndex(3, IndexState.End), 19220 }, }, }, - }, + ], }; var lrcText = new[] @@ -416,9 +420,9 @@ public void TestEncodeWithRuby() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島", TimeTags = new SortedDictionary @@ -428,29 +432,29 @@ public void TestEncodeWithRuby() { new TextIndex(2), 3000 }, { new TextIndex(2, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "じま", StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "とう", StartCharIndex = 2, EndCharIndex = 2, }, - }, + ], }, - }, + ], }; var lrcText = new[] @@ -470,9 +474,9 @@ public void TestEncodeWithRubyAndRubyTimeTag() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島", TimeTags = new SortedDictionary @@ -482,9 +486,9 @@ public void TestEncodeWithRubyAndRubyTimeTag() { new TextIndex(2), 3000 }, { new TextIndex(2, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -494,7 +498,7 @@ public void TestEncodeWithRubyAndRubyTimeTag() StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "じま", TimeTags = new SortedDictionary @@ -504,7 +508,7 @@ public void TestEncodeWithRubyAndRubyTimeTag() StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "とう", TimeTags = new SortedDictionary @@ -514,9 +518,9 @@ public void TestEncodeWithRubyAndRubyTimeTag() StartCharIndex = 2, EndCharIndex = 2, }, - }, + ], }, - }, + ], }; var lrcText = new[] @@ -536,9 +540,9 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島島島島", TimeTags = new SortedDictionary @@ -549,9 +553,9 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() { new TextIndex(3), 4000 }, { new TextIndex(3, IndexState.End), 5000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -561,7 +565,7 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -571,7 +575,7 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -582,7 +586,7 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 2, EndCharIndex = 2, }, - new() + new RubyTag { Text = "しま", TimeTags = new SortedDictionary @@ -593,9 +597,9 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() StartCharIndex = 3, EndCharIndex = 3, }, - }, + ], }, - }, + ], }; var lrcText = new[] @@ -615,40 +619,40 @@ public void TestEncodeWithNoTimeRangeRuby() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "カラオケ", - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "か", StartCharIndex = 0, EndCharIndex = 0, }, - new() + new RubyTag { Text = "ら", StartCharIndex = 1, EndCharIndex = 1, }, - new() + new RubyTag { Text = "お", StartCharIndex = 2, EndCharIndex = 2, }, - new() + new RubyTag { Text = "け", StartCharIndex = 3, EndCharIndex = 3, }, - }, + ], }, - }, + ], }; var lrcText = new[] @@ -669,9 +673,9 @@ public void TestEncodeWithRubyInDifferentLine() { var song = new Song { - Lyrics = new List - { - new() + Lyrics = + [ + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -679,17 +683,18 @@ public void TestEncodeWithRubyInDifferentLine() { new TextIndex(0), 1000 }, { new TextIndex(0, IndexState.End), 2000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "しま", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - new() + + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -697,17 +702,18 @@ public void TestEncodeWithRubyInDifferentLine() { new TextIndex(0), 3000 }, { new TextIndex(0, IndexState.End), 4000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "じま", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - new() + + new Lyric { Text = "島", TimeTags = new SortedDictionary @@ -715,17 +721,17 @@ public void TestEncodeWithRubyInDifferentLine() { new TextIndex(0), 5000 }, { new TextIndex(0, IndexState.End), 6000 }, }, - RubyTags = new List - { - new() + RubyTags = + [ + new RubyTag { Text = "とう", StartCharIndex = 0, EndCharIndex = 0, }, - }, + ], }, - }, + ], }; var lrcText = new[] diff --git a/LrcParser.Tests/Utils/TypeUtilsTest.cs b/LrcParser.Tests/Utils/TypeUtilsTest.cs index 59eeae9..263c57b 100644 --- a/LrcParser.Tests/Utils/TypeUtilsTest.cs +++ b/LrcParser.Tests/Utils/TypeUtilsTest.cs @@ -40,7 +40,5 @@ public void TestChangeTypeToDifferentType() Assert.That(TypeUtils.ChangeType(null), Is.EqualTo(default(double?))); } - private class TestClass - { - } + private class TestClass; } diff --git a/LrcParser/LrcParser.csproj b/LrcParser/LrcParser.csproj index 8ca38bd..59537df 100644 --- a/LrcParser/LrcParser.csproj +++ b/LrcParser/LrcParser.csproj @@ -2,7 +2,7 @@ netstandard2.1 - 10.0 + 12.0 enable enable diff --git a/LrcParser/Model/Lyric.cs b/LrcParser/Model/Lyric.cs index a13c69b..e4259f1 100644 --- a/LrcParser/Model/Lyric.cs +++ b/LrcParser/Model/Lyric.cs @@ -18,5 +18,5 @@ public class Lyric /// /// Ruby tags /// - public List RubyTags { get; set; } = new(); + public List RubyTags { get; set; } = []; } diff --git a/LrcParser/Model/Song.cs b/LrcParser/Model/Song.cs index 1a5838d..68e1836 100644 --- a/LrcParser/Model/Song.cs +++ b/LrcParser/Model/Song.cs @@ -5,5 +5,5 @@ namespace LrcParser.Model; public class Song { - public List Lyrics { get; set; } = new(); + public List Lyrics { get; set; } = []; } diff --git a/LrcParser/Parser/Lines/SingleLineParser.cs b/LrcParser/Parser/Lines/SingleLineParser.cs index 644be41..82fd333 100644 --- a/LrcParser/Parser/Lines/SingleLineParser.cs +++ b/LrcParser/Parser/Lines/SingleLineParser.cs @@ -16,7 +16,13 @@ public bool CanEncode(object component) object ISingleLineParser.Decode(string text) => Decode(text); - public string Encode(object component, int index) => Encode(component as T, index); + public string Encode(object component, int index) + { + if (component is not T target) + throw new InvalidCastException(); + + return Encode(target, index); + } /// /// Decode to target class and leave remain text diff --git a/LrcParser/Parser/Lrc/Lines/LrcRubyParser.cs b/LrcParser/Parser/Lrc/Lines/LrcRubyParser.cs index 53ef629..11a0616 100644 --- a/LrcParser/Parser/Lrc/Lines/LrcRubyParser.cs +++ b/LrcParser/Parser/Lrc/Lines/LrcRubyParser.cs @@ -12,7 +12,7 @@ namespace LrcParser.Parser.Lrc.Lines; public class LrcRubyParser : SingleLineParser { public override bool CanDecode(string text) - => !string.IsNullOrEmpty(text) && text.ToLower().StartsWith("@ruby"); + => !string.IsNullOrEmpty(text) && text.ToLower().StartsWith("@ruby", StringComparison.Ordinal); public override LrcRuby Decode(string text) { diff --git a/LrcParser/Parser/LyricParser.cs b/LrcParser/Parser/LyricParser.cs index 84f8aab..72c1b1d 100644 --- a/LrcParser/Parser/LyricParser.cs +++ b/LrcParser/Parser/LyricParser.cs @@ -29,7 +29,7 @@ public Song Decode(string text) return new Song(); var lines = text.Split( - new[] { "\r\n", "\r", "\n" }, + ["\r\n", "\r", "\n"], StringSplitOptions.None ).Where(x => !string.IsNullOrWhiteSpace(x));