Improve case insensitive EndsWith

This commit is contained in:
_aLfa_ 2014-09-17 00:59:02 +02:00
parent af8cf1e370
commit 52aeda7a7c
36 changed files with 57 additions and 53 deletions

View File

@ -242,7 +242,7 @@ namespace Nikse.SubtitleEdit.Forms
int numberOfAudioTracks = 0; int numberOfAudioTracks = 0;
if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text)) if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text))
{ {
if (labelVideoFileName.Text.ToLower().EndsWith(".mkv")) if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
{ // Choose for number of audio tracks in matroska files { // Choose for number of audio tracks in matroska files
try try
{ {
@ -269,7 +269,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
} }
} }
else if (labelVideoFileName.Text.ToLower().EndsWith(".mp4") || labelVideoFileName.Text.ToLower().EndsWith(".m4v")) else if (labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
{ // Choose for number of audio tracks in mp4 files { // Choose for number of audio tracks in mp4 files
try try
{ {
@ -316,7 +316,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
// check for delay in matroska files // check for delay in matroska files
if (labelVideoFileName.Text.ToLower().EndsWith(".mkv")) if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
{ {
try try
{ {

View File

@ -680,16 +680,16 @@ namespace Nikse.SubtitleEdit.Forms
var bluRaySubtitles = new List<BluRaySupParser.PcsData>(); var bluRaySubtitles = new List<BluRaySupParser.PcsData>();
bool isVobSub = false; bool isVobSub = false;
bool isMatroska = false; bool isMatroska = false;
if (format == null && fileName.ToLower().EndsWith(".sup") && Main.IsBluRaySupFile(fileName)) if (format == null && fileName.EndsWith(".sup", StringComparison.OrdinalIgnoreCase) && Main.IsBluRaySupFile(fileName))
{ {
var log = new StringBuilder(); var log = new StringBuilder();
bluRaySubtitles = BluRaySupParser.ParseBluRaySup(fileName, log); bluRaySubtitles = BluRaySupParser.ParseBluRaySup(fileName, log);
} }
else if (format == null && fileName.ToLower().EndsWith(".sub") && Main.HasVobSubHeader(fileName)) else if (format == null && fileName.EndsWith(".sub", StringComparison.OrdinalIgnoreCase) && Main.HasVobSubHeader(fileName))
{ {
isVobSub = true; isVobSub = true;
} }
else if (format == null && fileName.ToLower().EndsWith(".mkv") && item.SubItems[2].Text.StartsWith("Matroska")) else if (format == null && fileName.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) && item.SubItems[2].Text.StartsWith("Matroska"))
{ {
isMatroska = true; isMatroska = true;
} }

View File

@ -687,7 +687,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
sb + sb +
"</DCSubtitle>"); "</DCSubtitle>");
string fName = saveFileDialog1.FileName; string fName = saveFileDialog1.FileName;
if (!fName.ToLower().EndsWith(".xml")) if (!fName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
fName += ".xml"; fName += ".xml";
File.WriteAllText(fName, SubtitleFormat.ToUtf8XmlString(doc)); File.WriteAllText(fName, SubtitleFormat.ToUtf8XmlString(doc));
MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(fName))); MessageBox.Show(string.Format(Configuration.Settings.Language.ExportPngXml.XImagesSavedInY, imagesSavedCount, Path.GetDirectoryName(fName)));

View File

@ -188,7 +188,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
foreach (ZipExtractor.ZipFileEntry entry in dir) foreach (ZipExtractor.ZipFileEntry entry in dir)
{ {
if (entry.FilenameInZip.ToLower().EndsWith(".zip", StringComparison.Ordinal)) if (entry.FilenameInZip.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
{ {
var innerMs = new MemoryStream(); var innerMs = new MemoryStream();
zip.ExtractFile(entry, innerMs); zip.ExtractFile(entry, innerMs);
@ -213,7 +213,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
foreach (ZipExtractor.ZipFileEntry entry in dir) foreach (ZipExtractor.ZipFileEntry entry in dir)
{ {
if (entry.FilenameInZip.ToLower().EndsWith(".dic") || entry.FilenameInZip.ToLower().EndsWith(".aff")) if (entry.FilenameInZip.EndsWith(".dic", StringComparison.OrdinalIgnoreCase) || entry.FilenameInZip.EndsWith(".aff", StringComparison.OrdinalIgnoreCase))
{ {
string fileName = Path.GetFileName(entry.FilenameInZip); string fileName = Path.GetFileName(entry.FilenameInZip);

View File

@ -70,7 +70,7 @@ namespace Nikse.SubtitleEdit.Forms
textBoxText.Text = File.ReadAllText(fileName, encoding); textBoxText.Text = File.ReadAllText(fileName, encoding);
// check for RTF file // check for RTF file
if (fileName.ToLower().EndsWith(".rtf") && !textBoxText.Text.Trim().StartsWith("{\\rtf")) if (fileName.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase) && !textBoxText.Text.Trim().StartsWith("{\\rtf"))
{ {
var rtBox = new RichTextBox(); var rtBox = new RichTextBox();
rtBox.Rtf = textBoxText.Text; rtBox.Rtf = textBoxText.Text;

View File

@ -2616,7 +2616,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
if (fileName.ToLower().EndsWith(".dost", StringComparison.Ordinal)) if (fileName.EndsWith(".dost", StringComparison.OrdinalIgnoreCase))
{ {
try try
{ {
@ -2823,7 +2823,7 @@ namespace Nikse.SubtitleEdit.Forms
string s = File.ReadAllText(fileName, enc); string s = File.ReadAllText(fileName, enc);
// check for RTF file // check for RTF file
if (fileName.ToLower().EndsWith(".rtf", StringComparison.Ordinal) && !s.Trim().StartsWith("{\\rtf", StringComparison.Ordinal)) if (fileName.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase) && !s.Trim().StartsWith("{\\rtf", StringComparison.Ordinal))
{ {
var rtBox = new RichTextBox(); var rtBox = new RichTextBox();
rtBox.Rtf = s; rtBox.Rtf = s;
@ -3023,7 +3023,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else else
{ {
if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".xml", StringComparison.Ordinal)) if (!string.IsNullOrEmpty(fileName) && fileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
{ {
string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)); string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName));
var sb = new StringBuilder(); var sb = new StringBuilder();
@ -9243,7 +9243,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowStatus(_language.SubtitleImportedFromMatroskaFile); ShowStatus(_language.SubtitleImportedFromMatroskaFile);
_subtitle.Renumber(1); _subtitle.Renumber(1);
_subtitle.WasLoadedWithFrameNumbers = false; _subtitle.WasLoadedWithFrameNumbers = false;
if (fileName.ToLower().EndsWith(".mkv") || fileName.ToLower().EndsWith(".mks")) if (fileName.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".mks", StringComparison.OrdinalIgnoreCase))
{ {
_fileName = fileName.Substring(0, fileName.Length - 4); _fileName = fileName.Substring(0, fileName.Length - 4);
Text = Title + " - " + _fileName; Text = Title + " - " + _fileName;
@ -10091,7 +10091,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowStatus(_language.SubtitleImportedFromMatroskaFile); ShowStatus(_language.SubtitleImportedFromMatroskaFile);
_subtitle.Renumber(1); _subtitle.Renumber(1);
_subtitle.WasLoadedWithFrameNumbers = false; _subtitle.WasLoadedWithFrameNumbers = false;
if (fileName.ToLower().EndsWith(".mp4") || fileName.ToLower().EndsWith(".m4v")) if (fileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
{ {
_fileName = fileName.Substring(0, fileName.Length - 4); _fileName = fileName.Substring(0, fileName.Length - 4);
Text = Title + " - " + _fileName; Text = Title + " - " + _fileName;

View File

@ -165,7 +165,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (comboBoxRule.SelectedIndex == FunctionEndsWith) // Ends with else if (comboBoxRule.SelectedIndex == FunctionEndsWith) // Ends with
{ {
if (checkBoxCaseSensitive.Checked && p.Text.EndsWith(text) || !checkBoxCaseSensitive.Checked && p.Text.ToLower().EndsWith(text.ToLower())) if (checkBoxCaseSensitive.Checked && p.Text.EndsWith(text) || !checkBoxCaseSensitive.Checked && p.Text.EndsWith(text, StringComparison.OrdinalIgnoreCase))
AddToListView(p, i); AddToListView(p, i);
} }
else if (comboBoxRule.SelectedIndex == FunctionNotContains) // Not contains else if (comboBoxRule.SelectedIndex == FunctionNotContains) // Not contains

View File

@ -486,12 +486,12 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_namesEtcList.Add(ChangeWord); _namesEtcList.Add(ChangeWord);
_namesEtcListUppercase.Add(ChangeWord.ToUpper()); _namesEtcListUppercase.Add(ChangeWord.ToUpper());
if (_languageName.StartsWith("en_") && !ChangeWord.ToLower().EndsWith('s')) if (_languageName.StartsWith("en_") && !ChangeWord.EndsWith("s", StringComparison.OrdinalIgnoreCase))
{ {
_namesEtcList.Add(ChangeWord + "s"); _namesEtcList.Add(ChangeWord + "s");
_namesEtcListUppercase.Add(ChangeWord.ToUpper() + "S"); _namesEtcListUppercase.Add(ChangeWord.ToUpper() + "S");
} }
if (!ChangeWord.ToLower().EndsWith('s')) if (!ChangeWord.EndsWith("s", StringComparison.OrdinalIgnoreCase))
{ {
_namesEtcListWithApostrophe.Add(ChangeWord + "'s"); _namesEtcListWithApostrophe.Add(ChangeWord + "'s");
_namesEtcListUppercase.Add(ChangeWord.ToUpper() + "'S"); _namesEtcListUppercase.Add(ChangeWord.ToUpper() + "'S");
@ -711,7 +711,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng &&
_languageName.StartsWith("en_") && _currentWord.ToLower().EndsWith("in'")) _languageName.StartsWith("en_") && _currentWord.EndsWith("in'", StringComparison.OrdinalIgnoreCase))
{ {
correct = DoSpell(_currentWord.TrimEnd('\'') + "g"); correct = DoSpell(_currentWord.TrimEnd('\'') + "g");
} }
@ -1270,12 +1270,12 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_namesEtcList.Remove(undo.UndoWord); _namesEtcList.Remove(undo.UndoWord);
_namesEtcListUppercase.Remove(undo.UndoWord.ToUpper()); _namesEtcListUppercase.Remove(undo.UndoWord.ToUpper());
if (_languageName.StartsWith("en_") && !undo.UndoWord.ToLower().EndsWith('s')) if (_languageName.StartsWith("en_") && !undo.UndoWord.EndsWith("s", StringComparison.OrdinalIgnoreCase))
{ {
_namesEtcList.Remove(undo.UndoWord + "s"); _namesEtcList.Remove(undo.UndoWord + "s");
_namesEtcListUppercase.Remove(undo.UndoWord.ToUpper() + "S"); _namesEtcListUppercase.Remove(undo.UndoWord.ToUpper() + "S");
} }
if (!undo.UndoWord.ToLower().EndsWith('s')) if (!undo.UndoWord.EndsWith("s", StringComparison.OrdinalIgnoreCase))
{ {
_namesEtcListWithApostrophe.Remove(undo.UndoWord + "'s"); _namesEtcListWithApostrophe.Remove(undo.UndoWord + "'s");
_namesEtcListUppercase.Remove(undo.UndoWord.ToUpper() + "'S"); _namesEtcListUppercase.Remove(undo.UndoWord.ToUpper() + "'S");

View File

@ -1551,7 +1551,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
correct = true; // already fixed correct = true; // already fixed
if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && wordNotEndTrimmed.EndsWith('\'') && if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng && wordNotEndTrimmed.EndsWith('\'') &&
SpellCheckDictionaryName.StartsWith("en_") && word.ToLower().EndsWith("in")) SpellCheckDictionaryName.StartsWith("en_") && word.EndsWith("in", StringComparison.OrdinalIgnoreCase))
{ {
correct = DoSpell(word + "g"); correct = DoSpell(word + "g");
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Logic.SpellCheck namespace Nikse.SubtitleEdit.Logic.SpellCheck
@ -12,7 +13,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
return new MacHunspell(dictionary + ".aff", dictionary + ".dic"); return new MacHunspell(dictionary + ".aff", dictionary + ".dic");
// Finnish is uses Voikko (not available via hunspell) // Finnish is uses Voikko (not available via hunspell)
if (dictionary.ToLower().EndsWith("fi_fi")) if (dictionary.EndsWith("fi_fi", StringComparison.OrdinalIgnoreCase))
return new VoikkoSpellCheck(Configuration.BaseDirectory, Configuration.DictionariesFolder); return new VoikkoSpellCheck(Configuration.BaseDirectory, Configuration.DictionariesFolder);
return new WindowsHunspell(dictionary + ".aff", dictionary + ".dic"); return new WindowsHunspell(dictionary + ".aff", dictionary + ".dic");

View File

@ -67,7 +67,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var sb = new StringBuilder(); var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line)); lines.ForEach(line => sb.AppendLine(line));
string all = sb.ToString(); string all = sb.ToString();
if (!string.IsNullOrEmpty(fileName) && fileName.ToLower().EndsWith(".ass", StringComparison.Ordinal) && !all.Contains("[V4 Styles]")) if (!string.IsNullOrEmpty(fileName) && fileName.EndsWith(".ass", StringComparison.OrdinalIgnoreCase) && !all.Contains("[V4 Styles]"))
{ {
} }
else if (!all.ToLower().Contains("dialogue:")) else if (!all.ToLower().Contains("dialogue:"))

View File

@ -34,7 +34,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && fileName.ToLower().EndsWith(".dost")) if (fileName != null && fileName.EndsWith(".dost", StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -139,7 +139,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
return true; return true;
} }
if (fileName.ToLower().EndsWith(".stl") && if (fileName.EndsWith(".stl", StringComparison.OrdinalIgnoreCase) &&
buffer.Length > 1283 && buffer.Length > 1283 &&
buffer[1024] == 0 && buffer[1024] == 0 &&
buffer[1025] == 1 && buffer[1025] == 1 &&

View File

@ -144,7 +144,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
FileInfo fi = new FileInfo(fileName); FileInfo fi = new FileInfo(fileName);
if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big
{ {
if (fileName.ToLower().EndsWith(".cap")) if (fileName.EndsWith(".cap", StringComparison.OrdinalIgnoreCase))
{ {
byte[] buffer = Utilities.ReadAllBytes(fileName); byte[] buffer = Utilities.ReadAllBytes(fileName);
if (buffer[0] == 0x2b) // "+" if (buffer[0] == 0x2b) // "+"

View File

@ -113,7 +113,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{ {
if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName)) if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
{ {
if (!fileName.ToLower().EndsWith(".cin")) if (!fileName.EndsWith(".cin", StringComparison.OrdinalIgnoreCase))
return false; return false;
var sub = new Subtitle(); var sub = new Subtitle();

View File

@ -203,7 +203,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var fi = new FileInfo(fileName); var fi = new FileInfo(fileName);
if (fi.Length >= 200 && fi.Length < 1024000) // not too small or too big if (fi.Length >= 200 && fi.Length < 1024000) // not too small or too big
{ {
if (fileName.ToLower().EndsWith(".cap")) if (fileName.EndsWith(".cap", StringComparison.OrdinalIgnoreCase))
{ {
byte[] buffer = Utilities.ReadAllBytes(fileName); byte[] buffer = Utilities.ReadAllBytes(fileName);
for (int i = 0; i < buffer.Length - 20; i++) for (int i = 0; i < buffer.Length - 20; i++)

View File

@ -29,7 +29,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName.ToLower().EndsWith(".chk")) if (fileName.EndsWith(".chk", StringComparison.OrdinalIgnoreCase))
{ {
var buffer = Utilities.ReadAllBytes(fileName); var buffer = Utilities.ReadAllBytes(fileName);
return buffer.Length > 0 && buffer[0] == 0x1d; return buffer.Length > 0 && buffer[0] == 0x1d;

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -34,7 +35,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var fi = new FileInfo(fileName); var fi = new FileInfo(fileName);
if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big
{ {
if (fileName.ToLower().EndsWith(".elr")) if (fileName.EndsWith(".elr", StringComparison.OrdinalIgnoreCase))
{ {
byte[] buffer = Utilities.ReadAllBytes(fileName); byte[] buffer = Utilities.ReadAllBytes(fileName);
byte[] compareBuffer = { 0x05, 0x01, 0x0D, 0x15, 0x11, 0x00, 0xA9, 0x00, 0x45, 0x00, 0x6C, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x20, 0x00, 0x53, 0x00, 0x74, 0x00, 0x75, 0x00, 0x64, 0x00, 0x69, 0x00, 0x6F, 0x00 }; byte[] compareBuffer = { 0x05, 0x01, 0x0D, 0x15, 0x11, 0x00, 0xA9, 0x00, 0x45, 0x00, 0x6C, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x20, 0x00, 0x53, 0x00, 0x74, 0x00, 0x75, 0x00, 0x64, 0x00, 0x69, 0x00, 0x6F, 0x00 };

View File

@ -586,7 +586,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
header.DiskFormatCode.StartsWith("STL50") || header.DiskFormatCode.StartsWith("STL50") ||
header.DiskFormatCode.StartsWith("STL60")) header.DiskFormatCode.StartsWith("STL60"))
{ {
return Utilities.IsInteger(header.CodePageNumber) || fileName.ToLower().EndsWith("stl"); return Utilities.IsInteger(header.CodePageNumber) || fileName.EndsWith("stl", StringComparison.OrdinalIgnoreCase);
} }
} }
catch catch

View File

@ -23,7 +23,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -30,7 +30,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
@ -23,7 +24,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -26,7 +26,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
return base.IsMine(lines, fileName); return base.IsMine(lines, fileName);

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -34,7 +35,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var fi = new FileInfo(fileName); var fi = new FileInfo(fileName);
if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big if (fi.Length >= 640 && fi.Length < 1024000) // not too small or too big
{ {
if (fileName.ToLower().EndsWith(".cap")) if (fileName.EndsWith(".cap", StringComparison.OrdinalIgnoreCase))
{ {
byte[] buffer = Utilities.ReadAllBytes(fileName); byte[] buffer = Utilities.ReadAllBytes(fileName);

View File

@ -948,7 +948,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
//buffer[21] < 10 && // start from number //buffer[21] < 10 && // start from number
//buffer[22] == 0 && //buffer[22] == 0 &&
buffer[23] == 0x60 && buffer[23] == 0x60 &&
fileName.ToLower().EndsWith(".pac")) fileName.EndsWith(".pac", StringComparison.OrdinalIgnoreCase))
return true; return true;
} }
} }

View File

@ -326,7 +326,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
text = text.Remove(0, text.IndexOf('>') + 1); text = text.Remove(0, text.IndexOf('>') + 1);
text = text.TrimEnd(); text = text.TrimEnd();
if (text.ToLower().EndsWith("</sync>", StringComparison.Ordinal)) if (text.EndsWith("</sync>", StringComparison.OrdinalIgnoreCase))
text = text.Substring(0, text.Length - 7).TrimEnd(); text = text.Substring(0, text.Length - 7).TrimEnd();
if (text.EndsWith("</p>", StringComparison.Ordinal) || text.EndsWith("</P>", StringComparison.Ordinal)) if (text.EndsWith("</p>", StringComparison.Ordinal) || text.EndsWith("</P>", StringComparison.Ordinal))

View File

@ -107,7 +107,7 @@ $ColorIndex4 = 3
_errorCount = 0; _errorCount = 0;
subtitle.Paragraphs.Clear(); subtitle.Paragraphs.Clear();
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,.+", RegexOptions.Compiled); var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,.+", RegexOptions.Compiled);
if (fileName != null && fileName.ToLower().EndsWith(".stl")) // allow empty text if extension is ".stl"... if (fileName != null && fileName.EndsWith(".stl", StringComparison.OrdinalIgnoreCase)) // allow empty text if extension is ".stl"...
regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,", RegexOptions.Compiled); regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,", RegexOptions.Compiled);
foreach (string line in lines) foreach (string line in lines)
{ {

View File

@ -89,7 +89,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (buffer[00] > 10 && if (buffer[00] > 10 &&
buffer[01] == 0 && buffer[01] == 0 &&
fileName.ToLower().EndsWith(".spt")) fileName.EndsWith(".spt", StringComparison.OrdinalIgnoreCase))
return true; return true;
} }
} }

View File

@ -191,7 +191,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var fi = new FileInfo(fileName); var fi = new FileInfo(fileName);
if (fi.Length >= 200 && fi.Length < 1024000) // not too small or too big if (fi.Length >= 200 && fi.Length < 1024000) // not too small or too big
{ {
if (fileName.ToLower().EndsWith(".ult") || fileName.ToLower().EndsWith(".uld")) // drop frame is often named uld, and ult for non-drop if (fileName.EndsWith(".ult", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".uld", StringComparison.OrdinalIgnoreCase)) // drop frame is often named uld, and ult for non-drop
{ {
byte[] buffer = Utilities.ReadAllBytes(fileName); byte[] buffer = Utilities.ReadAllBytes(fileName);
string id = Encoding.ASCII.GetString(buffer, 0, UltechId.Length); string id = Encoding.ASCII.GetString(buffer, 0, UltechId.Length);

View File

@ -145,7 +145,7 @@ DIGITAL_CINEMA=YES
if (line.ToLower().StartsWith("[i]")) if (line.ToLower().StartsWith("[i]"))
{ {
s = "<i>" + s.Remove(0, 3); s = "<i>" + s.Remove(0, 3);
if (s.ToLower().EndsWith("[/i]")) if (s.EndsWith("[/i]", StringComparison.OrdinalIgnoreCase))
s = s.Remove(s.Length - 4, 4); s = s.Remove(s.Length - 4, 4);
s += "</i>"; s += "</i>";
} }

View File

@ -23,7 +23,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -23,7 +23,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -23,7 +23,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -28,7 +28,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName) public override bool IsMine(List<string> lines, string fileName)
{ {
if (fileName != null && !fileName.ToLower().EndsWith(Extension)) if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
return false; return false;
var subtitle = new Subtitle(); var subtitle = new Subtitle();

View File

@ -971,7 +971,7 @@ namespace Nikse.SubtitleEdit.Logic
{ // keep utf-8 encoding if it's default { // keep utf-8 encoding if it's default
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
} }
else if (couldBeUtf8 && fileName.ToLower().EndsWith(".xml", StringComparison.Ordinal) && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\"")) else if (couldBeUtf8 && fileName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\""))
{ // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters) { // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters)
encoding = Encoding.UTF8; encoding = Encoding.UTF8;
} }

View File

@ -478,7 +478,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(Configuration.Settings.General.VlcLocation)) if (!string.IsNullOrEmpty(Configuration.Settings.General.VlcLocation))
{ {
if (Configuration.Settings.General.VlcLocation.ToUpper().EndsWith(".exe", StringComparison.Ordinal)) if (Configuration.Settings.General.VlcLocation.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
Configuration.Settings.General.VlcLocation = Path.GetDirectoryName(Configuration.Settings.General.VlcLocation); Configuration.Settings.General.VlcLocation = Path.GetDirectoryName(Configuration.Settings.General.VlcLocation);
path = Path.Combine(Configuration.Settings.General.VlcLocation, fileName); path = Path.Combine(Configuration.Settings.General.VlcLocation, fileName);
@ -491,7 +491,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
try try
{ {
path = Configuration.Settings.General.VlcLocationRelative; path = Configuration.Settings.General.VlcLocationRelative;
if (path.ToUpper().EndsWith(".exe", StringComparison.Ordinal)) if (path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path);
path = Path.Combine(path, fileName); path = Path.Combine(path, fileName);