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