This commit is contained in:
Kathy Ruffing 2010-10-07 12:42:59 +00:00
parent 3000d61d8c
commit c26e539b15

View File

@ -253,8 +253,6 @@ namespace Volian.Controls.Library
} }
private string DoTransitionAdjustments(string text) private string DoTransitionAdjustments(string text)
{ {
if (_MyItemInfo.ItemID == 230 || _MyItemInfo.ItemID == 154 || _MyItemInfo.ItemID == 1932)
Console.Write("");
string strippedText = StaticStripRtfCommands(text); string strippedText = StaticStripRtfCommands(text);
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):[0-9]* ([0-9]*).*?\[END>"); 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); MatchCollection matches = Regex.Matches(text, lookFor);
@ -1163,153 +1161,153 @@ namespace Volian.Controls.Library
} }
#endregion #endregion
#region ReplaceWords #region ReplaceWords
private string DoReplaceWords(string Text) //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))
//{ //{
// res += Text.Substring(cpindx, m.Index - cpindx); // ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
// cpindx += (m.Index - cpindx); // foreach (ReplaceStr rs in rsl)
// res += rs.ReplaceWith; // {
// cpindx += rs.ReplaceWord.Length; // 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);
// }
// }
// // 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;
//} //}
//if (cpindx < Text.Length) res += Text.Substring(cpindx, Text.Length - cpindx); //private string DoReplaceWords1(string Text)
//Text = res; //{
// 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;
// If there are Regex Control Characters '\[]()' prefix them with backslash // // note that the order of this check is important. Check in this order...
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0"); // // background here
//string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)"; // if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
// jsj 07Jun2010 HardSpaces defeat replaceword logic // else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
//string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)"; // else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)"; // else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
try // else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
{ // else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase); // //else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
//Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase); // else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
}
catch (Exception ex)
{
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
}
} // if (replaceit)
// CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case // {
else if ((rs.Flag & E_ReplaceFlags.CaseInsensAll) > 0) // // 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;
// only in Maine Yankee - we don't need to do this one. // string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
} // string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
// CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord, // try
// except the case where the first character may be different // {
else if ((rs.Flag & E_ReplaceFlags.CaseInsensFirst) > 0) // Text = ReplaceWord(Text, pat, rs.ReplaceWith, myOptions);
{ // }
// only used in V.C. Summer - we don't need to do this either. // catch (Exception ex)
} // {
else // Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
{ // }
// 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
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space // return Text;
//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;
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;
}
private Dictionary<ReplaceStr, Regex> dicReplaceRegex = new Dictionary<ReplaceStr, Regex>(); private Dictionary<ReplaceStr, Regex> dicReplaceRegex = new Dictionary<ReplaceStr, Regex>();
private string DoReplaceWords2(string Text) private string DoReplaceWords2(string Text)
{ {
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps. if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
FoundMatches myMatches = new FoundMatches(Text); FoundMatches myMatches = new FoundMatches(Text);
myMatches.Add(regFindLink, null); //KBR myMatches.Add(regFindLink, null);
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList; ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
// Loop through text looking for words to be replaced // Loop through text looking for words to be replaced
foreach (ReplaceStr rs in rsl) foreach (ReplaceStr rs in rsl)
{ {
bool replaceit = false; bool replaceit = false;
// note that the order of this check is important. Check in this order... // note that the order of this check is important. Check in this order...
// background here // background here
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true; if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
@ -1326,7 +1324,8 @@ namespace Volian.Controls.Library
if (!dicReplaceRegex.ContainsKey(rs)) if (!dicReplaceRegex.ContainsKey(rs))
{ {
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is // 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; //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 replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
string pat = @"(?<=\W|^)(?<!\\u160\?)" + replaceWord + @"(?!\\u160\?)(?=\W|$)"; string pat = @"(?<=\W|^)(?<!\\u160\?)" + replaceWord + @"(?!\\u160\?)(?=\W|$)";
dicReplaceRegex.Add(rs, new Regex(pat, myOptions)); dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
@ -1339,7 +1338,6 @@ namespace Volian.Controls.Library
{ {
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message); Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message);
} }
} }
} }
Text = myMatches.ReplaceMatches(); Text = myMatches.ReplaceMatches();
@ -1361,8 +1359,6 @@ namespace Volian.Controls.Library
} }
private bool PartOfLinkText(Match myMatch, MatchCollection myLinks) private bool PartOfLinkText(Match myMatch, MatchCollection myLinks)
{ {
if (_MyItemInfo.ItemID == 152)
Console.Write("");
foreach (Match myLink in myLinks) foreach (Match myLink in myLinks)
if (myMatch.Index > myLink.Index && myMatch.Index < (myLink.Index + myLink.Length)) if (myMatch.Index > myLink.Index && myMatch.Index < (myLink.Index + myLink.Length))
return true; return true;