diff --git a/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs b/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs index cc4b6b2..ce74d18 100644 --- a/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Lines/LrcLyricParserTest.cs @@ -33,7 +33,7 @@ public void TestDecode(string lyric, string text, string[] timeTags) var expected = new LrcLyric { Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) + TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), }; var actual = Decode(lyric); @@ -51,7 +51,7 @@ public void TestEncode(string text, string[] timeTags, string expected) var lyric = new LrcLyric { Text = text, - TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) + TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), }; var actual = Encode(lyric); diff --git a/LrcParser.Tests/Parser/Lrc/Lines/LrcRubyParserTest.cs b/LrcParser.Tests/Parser/Lrc/Lines/LrcRubyParserTest.cs index 8b56263..201975d 100644 --- a/LrcParser.Tests/Parser/Lrc/Lines/LrcRubyParserTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Lines/LrcRubyParserTest.cs @@ -35,7 +35,7 @@ public void TestDecode(string rubyTag, string parent, string ruby, string[] time Ruby = ruby, TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), StartTime = startTime, - EndTime = endTime + EndTime = endTime, }; var actual = Decode(rubyTag); @@ -59,7 +59,7 @@ public void TestEncode(string parent, string ruby, string[] timeTags, int? start Ruby = ruby, TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), StartTime = startTime, - EndTime = endTime + EndTime = endTime, }; var actual = Encode(rubyTag); diff --git a/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs b/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs index 70f0d24..bf11e37 100644 --- a/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs +++ b/LrcParser.Tests/Parser/Lrc/LrcParserTest.cs @@ -14,7 +14,7 @@ public void TestDecode() { var lrcText = new[] { - "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]" + "[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", }; var song = new Song @@ -31,9 +31,9 @@ public void TestDecode() { new TextIndex(2), 18550 }, { new TextIndex(3), 18940 }, { new TextIndex(3, IndexState.End), 19220 }, - } - } - } + }, + }, + }, }; checkDecode(lrcText, song); @@ -47,7 +47,7 @@ public void TestDecodeWithRuby() "[00:01:00]島[00:02:00]島[00:03:00]島[00:04:00]", "@Ruby1=島,しま,,[00:02:00]", "@Ruby2=島,じま,[00:02:00],[00:03:00]", - "@Ruby3=島,とう,[00:03:00]" + "@Ruby3=島,とう,[00:03:00]", }; var song = new Song @@ -70,23 +70,23 @@ public void TestDecodeWithRuby() { Text = "しま", StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "じま", StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "とう", StartCharIndex = 2, - EndCharIndex = 2 - } - } + EndCharIndex = 2, + }, + }, }, - } + }, }; checkDecode(lrcText, song); @@ -100,7 +100,7 @@ public void TestDecodeWithRubyAndRubyTimeTag() "[00:01:00]島[00:02:00]島[00:03:00]島[00:04:00]", "@Ruby1=島,し[00:00:50]ま,,[00:02:00]", "@Ruby2=島,じ[00:00:50]ま,[00:02:00],[00:03:00]", - "@Ruby3=島,と[00:00:50]う,[00:03:00]" + "@Ruby3=島,と[00:00:50]う,[00:03:00]", }; var song = new Song @@ -124,34 +124,34 @@ public void TestDecodeWithRubyAndRubyTimeTag() Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 1500 } + { new TextIndex(1), 1500 }, }, StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "じま", TimeTags = new SortedDictionary { - { new TextIndex(1), 2500 } + { new TextIndex(1), 2500 }, }, StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "とう", TimeTags = new SortedDictionary { - { new TextIndex(1), 3500 } + { new TextIndex(1), 3500 }, }, StartCharIndex = 2, - EndCharIndex = 2 - } - } + EndCharIndex = 2, + }, + }, }, - } + }, }; checkDecode(lrcText, song); @@ -165,7 +165,7 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() "[00:01:00]島[00:02:00]島[00:03:00]島[00:04:00]", "@Ruby1=島,し[00:00:40]ま,,[00:02:00]", "@Ruby2=島,し[00:00:50]ま,[00:02:00],[00:03:00]", - "@Ruby3=島,し[00:00:60]ま,[00:03:00]" + "@Ruby3=島,し[00:00:60]ま,[00:03:00]", }; var song = new Song @@ -189,34 +189,34 @@ public void TestDecodeWithSameRubyWithDifferentRubyTimeTag() Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 1400 } + { new TextIndex(1), 1400 }, }, StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 2500 } + { new TextIndex(1), 2500 }, }, StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 3600 } + { new TextIndex(1), 3600 }, }, StartCharIndex = 2, - EndCharIndex = 2 - } - } + EndCharIndex = 2, + }, + }, }, - } + }, }; checkDecode(lrcText, song); @@ -231,7 +231,7 @@ public void TestDecodeWithNoTimeRangeRuby() "@Ruby1=カ,か", "@Ruby2=ラ,ら", "@Ruby3=オ,お", - "@Ruby4=ケ,け" + "@Ruby4=ケ,け", }; var song = new Song @@ -247,29 +247,29 @@ public void TestDecodeWithNoTimeRangeRuby() { Text = "か", StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "ら", StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "お", StartCharIndex = 2, - EndCharIndex = 2 + EndCharIndex = 2, }, new() { Text = "け", StartCharIndex = 3, - EndCharIndex = 3 - } - } + EndCharIndex = 3, + }, + }, }, - } + }, }; checkDecode(lrcText, song); @@ -285,7 +285,7 @@ public void TestDecodeWithRubyInDifferentLine() "[00:05:00]島[00:06:00]", "@Ruby1=島,しま,,[00:02:00]", "@Ruby2=島,じま,[00:03:00],[00:04:00]", - "@Ruby3=島,とう,[00:05:00]" + "@Ruby3=島,とう,[00:05:00]", }; var song = new Song @@ -306,9 +306,9 @@ public void TestDecodeWithRubyInDifferentLine() { Text = "しま", StartCharIndex = 0, - EndCharIndex = 0 - } - } + EndCharIndex = 0, + }, + }, }, new() { @@ -324,9 +324,9 @@ public void TestDecodeWithRubyInDifferentLine() { Text = "じま", StartCharIndex = 0, - EndCharIndex = 0 - } - } + EndCharIndex = 0, + }, + }, }, new() { @@ -342,11 +342,11 @@ public void TestDecodeWithRubyInDifferentLine() { Text = "とう", StartCharIndex = 0, - EndCharIndex = 0 - } - } - } - } + EndCharIndex = 0, + }, + }, + }, + }, }; checkDecode(lrcText, song); @@ -359,7 +359,7 @@ public void TestDecodeWithInvalid() var lrcText = new[] { "[00:01:00]島[00:02:00]", - "@Ruby1=島,島" + "@Ruby1=島,島", }; var song = new Song @@ -375,7 +375,7 @@ public void TestDecodeWithInvalid() { new TextIndex(0, IndexState.End), 2000 }, }, }, - } + }, }; checkDecode(lrcText, song); @@ -398,14 +398,14 @@ public void TestEncode() { new TextIndex(2), 18550 }, { new TextIndex(3), 18940 }, { new TextIndex(3, IndexState.End), 19220 }, - } - } - } + }, + }, + }, }; var lrcText = new[] { - "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]" + "[00:17.97]帰[00:18.37]り[00:18.55]道[00:18.94]は[00:19.22]", }; checkEncode(song, lrcText); @@ -434,23 +434,23 @@ public void TestEncodeWithRuby() { Text = "しま", StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "じま", StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "とう", StartCharIndex = 2, - EndCharIndex = 2 - } - } + EndCharIndex = 2, + }, + }, }, - } + }, }; var lrcText = new[] @@ -459,7 +459,7 @@ public void TestEncodeWithRuby() "", "@Ruby1=島,しま,,[00:02.00]", "@Ruby2=島,じま,[00:02.00],[00:03.00]", - "@Ruby3=島,とう,[00:03.00]" + "@Ruby3=島,とう,[00:03.00]", }; checkEncode(song, lrcText); @@ -489,34 +489,34 @@ public void TestEncodeWithRubyAndRubyTimeTag() Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 1500 } + { new TextIndex(1), 1500 }, }, StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "じま", TimeTags = new SortedDictionary { - { new TextIndex(1), 2500 } + { new TextIndex(1), 2500 }, }, StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "とう", TimeTags = new SortedDictionary { - { new TextIndex(1), 3500 } + { new TextIndex(1), 3500 }, }, StartCharIndex = 2, - EndCharIndex = 2 - } - } + EndCharIndex = 2, + }, + }, }, - } + }, }; var lrcText = new[] @@ -525,7 +525,7 @@ public void TestEncodeWithRubyAndRubyTimeTag() "", "@Ruby1=島,し[00:00.50]ま,,[00:02.00]", "@Ruby2=島,じ[00:00.50]ま,[00:02.00],[00:03.00]", - "@Ruby3=島,と[00:00.50]う,[00:03.00]" + "@Ruby3=島,と[00:00.50]う,[00:03.00]", }; checkEncode(song, lrcText); @@ -556,20 +556,20 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 1400 } + { new TextIndex(1), 1400 }, }, StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "しま", TimeTags = new SortedDictionary { - { new TextIndex(1), 2500 } + { new TextIndex(1), 2500 }, }, StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { @@ -577,10 +577,10 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() TimeTags = new SortedDictionary { // will merge with second time-tag - { new TextIndex(1), 3500 } + { new TextIndex(1), 3500 }, }, StartCharIndex = 2, - EndCharIndex = 2 + EndCharIndex = 2, }, new() { @@ -588,14 +588,14 @@ public void TestEncodeWithSameRubyWithDifferentRubyTimeTag() TimeTags = new SortedDictionary { // although the relative time is same as the first time-tag, but might not be able to merge. - { new TextIndex(1), 4400 } + { new TextIndex(1), 4400 }, }, StartCharIndex = 3, - EndCharIndex = 3 - } - } + EndCharIndex = 3, + }, + }, }, - } + }, }; var lrcText = new[] @@ -626,29 +626,29 @@ public void TestEncodeWithNoTimeRangeRuby() { Text = "か", StartCharIndex = 0, - EndCharIndex = 0 + EndCharIndex = 0, }, new() { Text = "ら", StartCharIndex = 1, - EndCharIndex = 1 + EndCharIndex = 1, }, new() { Text = "お", StartCharIndex = 2, - EndCharIndex = 2 + EndCharIndex = 2, }, new() { Text = "け", StartCharIndex = 3, - EndCharIndex = 3 - } - } + EndCharIndex = 3, + }, + }, }, - } + }, }; var lrcText = new[] @@ -658,7 +658,7 @@ public void TestEncodeWithNoTimeRangeRuby() "@Ruby1=カ,か", "@Ruby2=ラ,ら", "@Ruby3=オ,お", - "@Ruby4=ケ,け" + "@Ruby4=ケ,け", }; checkEncode(song, lrcText); @@ -685,9 +685,9 @@ public void TestEncodeWithRubyInDifferentLine() { Text = "しま", StartCharIndex = 0, - EndCharIndex = 0 - } - } + EndCharIndex = 0, + }, + }, }, new() { @@ -703,9 +703,9 @@ public void TestEncodeWithRubyInDifferentLine() { Text = "じま", StartCharIndex = 0, - EndCharIndex = 0 - } - } + EndCharIndex = 0, + }, + }, }, new() { @@ -721,11 +721,11 @@ public void TestEncodeWithRubyInDifferentLine() { Text = "とう", StartCharIndex = 0, - EndCharIndex = 0 - } - } - } - } + EndCharIndex = 0, + }, + }, + }, + }, }; var lrcText = new[] @@ -734,7 +734,7 @@ public void TestEncodeWithRubyInDifferentLine() "", "@Ruby1=島,しま,,[00:02.00]", "@Ruby2=島,じま,[00:03.00],[00:04.00]", - "@Ruby3=島,とう,[00:05.00]" + "@Ruby3=島,とう,[00:05.00]", }; checkEncode(song, lrcText); @@ -747,7 +747,7 @@ public void TestEncodeWithEmptyFile() var lrcText = new[] { - "" + "", }; checkEncode(song, lrcText); diff --git a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs index 6111bc3..8b26b74 100644 --- a/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs +++ b/LrcParser.Tests/Parser/Lrc/Utils/LrcTimedTextUtilsTest.cs @@ -15,7 +15,7 @@ public class LrcTimedTextUtilsTest [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22] ", "帰り道は ", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] [TestCase("帰[00:18:37]り[00:18:55]道[00:18:94]は[00:19:22]", "帰り道は", new[] { "[1,start]:18370", "[2,start]:18550", "[3,start]:18940", "[3,end]:19220" })] [TestCase("[00:17:97]帰[00:18:37]り[00:18:55]道[00:18:94]は", "帰り道は", new[] { "[0,start]:17970", "[1,start]:18370", "[2,start]:18550", "[3,start]:18940" })] - [TestCase("[00:51.00][01:29.99][01:48.29][02:31.00][02:41.99]You gotta fight !", "You gotta fight !", new string[] { "[0,start]:51000" })] // decode with invalid format. + [TestCase("[00:51.00][01:29.99][01:48.29][02:31.00][02:41.99]You gotta fight !", "You gotta fight !", new[] { "[0,start]:51000" })] // decode with invalid format. [TestCase("帰り道は", "帰り道は", new string[] { })] [TestCase("", "", new string[] { })] [TestCase(null, "", new string[] { })] diff --git a/LrcParser.Tests/Parser/LyricParserTest.cs b/LrcParser.Tests/Parser/LyricParserTest.cs index 050af22..d054498 100644 --- a/LrcParser.Tests/Parser/LyricParserTest.cs +++ b/LrcParser.Tests/Parser/LyricParserTest.cs @@ -52,7 +52,7 @@ protected override Song PostProcess(List values) Lyrics = lines.Select(l => new Lyric { Text = l, - }).ToList() + }).ToList(), }; } diff --git a/LrcParser/Extension/EnumerableExtensions.cs b/LrcParser/Extension/EnumerableExtensions.cs index 1cf406c..4fbec24 100644 --- a/LrcParser/Extension/EnumerableExtensions.cs +++ b/LrcParser/Extension/EnumerableExtensions.cs @@ -42,6 +42,8 @@ public static IEnumerable> GroupByContinuous values) { Text = l.Text, TimeTags = getTimeTags(l.TimeTags), - RubyTags = getRubyTags(rubies, l).ToList() - }).ToList() + RubyTags = getRubyTags(rubies, l).ToList(), + }).ToList(), }; static IEnumerable getRubyTags(IEnumerable rubyTags, LrcLyric lyric) @@ -68,7 +68,7 @@ static IEnumerable getRubyTags(IEnumerable rubyTags, LrcLyric Text = rubyTag.Ruby, TimeTags = getTimeTags(rubyTag.TimeTags, startTimeTag.Value), StartCharIndex = startLyricCharIndex, - EndCharIndex = endLyricCharIndex + EndCharIndex = endLyricCharIndex, }; } else @@ -85,7 +85,7 @@ static IEnumerable getRubyTags(IEnumerable rubyTags, LrcLyric Text = rubyTag.Ruby, TimeTags = getTimeTags(rubyTag.TimeTags, startTimeTag.Value), StartCharIndex = convertStartTextIndexToCharIndex(startTimeTag.Key), - EndCharIndex = convertEndTextIndexToCharIndex(endTimeTag.Key) + EndCharIndex = convertEndTextIndexToCharIndex(endTimeTag.Key), }; } } @@ -102,7 +102,7 @@ static int convertEndTextIndexToCharIndex(TextIndex textIndex) => { IndexState.Start => textIndex.Index - 1, IndexState.End => textIndex.Index, - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException(), }; } @@ -136,7 +136,7 @@ protected override IEnumerable PreProcess(Song song) .GroupByContinuous(x => new RubyGroup { Ruby = x.Ruby, - TimeTags = x.TimeTags + TimeTags = x.TimeTags, }).ToList(); // then, combine those continuous ruby. @@ -159,11 +159,13 @@ protected override IEnumerable PreProcess(Song song) Parent = parent, TimeTags = timeTags, StartTime = minStartTime, - EndTime = maxEndTime + EndTime = maxEndTime, }; } } + yield break; + static IEnumerable getRubyTags(Lyric lyric) { var timeTags = lyric.TimeTags; diff --git a/LrcParser/Parser/Lrc/Utils/TimeTagUtils.cs b/LrcParser/Parser/Lrc/Utils/TimeTagUtils.cs index 7944474..e9d801b 100644 --- a/LrcParser/Parser/Lrc/Utils/TimeTagUtils.cs +++ b/LrcParser/Parser/Lrc/Utils/TimeTagUtils.cs @@ -36,6 +36,7 @@ internal static int TimeTagToMillionSecond(string timeTag) { if (timeTag.Length < 10 || timeTag[0] != '[' || !char.IsDigit(timeTag[1])) return -1; + int minute = int.Parse(timeTag.Substring(1, 2)); int second = int.Parse(timeTag.Substring(4, 2)); int millionSecond = int.Parse(timeTag.Substring(7, 2)); diff --git a/LrcParser/Utils/TextIndexUtils.cs b/LrcParser/Utils/TextIndexUtils.cs index 57530d5..a8e130e 100644 --- a/LrcParser/Utils/TextIndexUtils.cs +++ b/LrcParser/Utils/TextIndexUtils.cs @@ -42,6 +42,6 @@ internal static T GetValueByState(TextIndex index, T startValue, T endValue) { IndexState.Start => startValue, IndexState.End => endValue, - _ => throw new ArgumentOutOfRangeException(nameof(index)) + _ => throw new ArgumentOutOfRangeException(nameof(index)), }; }