diff --git a/libse/HtmlUtil.cs b/libse/HtmlUtil.cs
index d585e177d..b7dfa83c3 100644
--- a/libse/HtmlUtil.cs
+++ b/libse/HtmlUtil.cs
@@ -46,7 +46,7 @@ namespace Nikse.SubtitleEdit.Core
/// An encoded string.
public static string EncodeNamed(string source)
{
- if (source == null)
+ if (string.IsNullOrEmpty(source))
return string.Empty;
var encoded = new StringBuilder(source.Length);
@@ -327,7 +327,7 @@ namespace Nikse.SubtitleEdit.Core
/// An encoded string.
public static string EncodeNumeric(string source)
{
- if (source == null)
+ if (string.IsNullOrEmpty(source))
return string.Empty;
var encoded = new StringBuilder(source.Length);
diff --git a/libse/ManagedBitmap.cs b/libse/ManagedBitmap.cs
index e317345d0..93ad486b5 100644
--- a/libse/ManagedBitmap.cs
+++ b/libse/ManagedBitmap.cs
@@ -17,16 +17,10 @@ namespace Nikse.SubtitleEdit.Core
try
{
byte[] buffer = new byte[1024];
- MemoryStream fd = new MemoryStream();
- Stream fs = File.OpenRead(fileName);
- using (Stream csStream = new GZipStream(fs, CompressionMode.Decompress))
+ using (var fd = new MemoryStream())
+ using (Stream csStream = new GZipStream(File.OpenRead(fileName), CompressionMode.Decompress))
{
- int nRead;
- while ((nRead = csStream.Read(buffer, 0, buffer.Length)) > 0)
- {
- fd.Write(buffer, 0, nRead);
- }
- csStream.Flush();
+ csStream.CopyTo(fd);
buffer = fd.ToArray();
}
@@ -147,10 +141,10 @@ namespace Nikse.SubtitleEdit.Core
private static void WriteColor(Stream stream, Color c)
{
byte[] buffer = new byte[4];
- buffer[0] = (byte)c.A;
- buffer[1] = (byte)c.R;
- buffer[2] = (byte)c.G;
- buffer[3] = (byte)c.B;
+ buffer[0] = c.A;
+ buffer[1] = c.R;
+ buffer[2] = c.G;
+ buffer[3] = c.B;
stream.Write(buffer, 0, buffer.Length);
}
diff --git a/libse/StripableText.cs b/libse/StripableText.cs
index 171067529..e39459890 100644
--- a/libse/StripableText.cs
+++ b/libse/StripableText.cs
@@ -177,6 +177,7 @@ namespace Nikse.SubtitleEdit.Core
}
}
+ private static readonly char[] ExpectedCharsArray = { '.', '!', '?', ':', ';', ')', ']', '}', '(', '[', '{' };
public void FixCasing(List namesEtc, bool changeNameCases, bool makeUppercaseAfterBreak, bool checkLastLine, string lastLine)
{
var replaceIds = new List();
@@ -212,10 +213,10 @@ namespace Nikse.SubtitleEdit.Core
}
}
- if (makeUppercaseAfterBreak && StrippedText.Contains(new[] { '.', '!', '?', ':', ';', ')', ']', '}', '(', '[', '{' }))
+ if (makeUppercaseAfterBreak && StrippedText.Contains(ExpectedCharsArray))
{
const string breakAfterChars = @".!?:;)]}([{";
-
+ const string ExpectedChars = "\"`´'()<>!?.- \r\n";
var sb = new StringBuilder();
bool lastWasBreak = false;
for (int i = 0; i < StrippedText.Length; i++)
@@ -223,7 +224,7 @@ namespace Nikse.SubtitleEdit.Core
var s = StrippedText[i];
if (lastWasBreak)
{
- if (("\"`´'()<>!?.- " + Environment.NewLine).Contains(s))
+ if (ExpectedChars.Contains(s))
{
sb.Append(s);
}
diff --git a/src/Forms/OCRSpellCheck.cs b/src/Forms/OCRSpellCheck.cs
index 9df6f9c21..3b482fca9 100644
--- a/src/Forms/OCRSpellCheck.cs
+++ b/src/Forms/OCRSpellCheck.cs
@@ -87,18 +87,19 @@ namespace Nikse.SubtitleEdit.Forms
{
if (word != null && richTextBoxParagraph.Text.Contains(word))
{
+ const string ExpectedWordBoundaryChars = @" <>-""”“[]'‘`´¶()♪¿¡.…—!?,:;/\r\n";
for (int i = 0; i < richTextBoxParagraph.Text.Length; i++)
{
if (richTextBoxParagraph.Text.Substring(i).StartsWith(word))
{
bool startOk = i == 0;
if (!startOk)
- startOk = (@" <>-""”“[]'‘`´¶()♪¿¡.…—!?,:;/" + Environment.NewLine).Contains(richTextBoxParagraph.Text[i - 1]);
+ startOk = ExpectedWordBoundaryChars.Contains(richTextBoxParagraph.Text[i - 1]);
if (startOk)
{
bool endOk = (i + word.Length == richTextBoxParagraph.Text.Length);
if (!endOk)
- endOk = (@" <>-""”“[]'‘`´¶()♪¿¡.…—!?,:;/" + Environment.NewLine).Contains(richTextBoxParagraph.Text[i + word.Length]);
+ endOk = ExpectedWordBoundaryChars.Contains(richTextBoxParagraph.Text[i + word.Length]);
if (endOk)
{
richTextBoxParagraph.SelectionStart = i + 1;