mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Minor fixes for json
This commit is contained in:
parent
d490604d33
commit
8fcf78f908
@ -100,7 +100,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach (string s in lines)
|
foreach (string s in lines)
|
||||||
sb.Append(s);
|
sb.Append(s);
|
||||||
if (!sb.ToString().TrimStart().StartsWith("[{\"start"))
|
if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
||||||
@ -145,6 +145,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly char[] CommaAndEndCurlyBracket = { ',', '}' };
|
||||||
|
|
||||||
public static string ReadTag(string s, string tag)
|
public static string ReadTag(string s, string tag)
|
||||||
{
|
{
|
||||||
var startIndex = s.IndexOfAny(new[] { "\"" + tag + "\"", "'" + tag + "'" }, StringComparison.Ordinal);
|
var startIndex = s.IndexOfAny(new[] { "\"" + tag + "\"", "'" + tag + "'" }, StringComparison.Ordinal);
|
||||||
@ -153,7 +155,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
var res = s.Substring(startIndex + 3 + tag.Length).Trim().TrimStart(':').TrimStart();
|
var res = s.Substring(startIndex + 3 + tag.Length).Trim().TrimStart(':').TrimStart();
|
||||||
if (res.StartsWith('"'))
|
if (res.StartsWith('"'))
|
||||||
{ // text
|
{ // text
|
||||||
res = Json.ConvertJsonSpecialCharacters(res);
|
res = ConvertJsonSpecialCharacters(res);
|
||||||
res = res.Replace("\\\"", "@__1");
|
res = res.Replace("\\\"", "@__1");
|
||||||
int endIndex = res.IndexOf("\"}", StringComparison.Ordinal);
|
int endIndex = res.IndexOf("\"}", StringComparison.Ordinal);
|
||||||
int endAlternate = res.IndexOf("\",", StringComparison.Ordinal);
|
int endAlternate = res.IndexOf("\",", StringComparison.Ordinal);
|
||||||
@ -169,7 +171,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // number
|
{ // number
|
||||||
var endIndex = res.IndexOfAny(new[] { ',', '}' });
|
var endIndex = res.IndexOfAny(CommaAndEndCurlyBracket);
|
||||||
if (endIndex < 0)
|
if (endIndex < 0)
|
||||||
return null;
|
return null;
|
||||||
return res.Substring(0, endIndex);
|
return res.Substring(0, endIndex);
|
||||||
|
@ -56,7 +56,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach (string s in lines)
|
foreach (string s in lines)
|
||||||
sb.Append(s);
|
sb.Append(s);
|
||||||
if (!sb.ToString().TrimStart().StartsWith("[{\"startMillis"))
|
if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
||||||
|
@ -57,7 +57,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
foreach (string s in lines)
|
foreach (string s in lines)
|
||||||
sb.Append(s);
|
sb.Append(s);
|
||||||
int startIndex = sb.ToString().IndexOf("[{\"duration", StringComparison.Ordinal);
|
int startIndex = sb.ToString().IndexOf("[{\"", StringComparison.Ordinal);
|
||||||
if (startIndex < 0)
|
if (startIndex < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
return subtitle.Paragraphs.Count > _errorCount;
|
return subtitle.Paragraphs.Count > _errorCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly char[] CharSpace = { ' ' };
|
||||||
|
|
||||||
public override string ToText(Subtitle subtitle, string title)
|
public override string ToText(Subtitle subtitle, string title)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@ -38,7 +40,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
|
|
||||||
//split words
|
//split words
|
||||||
string text = p.Text.Replace(Environment.NewLine, " ").Replace(" ", " ");
|
string text = p.Text.Replace(Environment.NewLine, " ").Replace(" ", " ");
|
||||||
var words = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
var words = text.Split(CharSpace, StringSplitOptions.RemoveEmptyEntries);
|
||||||
var times = GenerateTimes(words, text, p.StartTime, p.EndTime);
|
var times = GenerateTimes(words, text, p.StartTime, p.EndTime);
|
||||||
for (int j = 0; j < words.Length; j++)
|
for (int j = 0; j < words.Length; j++)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user