[UnknownSubtitle4] - Add method to decode/encoding formatting

This commit is contained in:
Ivandro Ismael 2016-02-23 17:29:31 +00:00
parent 087d90bf07
commit d5874e3c69

View File

@ -50,7 +50,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs) foreach (Paragraph p in subtitle.Paragraphs)
{ {
string text = p.Text.Replace(Environment.NewLine, "|"); string text = EncodeFormatting(p.Text);
sb.AppendLine(string.Format(paragraphWriteFormat, sb.AppendLine(string.Format(paragraphWriteFormat,
p.StartTime.Hours, p.StartTime.Hours,
@ -115,21 +115,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
if (line.Length > 0) if (line.Length > 0)
{ {
string text = line.Replace("|", Environment.NewLine); paragraph.Text = DecodeFormatting(line);
text = line.Replace("[br]", Environment.NewLine);
text = line.Replace("<br>", Environment.NewLine);
text = line.Replace("<br />", Environment.NewLine);
text = text.Replace("{\\i1}", "<i>");
text = text.Replace("{\\i0}", "</i>");
text = text.Replace("{\\i}", "</i>");
text = text.Replace("{\\b1}", "<b>'");
text = text.Replace("{\\b0}", "</b>");
text = text.Replace("{\\b}", "</b>");
text = text.Replace("{\\u1}", "<u>");
text = text.Replace("{\\u0}", "</u>");
text = text.Replace("{\\u}", "</u>");
paragraph.Text = text;
subtitle.Paragraphs.Add(paragraph); subtitle.Paragraphs.Add(paragraph);
paragraph = new Paragraph(); paragraph = new Paragraph();
expecting = ExpectingLine.TimeCodes; expecting = ExpectingLine.TimeCodes;
@ -139,5 +125,37 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
} }
subtitle.Renumber(); subtitle.Renumber();
} }
public string DecodeFormatting(string text)
{
text = text.Replace("|", Environment.NewLine);
text = text.Replace("[br]", Environment.NewLine);
text = text.Replace("<br>", Environment.NewLine);
text = text.Replace("<br/>", Environment.NewLine);
text = text.Replace("<br />", Environment.NewLine);
text = text.Replace("{\\i1}", "<i>");
text = text.Replace("{\\i0}", "</i>");
text = text.Replace("{\\i}", "</i>");
text = text.Replace("{\\b1}", "<b>'");
text = text.Replace("{\\b0}", "</b>");
text = text.Replace("{\\b}", "</b>");
text = text.Replace("{\\u1}", "<u>");
text = text.Replace("{\\u0}", "</u>");
text = text.Replace("{\\u}", "</u>");
return text;
}
public string EncodeFormatting(string text)
{
text = text.Replace(Environment.NewLine, "|");
text = text.Replace("<i>", "{\\i1}");
text = text.Replace("</i>", "{\\i0}");
text = text.Replace("<b>", "{\\b1}");
text = text.Replace("</b>", "{\\b0}");
text = text.Replace("<u>", "{\\u1}");
text = text.Replace("</u>", "{\\u0}");
return text;
}
} }
} }