This commit is contained in:
parent
3000d61d8c
commit
c26e539b15
@ -253,8 +253,6 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private string DoTransitionAdjustments(string text)
|
||||
{
|
||||
if (_MyItemInfo.ItemID == 230 || _MyItemInfo.ItemID == 154 || _MyItemInfo.ItemID == 1932)
|
||||
Console.Write("");
|
||||
string strippedText = StaticStripRtfCommands(text);
|
||||
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):[0-9]* ([0-9]*).*?\[END>");
|
||||
MatchCollection matches = Regex.Matches(text, lookFor);
|
||||
@ -1163,153 +1161,153 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
#endregion
|
||||
#region ReplaceWords
|
||||
private string DoReplaceWords(string Text)
|
||||
{
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
bool replaceit = false;
|
||||
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High)>0) replaceit = true;
|
||||
else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
//else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
|
||||
|
||||
if (replaceit)
|
||||
{
|
||||
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace
|
||||
// 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|$)";
|
||||
//// 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))
|
||||
//private string DoReplaceWords(string Text)
|
||||
//{
|
||||
// res += Text.Substring(cpindx, m.Index - cpindx);
|
||||
// cpindx += (m.Index - cpindx);
|
||||
// res += rs.ReplaceWith;
|
||||
// cpindx += rs.ReplaceWord.Length;
|
||||
// ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// foreach (ReplaceStr rs in rsl)
|
||||
// {
|
||||
// if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
// bool replaceit = false;
|
||||
|
||||
// if (_MyItemInfo.ItemID == 2557) Console.WriteLine("here");
|
||||
// // note that the order of this check is important. Check in this order...
|
||||
// // background here
|
||||
// if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High)>0) replaceit = true;
|
||||
// else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
// //else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
|
||||
|
||||
// if (replaceit)
|
||||
// {
|
||||
// // CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace
|
||||
// // 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|$)";
|
||||
// //// 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
|
||||
// {
|
||||
// Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
// //Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
|
||||
// }
|
||||
//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
|
||||
{
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
//Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
}
|
||||
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)
|
||||
// {
|
||||
// // 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)
|
||||
// {
|
||||
// // 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|$)";
|
||||
// // jsj 07Jun2010 HardSpaces defeat replaceword logic
|
||||
// //string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)";
|
||||
// string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
// try
|
||||
// {
|
||||
// Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.None);
|
||||
// //Text = Regex.Replace(Text, pat, rs.ReplaceWith);
|
||||
// }
|
||||
// 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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// 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|$)";
|
||||
// jsj 07Jun2010 HardSpaces defeat replaceword logic
|
||||
//string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)";
|
||||
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
try
|
||||
{
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.None);
|
||||
//Text = Regex.Replace(Text, pat, rs.ReplaceWith);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
// //Console.WriteLine("--- Before '{0}'", Text);
|
||||
// Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
// //Console.WriteLine("--- After '{0}'", Text);
|
||||
// return Text;
|
||||
//}
|
||||
//private string DoReplaceWords1(string Text)
|
||||
//{
|
||||
// if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
// ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// // Loop through text looking for words to be replaced
|
||||
// foreach (ReplaceStr rs in rsl)
|
||||
// {
|
||||
// bool replaceit = false;
|
||||
|
||||
}
|
||||
}
|
||||
//Console.WriteLine("--- Before '{0}'", Text);
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
//Console.WriteLine("--- After '{0}'", Text);
|
||||
return Text;
|
||||
}
|
||||
private string DoReplaceWords1(string Text)
|
||||
{
|
||||
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// Loop through text looking for words to be replaced
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
bool replaceit = false;
|
||||
// // note that the order of this check is important. Check in this order...
|
||||
// // background here
|
||||
// if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
|
||||
// else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
// //else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
// else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
|
||||
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
|
||||
else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
//else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
|
||||
// if (replaceit)
|
||||
// {
|
||||
// // 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.None;
|
||||
// string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
|
||||
// string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
// try
|
||||
// {
|
||||
// Text = ReplaceWord(Text, pat, rs.ReplaceWith, myOptions);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
|
||||
// }
|
||||
|
||||
if (replaceit)
|
||||
{
|
||||
// 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.None;
|
||||
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
|
||||
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
try
|
||||
{
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, myOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
return Text;
|
||||
}
|
||||
// }
|
||||
// }
|
||||
// Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
// return Text;
|
||||
//}
|
||||
private Dictionary<ReplaceStr, Regex> dicReplaceRegex = new Dictionary<ReplaceStr, Regex>();
|
||||
private string DoReplaceWords2(string Text)
|
||||
{
|
||||
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
FoundMatches myMatches = new FoundMatches(Text);
|
||||
myMatches.Add(regFindLink, null);
|
||||
//KBR myMatches.Add(regFindLink, null);
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// Loop through text looking for words to be replaced
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
bool replaceit = false;
|
||||
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
|
||||
@ -1326,6 +1324,7 @@ namespace Volian.Controls.Library
|
||||
if (!dicReplaceRegex.ContainsKey(rs))
|
||||
{
|
||||
// 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;
|
||||
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
|
||||
string pat = @"(?<=\W|^)(?<!\\u160\?)" + replaceWord + @"(?!\\u160\?)(?=\W|$)";
|
||||
@ -1339,7 +1338,6 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Text = myMatches.ReplaceMatches();
|
||||
@ -1361,8 +1359,6 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private bool PartOfLinkText(Match myMatch, MatchCollection myLinks)
|
||||
{
|
||||
if (_MyItemInfo.ItemID == 152)
|
||||
Console.Write("");
|
||||
foreach (Match myLink in myLinks)
|
||||
if (myMatch.Index > myLink.Index && myMatch.Index < (myLink.Index + myLink.Length))
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user