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);
// } // }
//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"); // // CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case
//string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)"; // else if ((rs.Flag & E_ReplaceFlags.CaseInsensAll) > 0)
// jsj 07Jun2010 HardSpaces defeat replaceword logic // {
//string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?=[^\\u160?]|\W|$)"; // // only in Maine Yankee - we don't need to do this one.
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)"; // }
try // // CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord,
{ // // except the case where the first character may be different
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase); // else if ((rs.Flag & E_ReplaceFlags.CaseInsensFirst) > 0)
//Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase); // {
} // // 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);
// }
// }
} // }
// CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case // }
else if ((rs.Flag & E_ReplaceFlags.CaseInsensAll) > 0) // //Console.WriteLine("--- Before '{0}'", Text);
{ // Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
// only in Maine Yankee - we don't need to do this one. // //Console.WriteLine("--- After '{0}'", Text);
} // return Text;
// CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord, //}
// except the case where the first character may be different //private string DoReplaceWords1(string Text)
else if ((rs.Flag & E_ReplaceFlags.CaseInsensFirst) > 0) //{
{ // if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
// only used in V.C. Summer - we don't need to do this either. // ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
} // // Loop through text looking for words to be replaced
else // foreach (ReplaceStr rs in rsl)
{ // {
// If there are Regex Control Characters '\[]()' prefix them with backslash // bool replaceit = false;
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);
}
}
} // // note that the order of this check is important. Check in this order...
} // // background here
//Console.WriteLine("--- Before '{0}'", Text); // if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space // else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
//Console.WriteLine("--- After '{0}'", Text); // else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
return Text; // else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
} // else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
private string DoReplaceWords1(string Text) // else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
{ // //else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps. // else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
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... // if (replaceit)
// background here // {
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true; // // CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true; // RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None;
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true; // string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true; // string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true; // try
else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true; // {
//else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true; // Text = ReplaceWord(Text, pat, rs.ReplaceWith, myOptions);
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) // }
{ // }
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is // Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; // return Text;
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,6 +1324,7 @@ 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.Singleline : RegexOptions.None & RegexOptions.Singleline;
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.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|$)";
@ -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;