mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
[MacSub] - Fix typos + more optimization.
This commit is contained in:
parent
1f6cb847e6
commit
8a62a082b9
@ -68,8 +68,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
switch (expecting)
|
||||
{
|
||||
case Expecting.StartFrame:
|
||||
// 10 = length of int.MaxValues (2147483647); +1 = if contain '/'
|
||||
if (line.Length <= 10 + 1 && (CharUtils.IsDigit(line[0]) || line[0] == '/'))
|
||||
if (ContainsOnlyNumber(line))
|
||||
{
|
||||
p.StartFrame = int.Parse(line.TrimStart(trimChar));
|
||||
expecting = Expecting.Text;
|
||||
@ -92,11 +91,18 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
break;
|
||||
|
||||
case Expecting.EndFrame:
|
||||
p.EndFrame = int.Parse(line.TrimStart(trimChar));
|
||||
subtitle.Paragraphs.Add(p);
|
||||
// Prepare for next reading.
|
||||
p = new Paragraph();
|
||||
expecting = Expecting.StartFrame;
|
||||
if (ContainsOnlyNumber(line))
|
||||
{
|
||||
p.EndFrame = int.Parse(line.TrimStart(trimChar));
|
||||
subtitle.Paragraphs.Add(p);
|
||||
// Prepare for next reading.
|
||||
p = new Paragraph();
|
||||
expecting = Expecting.StartFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -122,5 +128,20 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static bool ContainsOnlyNumber(string inp)
|
||||
{
|
||||
int len = inp.Length;
|
||||
// 10 = length of int.MaxValue (2147483647); +1 if starts with '/'
|
||||
if (len == 0 || len > 11 || inp[0] != '/')
|
||||
return false;
|
||||
int halfLen = len / 2;
|
||||
for (int i = 1; i <= halfLen; i++) // /10.0 (Do not parse double)
|
||||
{
|
||||
if (!(CharUtils.IsDigit(inp[i]) && CharUtils.IsDigit(inp[len - i])))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user