mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Merge pull request #1247 from ivandrofly/patch-8
Fix + Update (libse/HtmlUtil.cs, src/Forms/OCRSpellCheck.cs)
This commit is contained in:
commit
7096e2cbfd
@ -46,7 +46,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
/// <returns>An encoded string.</returns>
|
||||
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
|
||||
/// <returns>An encoded string.</returns>
|
||||
public static string EncodeNumeric(string source)
|
||||
{
|
||||
if (source == null)
|
||||
if (string.IsNullOrEmpty(source))
|
||||
return string.Empty;
|
||||
|
||||
var encoded = new StringBuilder(source.Length);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -177,6 +177,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly char[] ExpectedCharsArray = { '.', '!', '?', ':', ';', ')', ']', '}', '(', '[', '{' };
|
||||
public void FixCasing(List<string> namesEtc, bool changeNameCases, bool makeUppercaseAfterBreak, bool checkLastLine, string lastLine)
|
||||
{
|
||||
var replaceIds = new List<string>();
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user