mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Testing removal of control characters - issue #1211 and more...
This commit is contained in:
parent
54bfba83d2
commit
020e95c5b2
@ -162,5 +162,28 @@ namespace Nikse.SubtitleEdit.Core
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string RemoveControlCharacters(this string s)
|
||||
{
|
||||
var sb = new StringBuilder(s.Length);
|
||||
foreach (var ch in s)
|
||||
{
|
||||
if (!Char.IsControl(ch))
|
||||
sb.Append(ch);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string RemoveControlCharactersButWhiteSpace(this string s)
|
||||
{
|
||||
var sb = new StringBuilder(s.Length);
|
||||
foreach (var ch in s)
|
||||
{
|
||||
if (!Char.IsControl(ch) || ch == '\u000d' || ch == '\u000a' || ch == '\u0009')
|
||||
sb.Append(ch);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
try
|
||||
{
|
||||
xml.LoadXml(xmlAsString);
|
||||
xml.LoadXml(xmlAsString.RemoveControlCharactersButWhiteSpace());
|
||||
|
||||
var nsmgr = new XmlNamespaceManager(xml.NameTable);
|
||||
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);
|
||||
@ -152,7 +152,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
xml.LoadXml(sb.ToString().Trim().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang"));
|
||||
xml.LoadXml(sb.ToString().RemoveControlCharactersButWhiteSpace().Trim().Replace("http://www.w3.org/2006/04/ttaf1#styling\"xml:lang", "http://www.w3.org/2006/04/ttaf1#styling\" xml:lang"));
|
||||
|
||||
var nsmgr = new XmlNamespaceManager(xml.NameTable);
|
||||
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);
|
||||
|
@ -124,7 +124,8 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
private void ButtonAddClick(object sender, EventArgs e)
|
||||
{
|
||||
if (textBoxFind.Text.Length > 0)
|
||||
string findText = textBoxFind.Text.RemoveControlCharacters();
|
||||
if (findText.Length > 0)
|
||||
{
|
||||
string searchType = SearchTypeNormal;
|
||||
if (radioButtonCaseSensitive.Checked)
|
||||
@ -132,7 +133,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
else if (radioButtonRegEx.Checked)
|
||||
{
|
||||
searchType = SearchTypeRegularExpression;
|
||||
if (!Utilities.IsValidRegex(textBoxFind.Text))
|
||||
if (!Utilities.IsValidRegex(findText))
|
||||
{
|
||||
MessageBox.Show(Configuration.Settings.Language.General.RegularExpressionIsNotValid);
|
||||
textBoxFind.Select();
|
||||
@ -140,7 +141,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
AddToReplaceListView(true, textBoxFind.Text, textBoxReplace.Text, EnglishSearchTypeToLocal(searchType));
|
||||
AddToReplaceListView(true, findText, textBoxReplace.Text.RemoveControlCharacters(), EnglishSearchTypeToLocal(searchType));
|
||||
textBoxFind.Text = string.Empty;
|
||||
textBoxReplace.Text = string.Empty;
|
||||
GeneratePreview();
|
||||
|
Loading…
Reference in New Issue
Block a user