Replace words for bolding [Bxxx], i.e. support for regular expression text in replaceword/with
Added TextAt counter for debug Added debug of TextAt by allowing specifying of ItemIds
This commit is contained in:
@@ -1644,8 +1644,10 @@ namespace Volian.Controls.Library
|
||||
// ReplaceStrData xml node is empty, it does the inheritance and gets the 'base' format's list.
|
||||
if (rsl.Count==1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return Text;
|
||||
// Loop through text looking for words to be replaced
|
||||
List<ReplaceStr> partialReplaceList = new List<ReplaceStr>();
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
bool dopartial = false;
|
||||
bool replaceit = false;
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
@@ -1662,6 +1664,11 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (!dicReplaceRegex.ContainsKey(rs))
|
||||
{
|
||||
if ((rs.Flag & E_ReplaceFlags.Partials) == E_ReplaceFlags.Partials)
|
||||
{
|
||||
partialReplaceList.Add(rs);
|
||||
dopartial = true;
|
||||
}
|
||||
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
|
||||
//RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase & RegexOptions.Singleline : RegexOptions.None & RegexOptions.Singleline;
|
||||
RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase: RegexOptions.None;
|
||||
@@ -1671,20 +1678,23 @@ namespace Volian.Controls.Library
|
||||
string wordMatchBeg = Regex.IsMatch(replaceWord.Substring(0, 1), @"\W") ? "" : @"(?<=\W|^)";
|
||||
string wordMatchEnd = Regex.IsMatch(replaceWord.Substring(replaceWord.Length - 1, 1), @"\W") ? "" : @"(?=\W|$)";
|
||||
string pat = wordMatchBeg + @"(?<!\\u160\?|\\u8209\?)" + replaceWord + @"(?!\\u160\?|\\u8209\?)" + wordMatchEnd;
|
||||
dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
|
||||
if (!dopartial) dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
|
||||
}
|
||||
try
|
||||
{
|
||||
myMatches.Add(dicReplaceRegex[rs], rs);
|
||||
if (!dopartial) myMatches.Add(dicReplaceRegex[rs], rs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
dopartial = false;
|
||||
}
|
||||
}
|
||||
Text = myMatches.ReplaceMatches();
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
foreach (ReplaceStr prs in partialReplaceList)
|
||||
Text = Regex.Replace(Text, prs.ReplaceWord, prs.ReplaceWith);
|
||||
return Text;
|
||||
}
|
||||
#region notused
|
||||
|
Reference in New Issue
Block a user