mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +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();
|
||||
foreach (string s in lines)
|
||||
sb.Append(s);
|
||||
if (!sb.ToString().TrimStart().StartsWith("[{\"start"))
|
||||
if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
||||
@ -145,6 +145,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
return s;
|
||||
}
|
||||
|
||||
private static readonly char[] CommaAndEndCurlyBracket = { ',', '}' };
|
||||
|
||||
public static string ReadTag(string s, string tag)
|
||||
{
|
||||
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();
|
||||
if (res.StartsWith('"'))
|
||||
{ // text
|
||||
res = Json.ConvertJsonSpecialCharacters(res);
|
||||
res = ConvertJsonSpecialCharacters(res);
|
||||
res = res.Replace("\\\"", "@__1");
|
||||
int endIndex = res.IndexOf("\"}", StringComparison.Ordinal);
|
||||
int endAlternate = res.IndexOf("\",", StringComparison.Ordinal);
|
||||
@ -169,7 +171,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
else
|
||||
{ // number
|
||||
var endIndex = res.IndexOfAny(new[] { ',', '}' });
|
||||
var endIndex = res.IndexOfAny(CommaAndEndCurlyBracket);
|
||||
if (endIndex < 0)
|
||||
return null;
|
||||
return res.Substring(0, endIndex);
|
||||
|
@ -56,7 +56,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var sb = new StringBuilder();
|
||||
foreach (string s in lines)
|
||||
sb.Append(s);
|
||||
if (!sb.ToString().TrimStart().StartsWith("[{\"startMillis"))
|
||||
if (!sb.ToString().TrimStart().StartsWith("[{\"", StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines())
|
||||
|
@ -57,7 +57,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var sb = new StringBuilder();
|
||||
foreach (string s in lines)
|
||||
sb.Append(s);
|
||||
int startIndex = sb.ToString().IndexOf("[{\"duration", StringComparison.Ordinal);
|
||||
int startIndex = sb.ToString().IndexOf("[{\"", StringComparison.Ordinal);
|
||||
if (startIndex < 0)
|
||||
return;
|
||||
|
||||
|
@ -28,6 +28,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
private static readonly char[] CharSpace = { ' ' };
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
@ -38,7 +40,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
|
||||
//split words
|
||||
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);
|
||||
for (int j = 0; j < words.Length; j++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user