Fix not changing urls in "Change casing" - thx ivandrofly :)

Fix #2337
This commit is contained in:
Nikolaj Olsson 2017-04-14 15:48:43 +02:00
parent 5e1a33f96f
commit ce1473210d
2 changed files with 41 additions and 2 deletions

View File

@ -203,7 +203,11 @@ namespace Nikse.SubtitleEdit.Core
if (startWithUppercase && StrippedText.Length > 0 && !Pre.Contains("..."))
{
StrippedText = char.ToUpper(StrippedText[0]) + StrippedText.Substring(1);
if (!StrippedText.StartsWith("www.", StringComparison.OrdinalIgnoreCase) &&
!StrippedText.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
StrippedText = char.ToUpper(StrippedText[0]) + StrippedText.Substring(1);
}
}
}
@ -262,7 +266,11 @@ namespace Nikse.SubtitleEdit.Core
}
else
{
lastWasBreak = true;
idx = sb.ToString().LastIndexOf(' ');
if (idx >= 0 && idx < sb.Length - 2 && !IsInMiddleOfUrl(i - idx, StrippedText.Substring(idx + 1)))
{
lastWasBreak = true;
}
}
}
}
@ -273,6 +281,13 @@ namespace Nikse.SubtitleEdit.Core
ReplaceNames2Fix(replaceIds, changeNameCases ? replaceNames : originalNames);
}
private bool IsInMiddleOfUrl(int idx, string s)
{
if (idx < s.Length - 1 && (char.IsWhiteSpace(s[idx]) || char.IsPunctuation(s[idx])))
return false;
return s.StartsWith("www.", StringComparison.OrdinalIgnoreCase) || s.StartsWith("http", StringComparison.OrdinalIgnoreCase);
}
public string CombineWithPrePost(string text)
{
return Pre + text + Post;

View File

@ -115,5 +115,29 @@ namespace Test.Logic
Assert.AreEqual(st.StrippedText, "Hi");
}
[TestMethod]
public void StrippableTextChangeCasing()
{
var st = new StrippableText("this is for www.nikse.dk. thank you.");
st.FixCasing(new System.Collections.Generic.List<string>(), false, true, true, "Bye.");
Assert.AreEqual(st.MergedString, "This is for www.nikse.dk. Thank you.");
}
[TestMethod]
public void StrippableTextChangeCasing2()
{
var st = new StrippableText("this is for www.nikse.dk! thank you.");
st.FixCasing(new System.Collections.Generic.List<string>(), false, true, true, "Bye.");
Assert.AreEqual(st.MergedString, "This is for www.nikse.dk! Thank you.");
}
[TestMethod]
public void StrippableTextChangeCasing3()
{
var st = new StrippableText("www.nikse.dk");
st.FixCasing(new System.Collections.Generic.List<string>(), false, true, true, "Bye.");
Assert.AreEqual(st.MergedString, "www.nikse.dk");
}
}
}