Merge pull request #867 from xylographe/xrfmt

Minor refact
This commit is contained in:
Nikolaj Olsson 2015-06-16 08:22:26 +02:00
commit f9b8ab33ee
5 changed files with 13 additions and 12 deletions

View File

@ -145,8 +145,8 @@ namespace Nikse.SubtitleEdit.Core
public static string FixExtraSpaces(this string s)
{
if (string.IsNullOrEmpty(s) || s.Trim().Length == 0)
return s;
if (string.IsNullOrWhiteSpace(s))
return string.Empty;
while (s.Contains(" "))
s = s.Replace(" ", " ");

View File

@ -904,7 +904,7 @@ namespace Nikse.SubtitleEdit.Forms
private static void CopyTextToClipboard(RichTextBox sender)
{
if (sender.Text.Trim().Length == 0)
if (string.IsNullOrWhiteSpace(sender.Text))
return;
if (sender.SelectedText.Length > 0)
{

View File

@ -857,12 +857,12 @@ namespace Nikse.SubtitleEdit.Logic.Forms
return lines[0];
}
}
if (lines.Length == 2 && lines[1].Replace(".", string.Empty).Replace("?", string.Empty).Replace("!", string.Empty).Replace("-", string.Empty).Replace("—", string.Empty).Trim().Length == 0)
if (lines.Length == 2 && string.IsNullOrWhiteSpace(lines[1].Replace(".", string.Empty).Replace("?", string.Empty).Replace("!", string.Empty).Replace("-", string.Empty).Replace("—", string.Empty)))
{
text = lines[0];
lines = text.SplitToLines();
}
else if (lines.Length == 2 && lines[0].Replace(".", string.Empty).Replace("?", string.Empty).Replace("!", string.Empty).Replace("-", string.Empty).Replace("—", string.Empty).Trim().Length == 0)
else if (lines.Length == 2 && string.IsNullOrWhiteSpace(lines[0].Replace(".", string.Empty).Replace("?", string.Empty).Replace("!", string.Empty).Replace("-", string.Empty).Replace("—", string.Empty)))
{
text = lines[1];
lines = text.SplitToLines();

View File

@ -1072,7 +1072,7 @@ namespace Nikse.SubtitleEdit.Logic
public void Save()
{
//this is too slow: Serialize(Configuration.BaseDirectory + "Settings.xml", this);
//this is too slow: Serialize(Configuration.SettingsFileName, this);
CustomSerialize(Configuration.SettingsFileName, this);
}
@ -1088,16 +1088,16 @@ namespace Nikse.SubtitleEdit.Logic
public static Settings GetSettings()
{
var settings = new Settings();
string settingsFileName = Configuration.SettingsFileName;
var settingsFileName = Configuration.SettingsFileName;
if (File.Exists(settingsFileName))
{
try
{
//too slow... :( - settings = Deserialize(settingsFileName); // 688 msecs
settings = CustomDeserialize(settingsFileName); // 15 msecs
if (settings.General.AutoConvertToUtf8)
settings.General.DefaultEncoding = Encoding.UTF8.EncodingName;
//too slow... :( - settings = Deserialize(Configuration.BaseDirectory + "Settings.xml"); // 688 msecs
}
catch
{
@ -2641,8 +2641,9 @@ namespace Nikse.SubtitleEdit.Logic
private static void CustomSerialize(string fileName, Settings settings)
{
var sw = new StringWriter();
using (var textWriter = new XmlTextWriter(sw) { Formatting = Formatting.Indented })
var xws = new XmlWriterSettings { Indent = true };
var sb = new StringBuilder();
using (var textWriter = XmlWriter.Create(sb, xws))
{
textWriter.WriteStartDocument();
@ -3187,7 +3188,7 @@ namespace Nikse.SubtitleEdit.Logic
try
{
File.WriteAllText(fileName, sw.ToString().Replace("encoding=\"utf-16\"", "encoding=\"utf-8\""), Encoding.UTF8);
File.WriteAllText(fileName, sb.ToString().Replace("encoding=\"utf-16\"", "encoding=\"utf-8\""), Encoding.UTF8);
}
catch
{

View File

@ -249,7 +249,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
}
text = sb + post;
if (HtmlUtil.RemoveHtmlTags(text).Trim().Length == 0)
if (string.IsNullOrWhiteSpace(HtmlUtil.RemoveHtmlTags(text)))
return string.Empty;
return text;
}