mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Refactor minor stuff
This commit is contained in:
parent
a4ce906b8d
commit
ce37dc1d75
@ -269,7 +269,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
|
||||
}
|
||||
foreach (string multiWordName in _namesMultiList)
|
||||
{
|
||||
if (text.Contains(multiWordName))
|
||||
if (text.FastIndexOf(multiWordName) >= 0)
|
||||
{
|
||||
if (multiWordName.StartsWith(word + " ", StringComparison.Ordinal) || multiWordName.EndsWith(" " + word, StringComparison.Ordinal) || multiWordName.Contains(" " + word + " "))
|
||||
{
|
||||
|
@ -213,7 +213,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
|
||||
string s = l;
|
||||
foreach (string from in _beginLineReplaceList.Keys)
|
||||
{
|
||||
if (s.Contains(from))
|
||||
if (s.FastIndexOf(from) >= 0)
|
||||
{
|
||||
string with = _beginLineReplaceList[from];
|
||||
if (s.StartsWith(from, StringComparison.Ordinal))
|
||||
|
@ -63,7 +63,8 @@
|
||||
if (!skip && charactersPerSecond > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
|
||||
{
|
||||
var temp = new Paragraph(p);
|
||||
while (Utilities.GetCharactersPerSecond(temp) > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
|
||||
var numberOfCharacters = temp.Text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace);
|
||||
while (Utilities.GetCharactersPerSecond(temp, numberOfCharacters) > Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds)
|
||||
{
|
||||
temp.EndTime.TotalMilliseconds++;
|
||||
}
|
||||
|
@ -164,19 +164,15 @@ namespace Nikse.SubtitleEdit.Core
|
||||
// http://www.codeproject.com/Articles/43726/Optimizing-string-operations-in-C
|
||||
public static int FastIndexOf(this string source, string pattern)
|
||||
{
|
||||
if (pattern == null)
|
||||
if (string.IsNullOrEmpty(pattern))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
if (pattern.Length == 0)
|
||||
{
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char c0 = pattern[0];
|
||||
if (pattern.Length == 1)
|
||||
{
|
||||
return source.IndexOf(pattern[0]);
|
||||
return source.IndexOf(c0);
|
||||
}
|
||||
|
||||
int limit = source.Length - pattern.Length + 1;
|
||||
@ -184,9 +180,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// Store the first 2 characters of "pattern"
|
||||
char c0 = pattern[0];
|
||||
|
||||
char c1 = pattern[1];
|
||||
|
||||
// Find the first occurrence of the first character
|
||||
int first = source.IndexOf(c0, 0, limit);
|
||||
while (first != -1)
|
||||
@ -199,8 +195,8 @@ namespace Nikse.SubtitleEdit.Core
|
||||
continue;
|
||||
}
|
||||
// Check the rest of "pattern" (starting with the 3rd character)
|
||||
bool found = true;
|
||||
for (var j = 2; j < pattern.Length; j++)
|
||||
var found = true;
|
||||
for (int j = 2; j < pattern.Length; j++)
|
||||
{
|
||||
if (source[first + j] != pattern[j])
|
||||
{
|
||||
@ -404,8 +400,8 @@ namespace Nikse.SubtitleEdit.Core
|
||||
char normalSpace = removeNormalSpace ? ' ' : zeroWidthSpace;
|
||||
bool ssaTagOn = false;
|
||||
bool htmlTagOn = false;
|
||||
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
var max = value.Length;
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
char ch = value[i];
|
||||
if (ssaTagOn)
|
||||
|
@ -18,9 +18,10 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
}
|
||||
|
||||
public StrippableText(string text, string stripStartCharacters, string stripEndCharacters)
|
||||
public StrippableText(string input, string stripStartCharacters, string stripEndCharacters)
|
||||
{
|
||||
OriginalText = text;
|
||||
OriginalText = input;
|
||||
var text = input;
|
||||
|
||||
Pre = string.Empty;
|
||||
if (text.Length > 0 && ("<{" + stripStartCharacters).Contains(text[0]))
|
||||
|
@ -407,7 +407,8 @@ namespace Nikse.SubtitleEdit.Core
|
||||
|
||||
double duration = Utilities.GetOptimalDisplayMilliseconds(p.Text, optimalCharactersPerSeconds);
|
||||
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + duration;
|
||||
while (Utilities.GetCharactersPerSecond(p) > maxCharactersPerSecond)
|
||||
var numberOfCharacters = p.Text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace);
|
||||
while (Utilities.GetCharactersPerSecond(p, numberOfCharacters) > maxCharactersPerSecond)
|
||||
{
|
||||
duration++;
|
||||
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + duration;
|
||||
@ -424,7 +425,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetFixedDuration(List<int> selectedIndexes, double fixedDurationMilliseconds)
|
||||
{
|
||||
for (int i = 0; i < _paragraphs.Count; i++)
|
||||
|
@ -1509,7 +1509,7 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
|
||||
endIndex1 = Math.Min(endIndex1, endIndex2);
|
||||
if (endIndex1 > 0)
|
||||
{
|
||||
s = s.Remove(indexOfTag, endIndex1 - indexOfTag);
|
||||
return s.Remove(indexOfTag, endIndex1 - indexOfTag);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
@ -1865,8 +1865,9 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
|
||||
/// Add new style to ASS header
|
||||
/// </summary>
|
||||
/// <returns>Header with new style</returns>
|
||||
public static string AddSsaStyle(SsaStyle style, string header)
|
||||
public static string AddSsaStyle(SsaStyle style, string inputHeader)
|
||||
{
|
||||
var header = inputHeader;
|
||||
if (string.IsNullOrEmpty(header))
|
||||
{
|
||||
header = DefaultHeader;
|
||||
|
@ -1031,6 +1031,18 @@ namespace Nikse.SubtitleEdit.Core
|
||||
return paragraph.Text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace) / duration.TotalSeconds;
|
||||
}
|
||||
|
||||
public static double GetCharactersPerSecond(Paragraph paragraph, int numberOfCharacters)
|
||||
{
|
||||
var duration = paragraph.Duration;
|
||||
if (duration.TotalMilliseconds < 1)
|
||||
{
|
||||
return 999;
|
||||
}
|
||||
|
||||
return numberOfCharacters / duration.TotalSeconds;
|
||||
}
|
||||
|
||||
|
||||
public static bool IsRunningOnMono()
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
|
Loading…
Reference in New Issue
Block a user