本文整理汇总了C#中ExpectingLine类的典型用法代码示例。如果您正苦于以下问题:C# ExpectingLine类的具体用法?C# ExpectingLine怎么用?C# ExpectingLine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExpectingLine类属于命名空间,在下文中一共展示了ExpectingLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
bool doRenum = false;
_errors = new StringBuilder();
_lineNumber = 0;
_isMsFrames = true;
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
_errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i = 0; i < lines.Count; i++)
{
_lineNumber++;
string line = lines[i].TrimEnd();
line = line.Trim('\u007F'); // 127=delete acscii
string next = string.Empty;
if (i + 1 < lines.Count)
next = lines[i + 1];
string nextNext = string.Empty;
if (i + 2 < lines.Count)
nextNext = lines[i + 2];
// A new line is missing between two paragraphs (buggy srt file)
if (_expecting == ExpectingLine.Text && i + 1 < lines.Count &&
_paragraph != null && !string.IsNullOrEmpty(_paragraph.Text) && Utilities.IsInteger(line) &&
RegexTimeCodes.IsMatch(lines[i + 1]))
{
ReadLine(subtitle, string.Empty, string.Empty, string.Empty);
}
if (_expecting == ExpectingLine.Number && RegexTimeCodes.IsMatch(line))
{
_expecting = ExpectingLine.TimeCodes;
doRenum = true;
}
ReadLine(subtitle, line, next, nextNext);
}
if (_paragraph != null && _paragraph.EndTime.TotalMilliseconds > _paragraph.StartTime.TotalMilliseconds)
subtitle.Paragraphs.Add(_paragraph);
if (doRenum)
subtitle.Renumber();
if (_isMsFrames)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
p.StartTime.Milliseconds = FramesToMillisecondsMax999(p.StartTime.Milliseconds);
p.EndTime.Milliseconds = FramesToMillisecondsMax999(p.EndTime.Milliseconds);
}
}
Errors = _errors.ToString();
}
示例2: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
bool doRenum = false;
_errors = new StringBuilder();
_lineNumber = 0;
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
_errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i=0; i<lines.Count; i++)
{
_lineNumber++;
string line = lines[i].TrimEnd();
line = line.Trim(Convert.ToChar(127)); // 127=delete acscii
string next = string.Empty;
if (i + 1 < lines.Count)
next = lines[i + 1];
string nextNext = string.Empty;
if (i + 2 < lines.Count)
nextNext = lines[i + 2];
// A new line is missing between two paragraphs (buggy srt file)
if (_expecting == ExpectingLine.Text && i + 1 < lines.Count &&
_paragraph != null && !string.IsNullOrEmpty(_paragraph.Text) && Utilities.IsInteger(line) &&
_regexTimeCodes.IsMatch(lines[i+1]))
{
ReadLine(subtitle, string.Empty, string.Empty, string.Empty);
}
if (_expecting == ExpectingLine.Number && _regexTimeCodes.IsMatch(line))
{
_expecting = ExpectingLine.TimeCodes;
doRenum = true;
}
ReadLine(subtitle, line, next, nextNext);
}
if (_paragraph.Text.Trim().Length > 0)
subtitle.Paragraphs.Add(_paragraph);
foreach (Paragraph p in subtitle.Paragraphs)
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
if (doRenum)
subtitle.Renumber(1);
Errors = _errors.ToString();
}
示例3: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
ReadLine(subtitle, line);
}
if (_paragraph.Text.Trim().Length > 0)
subtitle.Paragraphs.Add(_paragraph);
subtitle.Renumber(1);
}
示例4: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
ReadLine(subtitle, line);
}
if (!string.IsNullOrWhiteSpace(_paragraph.Text))
subtitle.Paragraphs.Add(_paragraph);
subtitle.Renumber();
}
示例5: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
// 0:00:07.500,0:00:13.500
// In den Bergen über Musanze in Ruanda feiert die Trustbank (Kreditnehmer-Gruppe) "Trususanze" ihren Erfolg.
// 0:00:14.000,0:00:17.000
// Indem sie ihre Zukunft einander anvertraut haben, haben sie sich
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.TimeCodes;
this._errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i = 0; i < lines.Count; i++)
{
string line = lines[i].TrimEnd();
string next = string.Empty;
if (i + 1 < lines.Count)
{
next = lines[i + 1];
}
// A new line is missing between two paragraphs (buggy srt file)
if (this._expecting == ExpectingLine.Text && i + 1 < lines.Count && this._paragraph != null && !string.IsNullOrEmpty(this._paragraph.Text) && RegexTimeCodes.IsMatch(lines[i]))
{
this.ReadLine(subtitle, string.Empty, string.Empty);
}
this.ReadLine(subtitle, line, next);
}
if (!string.IsNullOrWhiteSpace(this._paragraph.Text))
{
subtitle.Paragraphs.Add(this._paragraph);
}
foreach (Paragraph p in subtitle.Paragraphs)
{
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
subtitle.Renumber();
}
示例6: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.TimeCodes;
this._errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
this.ReadLine(subtitle, line);
}
if (!string.IsNullOrWhiteSpace(this._text.ToString()))
{
this._paragraph.Text = this._text.ToString().Trim();
subtitle.Paragraphs.Add(this._paragraph);
}
subtitle.Renumber();
}
示例7: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_paragraph = new Paragraph();
_expecting = ExpectingLine.TimeCodes;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
ReadLine(subtitle, line);
if (_text.Length > 1000)
return;
}
if (_text != null && _text.ToString().TrimStart().Length > 0)
{
_paragraph.Text = _text.ToString().Trim();
subtitle.Paragraphs.Add(_paragraph);
}
subtitle.Renumber();
}
示例8: ReadLine
/// <summary>
/// The read line.
/// </summary>
/// <param name="subtitle">
/// The subtitle.
/// </param>
/// <param name="line">
/// The line.
/// </param>
/// <param name="next">
/// The next.
/// </param>
private void ReadLine(Subtitle subtitle, string line, string next)
{
switch (this._expecting)
{
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, this._paragraph))
{
this._paragraph.Text = string.Empty;
this._expecting = ExpectingLine.Text;
}
else if (!string.IsNullOrWhiteSpace(line))
{
this._errorCount++;
}
break;
case ExpectingLine.Text:
if (!string.IsNullOrWhiteSpace(line))
{
if (this._paragraph.Text.Length > 0)
{
this._paragraph.Text += Environment.NewLine;
}
this._paragraph.Text += RemoveBadChars(line).TrimEnd();
}
else if (IsText(next))
{
if (this._paragraph.Text.Length > 0)
{
this._paragraph.Text += Environment.NewLine;
}
this._paragraph.Text += RemoveBadChars(line).TrimEnd();
}
else
{
subtitle.Paragraphs.Add(this._paragraph);
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.TimeCodes;
}
break;
}
}
示例9: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
bool doRenum = false;
this._errors = new StringBuilder();
this._lineNumber = 0;
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.Number;
this._errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i = 0; i < lines.Count; i++)
{
this._lineNumber++;
string line = lines[i].TrimEnd();
line = line.Trim('\u007F'); // 127=delete acscii
string next = string.Empty;
if (i + 1 < lines.Count)
{
next = lines[i + 1];
}
string nextNext = string.Empty;
if (i + 2 < lines.Count)
{
nextNext = lines[i + 2];
}
// A new line is missing between two paragraphs (buggy srt file)
if (this._expecting == ExpectingLine.Text && i + 1 < lines.Count && this._paragraph != null && !string.IsNullOrEmpty(this._paragraph.Text) && Utilities.IsInteger(line) && _regexTimeCodes.IsMatch(lines[i + 1]))
{
this.ReadLine(subtitle, string.Empty, string.Empty, string.Empty);
}
if (this._expecting == ExpectingLine.Number && _regexTimeCodes.IsMatch(line))
{
this._expecting = ExpectingLine.TimeCodes;
doRenum = true;
}
this.ReadLine(subtitle, line, next, nextNext);
}
if (this._paragraph.EndTime.TotalMilliseconds > this._paragraph.StartTime.TotalMilliseconds)
{
subtitle.Paragraphs.Add(this._paragraph);
}
foreach (Paragraph p in subtitle.Paragraphs)
{
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
if (doRenum)
{
subtitle.Renumber();
}
this.Errors = this._errors.ToString();
}
示例10: ReadLine
private void ReadLine(Subtitle subtitle, string line, string next, string nextNext)
{
switch (this._expecting)
{
case ExpectingLine.Number:
int number;
if (int.TryParse(line, out number))
{
this._paragraph.Number = number;
this._expecting = ExpectingLine.TimeCodes;
}
else if (!string.IsNullOrWhiteSpace(line))
{
if (this._lastParagraph != null && nextNext != null && (this._lastParagraph.Number + 1).ToString(CultureInfo.InvariantCulture) == nextNext)
{
this._lastParagraph.Text = (this._lastParagraph.Text + Environment.NewLine + line.Trim()).Trim();
}
else
{
if (this._errors.Length < 2000)
{
this._errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXExpectedNumberFromSourceLineY, this._lineNumber, line));
}
this._errorCount++;
}
}
break;
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, this._paragraph))
{
this._paragraph.Text = string.Empty;
this._expecting = ExpectingLine.Text;
}
else if (!string.IsNullOrWhiteSpace(line))
{
if (this._errors.Length < 2000)
{
this._errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXErrorReadingTimeCodeFromSourceLineY, this._lineNumber, line));
}
this._errorCount++;
this._expecting = ExpectingLine.Number; // lets go to next paragraph
}
break;
case ExpectingLine.Text:
if (!string.IsNullOrWhiteSpace(line))
{
if (this._paragraph.Text.Length > 0)
{
this._paragraph.Text += Environment.NewLine;
}
this._paragraph.Text += RemoveBadChars(line).TrimEnd().Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
else if (IsText(next))
{
if (this._paragraph.Text.Length > 0)
{
this._paragraph.Text += Environment.NewLine;
}
this._paragraph.Text += RemoveBadChars(line).TrimEnd().Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
else if (string.IsNullOrEmpty(line) && string.IsNullOrEmpty(this._paragraph.Text))
{
this._paragraph.Text = string.Empty;
if (!string.IsNullOrEmpty(next) && (Utilities.IsInteger(next) || _regexTimeCodes.IsMatch(next)))
{
subtitle.Paragraphs.Add(this._paragraph);
this._lastParagraph = this._paragraph;
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.Number;
}
}
else
{
subtitle.Paragraphs.Add(this._paragraph);
this._lastParagraph = this._paragraph;
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.Number;
}
break;
}
}
示例11: ReadLine
/// <summary>
/// The read line.
/// </summary>
/// <param name="subtitle">
/// The subtitle.
/// </param>
/// <param name="line">
/// The line.
/// </param>
private void ReadLine(Subtitle subtitle, string line)
{
switch (this._expecting)
{
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, this._paragraph))
{
this._text = new StringBuilder();
this._expecting = ExpectingLine.BlankBeforeText;
}
else if (!string.IsNullOrWhiteSpace(line))
{
this._errorCount++;
}
break;
case ExpectingLine.BlankBeforeText:
if (string.IsNullOrWhiteSpace(line))
{
this._text = new StringBuilder();
this._expecting = ExpectingLine.Text;
}
else
{
this._errorCount++;
this._expecting = ExpectingLine.Text; // lets go to next paragraph
}
break;
case ExpectingLine.Text:
if (!string.IsNullOrWhiteSpace(line))
{
this._text.AppendLine(line.TrimEnd());
}
else
{
this._paragraph.Text = this._text.ToString().Trim();
subtitle.Paragraphs.Add(this._paragraph);
this._paragraph = new Paragraph();
this._expecting = ExpectingLine.TimeCodes;
this._text = new StringBuilder();
}
break;
}
}
示例12: ReadLine
private void ReadLine(Subtitle subtitle, string line)
{
switch (_expecting)
{
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, _paragraph))
{
_text = new StringBuilder();
_expecting = ExpectingLine.Text;
}
else if (!string.IsNullOrWhiteSpace(line))
{
_errorCount++;
_expecting = ExpectingLine.Text; // lets go to next paragraph
}
break;
case ExpectingLine.Text:
if (!string.IsNullOrWhiteSpace(line))
{
_text.AppendLine(line.TrimEnd());
}
else if (_paragraph != null && _paragraph.EndTime.TotalMilliseconds > 0)
{
_paragraph.Text = _text.ToString().Trim();
subtitle.Paragraphs.Add(_paragraph);
_paragraph = new Paragraph();
_expecting = ExpectingLine.TimeCodes;
}
else
{
_errorCount++;
}
break;
}
}
示例13: ReadLine
private void ReadLine(Subtitle subtitle, string line, string next)
{
switch (_expecting)
{
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, _paragraph))
{
_paragraph.Text = string.Empty;
_expecting = ExpectingLine.Text;
}
else if (line.Trim().Length > 0)
{
_errorCount++;
_expecting = ExpectingLine.TimeCodes; // lets go to next paragraph
}
break;
case ExpectingLine.Text:
if (line.Trim().Length > 0)
{
if (_paragraph.Text.Length > 0)
_paragraph.Text += Environment.NewLine;
_paragraph.Text += RemoveBadChars(line).TrimEnd();
}
else if (IsText(next))
{
if (_paragraph.Text.Length > 0)
_paragraph.Text += Environment.NewLine;
_paragraph.Text += RemoveBadChars(line).TrimEnd();
}
else
{
subtitle.Paragraphs.Add(_paragraph);
_paragraph = new Paragraph();
_expecting = ExpectingLine.TimeCodes;
}
break;
}
}
示例14: ReadLine
private void ReadLine(Subtitle subtitle, string line)
{
//Subtitle number: 1
//Start time (or frames): 00:00:48,862:0000001222
//End time (or frames): 00:00:50,786:0000001270
//Subtitle text: In preajma lacului Razel,
switch (_expecting)
{
case ExpectingLine.Number:
if (line.StartsWith("Subtitle number: "))
{
_expecting = ExpectingLine.StartTime;
}
break;
case ExpectingLine.StartTime:
if (line.StartsWith("Start time (or frames): "))
{
TryReadTimeCodesLine(line.Substring(23), _paragraph, true);
_expecting = ExpectingLine.EndTime;
}
break;
case ExpectingLine.EndTime:
if (line.StartsWith("End time (or frames): "))
{
TryReadTimeCodesLine(line.Substring(21), _paragraph, false);
_expecting = ExpectingLine.Text;
}
break;
case ExpectingLine.Text:
if (line.StartsWith("Subtitle text: "))
{
string text = line.Substring(14).Trim();
text = text.Replace("|", Environment.NewLine);
_paragraph.Text = text;
subtitle.Paragraphs.Add(_paragraph);
_paragraph = new Paragraph();
_expecting = ExpectingLine.Number;
}
break;
}
}
示例15: ReadLine
private void ReadLine(Subtitle subtitle, string line)
{
switch (_expecting)
{
case ExpectingLine.TimeCodes:
if (TryReadTimeCodesLine(line, _paragraph))
{
_text = new StringBuilder();
_expecting = ExpectingLine.BlankBeforeText;
}
else if (line.Trim().Length > 0)
{
_errorCount++;
}
break;
case ExpectingLine.BlankBeforeText:
if (line.Trim().Length == 0)
{
_text = new StringBuilder();
_expecting = ExpectingLine.Text;
}
else
{
_errorCount++;
_expecting = ExpectingLine.Text; // lets go to next paragraph
}
break;
case ExpectingLine.Text:
if (line.Trim().Length > 0)
{
_text.AppendLine(line.TrimEnd());
}
else
{
_paragraph.Text = _text.ToString().Trim();
subtitle.Paragraphs.Add(_paragraph);
_paragraph = new Paragraph();
_expecting = ExpectingLine.TimeCodes;
_text = new StringBuilder();
}
break;
}
}