public void TestAtTagDecode(string rubyTagText, string parent, string ruby) { // Ruby tag var rubyTag = new RubyTag { Parent = parent, Ruby = ruby }; // Ruby tag component var atRubyTagComponent = new RubyTagParserComponent(null); var atTag = atRubyTagComponent.Encode(rubyTag); // At tag component var atTagComponent = new AtTagParserComponent(); var result = atTagComponent.Encode(atTag); Assert.AreEqual(result, rubyTagText); }
/// <summary> /// Encode lrc format file /// </summary> /// <param name="lyric"></param> /// <returns></returns> public override string Encode(Lyric lyric) { if (lyric == null) { return(null); } var sb = new StringBuilder(); // Get all lyric in remain text var timeTagComponent = new TimeTagParserComponent(); foreach (var line in lyric.Lines) { var lyricResult = timeTagComponent.Encode(line); //Copy result sb.AppendLine(lyricResult); } // Change new line sb.AppendLine(""); // Convert ruby into ast tag var rubyTagComponent = new RubyTagParserComponent(lyric); var atTags = lyric.RubyTags.Select(rubyTag => rubyTagComponent.Encode(rubyTag)).ToList(); // Convert at tag into string var atTagComponent = new AtTagParserComponent(); foreach (var atTagResult in atTags.Select(atTag => atTagComponent.Encode(atTag))) { //Copy result sb.AppendLine(atTagResult); } //return result return(sb.ToString()); }