mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 15:02:35 +01:00
Merge pull request #994 from ivandrofly/refactor-3
Refactor (src/Logic/SubtitleFormats/Json.cs)
This commit is contained in:
commit
4cdcad96b5
@ -148,12 +148,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
|
||||
public static string ReadTag(string s, string tag)
|
||||
{
|
||||
int startIndex = s.IndexOf("\"" + tag + "\"", StringComparison.Ordinal);
|
||||
if (startIndex < 0)
|
||||
startIndex = s.IndexOf("'" + tag + "'", StringComparison.Ordinal);
|
||||
var startIndex = s.IndexOfAny(new[] { "\"" + tag + "\"", "'" + tag + "'" }, StringComparison.Ordinal);
|
||||
if (startIndex < 0)
|
||||
return null;
|
||||
string res = s.Substring(startIndex + 3 + tag.Length).Trim().TrimStart(':').TrimStart();
|
||||
var res = s.Substring(startIndex + 3 + tag.Length).Trim().TrimStart(':').TrimStart();
|
||||
if (res.StartsWith('"'))
|
||||
{ // text
|
||||
res = Json.ConvertJsonSpecialCharacters(res);
|
||||
@ -172,9 +170,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
}
|
||||
else
|
||||
{ // number
|
||||
int endIndex = res.IndexOf(',');
|
||||
if (endIndex < 0)
|
||||
endIndex = res.IndexOf('}');
|
||||
var endIndex = res.IndexOfAny(new[] { ',', '}' });
|
||||
if (endIndex < 0)
|
||||
return null;
|
||||
return res.Substring(0, endIndex);
|
||||
@ -185,9 +181,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
var list = new List<string>();
|
||||
|
||||
int startIndex = s.IndexOf("\"" + tag + "\"", StringComparison.Ordinal);
|
||||
if (startIndex < 0)
|
||||
startIndex = s.IndexOf("'" + tag + "'", StringComparison.Ordinal);
|
||||
var startIndex = s.IndexOfAny(new[] { "\"" + tag + "\"", "'" + tag + "'" }, StringComparison.Ordinal);
|
||||
if (startIndex < 0)
|
||||
return list;
|
||||
|
||||
@ -263,8 +257,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
text = text.Trim();
|
||||
if (text.StartsWith('[') && text.EndsWith(']'))
|
||||
{
|
||||
text = text.Trim('[');
|
||||
text = text.Trim(']');
|
||||
text = text.Trim('[', ']');
|
||||
text = text.Trim();
|
||||
|
||||
text = text.Replace("<br />", Environment.NewLine);
|
||||
|
Loading…
Reference in New Issue
Block a user