This commit is contained in:
2010-06-08 20:53:36 +00:00
parent 7e780cace3
commit 58baa1dd81
6 changed files with 220 additions and 181 deletions

View File

@@ -1027,36 +1027,57 @@ namespace Volian.Controls.Library
// with the ReplaceWith string as is
if ((rs.Flag & E_ReplaceFlags.CaseInsens) > 0)
{
string res = "";
string fortest = Text.ToUpper();
string pat = @"(?<=\W|^)" + rs.ReplaceWord.ToUpper() + @"(?=\W|$)";
int cpindx = 0;
foreach (Match m in Regex.Matches(fortest, pat))
//string res = "";
//string fortest = Text.ToUpper();
////string pat = @"(?<=\W|^)" + rs.ReplaceWord.ToUpper() + @"(?=\W|$)";
//// jsj 07Jun2010 HardSpaces defeat replaceword logic
//string pat = @"(?<=\W|^)(?<![\\u160?])" + rs.ReplaceWord.ToUpper() + @"(?=[^\\u160?]|$)";
//int cpindx = 0;
//foreach (Match m in Regex.Matches(fortest, pat))
//{
// res += Text.Substring(cpindx, m.Index - cpindx);
// cpindx += (m.Index - cpindx);
// res += rs.ReplaceWith;
// cpindx += rs.ReplaceWord.Length;
//}
//if (cpindx < Text.Length) res += Text.Substring(cpindx, Text.Length - cpindx);
//Text = res;
// If there are Regex Control Characters '\[]()' prefix them with backslash
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
//string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)";
// jsj 07Jun2010 HardSpaces defeat replaceword logic
//string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)";
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
try
{
res += Text.Substring(cpindx, m.Index-cpindx);
cpindx += (m.Index - cpindx);
res += rs.ReplaceWith;
cpindx += rs.ReplaceWord.Length;
Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
}
if (cpindx < Text.Length) res += Text.Substring(cpindx, Text.Length - cpindx);
Text = res;
catch (Exception ex)
{
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
}
}
// CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case
else if ((rs.Flag & E_ReplaceFlags.CaseInsensAll) > 0)
{
// not in hlp
// only in Maine Yankee - we don't need to do this one.
}
// CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord,
// except the case where the first character may be different
else if ((rs.Flag & E_ReplaceFlags.CaseInsensFirst) > 0)
{
// not in hlp
// only used in V.C. Summer - we don't need to do this either.
}
else
{
// If there are Regex Control Characters '\[]()' prefix them with backslash
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)";
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
//string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)";
// jsj 07Jun2010 HardSpaces defeat replaceword logic
//string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)";
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
try
{
Text = Regex.Replace(Text, pat, rs.ReplaceWith);