B2022-015: BNPP - Added an ‘NotInRO flag’ for replace words to determine whether RO text should have Replace Words applied

This commit is contained in:
Kathy Ruffing 2022-01-21 15:23:47 +00:00
parent 6808579c38
commit 1e217c71ec
3 changed files with 39 additions and 20 deletions

View File

@ -304,7 +304,8 @@ namespace VEPROMS.CSLA.Library
BeforeTrans = 0x80000, // Only do replace if the string occurs immediately before a transition.
BeforeList = 0x100000, // C2021-045 Only if the text ends with a colon ":"
PageList = 0x200000, // F2021-053 Do replace words for PageList items that are ROs
FirstWord = 0x400000 // C2021-056 Do only if is the first word in the text
FirstWord = 0x400000, // C2021-056 Do only if is the first word in the text
NotInRO = 0x800000 // B2022-015 BNPPalr: Determine whether RO text should have Replace Words applied
}
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]

View File

@ -2443,18 +2443,21 @@ namespace VEPROMS.CSLA.Library
{
if (foundMatch.MyWord != null)
{
if (VerifyNoHardSpace(text, foundMatch, offset) && VerifyNoLink(text, foundMatch, offset))
// B2022-015 BNPPalr: Determine whether RO text should have Replace Words applied. InLinkAndNotInRoFlag checks
// for flag on replace word item & checks that it is within and RO link
bool InLinkAndNotInRoFlag = ((foundMatch.MyWord.Flag & FormatConfig.E_ReplaceFlagsUCF.NotInRO) != 0) ? VerifyWithinLink(text, foundMatch, offset) : false;
if (!InLinkAndNotInRoFlag && VerifyNoHardSpace(text, foundMatch, offset) && VerifyNoLink(text, foundMatch, offset))
{
//if(offset != 0 || foundMatch.MyMatch.Index != 0 || !foundMatch.MyWord.ReplaceWith.StartsWith(@"{\par}"))
//{
if (((foundMatch.MyWord.Flag & FormatConfig.E_ReplaceFlagsUCF.DiffUnit) == 0) || DiffUnit(foundMatch.MyWord.ReplaceWord,_MyItemInfo,"UNIT "))
{
string with = foundMatch.MyWord.ReplaceWith;
if (((foundMatch.MyWord.Flag & FormatConfig.E_ReplaceFlagsUCF.DiffUnit) == 0) || DiffUnit(foundMatch.MyWord.ReplaceWord, _MyItemInfo, "UNIT "))
{
string with = foundMatch.MyWord.ReplaceWith;
if (offset == 0 && with.StartsWith(@"{\par}"))
if(StartsWith(text,foundMatch.MyMatch.Index,"",@"\ul ",@"\b ",@"* ",@"* \ul ",@"* \b ",@"*",@"*\ul ",@"*\b "))
if (StartsWith(text, foundMatch.MyMatch.Index, "", @"\ul ", @"\b ", @"* ", @"* \ul ", @"* \b ", @"*", @"*\ul ", @"*\b "))
with = with.Replace(@"{\par}", "");
bool IsBold = ((_Font.Style & E_Style.Bold) == E_Style.Bold) ||
(_MyItemInfo.FormatStepData != null && _MyItemInfo.FormatStepData.BoldHighLevel && _MyItemInfo.IsRNOPart && _MyItemInfo.MyParent.IsHigh );
(_MyItemInfo.FormatStepData != null && _MyItemInfo.FormatStepData.BoldHighLevel && _MyItemInfo.IsRNOPart && _MyItemInfo.MyParent.IsHigh);
// B2019-034 If the word to be replaced in the procedure text was manually bolded, remove the bold on/off commands from the replacement word
if (!IsBold)
{
@ -2471,12 +2474,12 @@ namespace VEPROMS.CSLA.Library
// B2019-034 added more cases to look for and remove bold on/off from the ReplaceWith word
if (IsBold && (with.Contains(@"\b ") || with.Contains(@"\b\")))
{
with = with.Replace(@"\b ","");
with = with.Replace(@"\b ", "");
with = with.Replace(@"\b\", @"\");
with = with.Replace(@"\b0 ","");
with = with.Replace(@"\b0 ", "");
with = with.Replace(@"\b0\", @"\");
if (with.EndsWith(@"\b0"))
with = with.Replace(@"\b0","");
with = with.Replace(@"\b0", "");
// Removed the following two lines of code to fix B2019-164. This change was not needed for
// B2019-092, a format file changed fixed that problem:
//if (with.LastIndexOf(@"\") > with.LastIndexOf(" ")) // B2019-092 - make sure there is a space char to terminate remaining rft formatting command
@ -2505,7 +2508,7 @@ namespace VEPROMS.CSLA.Library
with = with.Replace(@"\ulnone ", "");
with = with.Replace(@"\ulnone\", @"\");
if (with.EndsWith(@"\ulnone"))
with = with.Replace(@"\ulnone","");
with = with.Replace(@"\ulnone", "");
// Removed the following two lines of code to fix B2019-164. This change was not needed for
// B2019-092, a format file changed fixed that problem:
//if (with.LastIndexOf(@"\") > with.LastIndexOf(" ")) // B2019-092 - make sure there is a space char to terminate remaining rft formatting command
@ -2513,10 +2516,10 @@ namespace VEPROMS.CSLA.Library
}
string preceedingText = text.Substring(0, offset + foundMatch.MyMatch.Index);
int ndxBold = preceedingText.LastIndexOf(@"\b");
if (ndxBold > -1 && preceedingText.Length>( ndxBold + 2) && preceedingText[ndxBold + 2] != '0' && with.Contains(@"\b "))
if (ndxBold > -1 && preceedingText.Length > (ndxBold + 2) && preceedingText[ndxBold + 2] != '0' && with.Contains(@"\b "))
{
with = with.Replace(@"\b ","");
with = with.Replace(@"\b0 ","");
with = with.Replace(@"\b ", "");
with = with.Replace(@"\b0 ", "");
}
int ndxULine = preceedingText.LastIndexOf(@"\ul");
if (ndxULine > -1 && preceedingText[ndxULine + 3] != 'n' && with.Contains(@"\ul "))
@ -2525,15 +2528,29 @@ namespace VEPROMS.CSLA.Library
with = with.Replace(@"\ulnone ", "");
}
text = text.Substring(0, offset + foundMatch.MyMatch.Index) + with + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length);
//offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length;
offset += with.Length - foundMatch.MyMatch.Length;
}
text = text.Substring(0, offset + foundMatch.MyMatch.Index) + with + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length);
//offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length;
offset += with.Length - foundMatch.MyMatch.Length;
}
}
}
}
return text;
}
// B2022-015 BNPPalr: Determine whether RO text should have Replace Words applied
private bool VerifyWithinLink(string text, FoundMatch foundMatch, int offset)
{
// Is Match within a link, i.e. between a start & end and has '#Link:R' (defined referenced object link) between them too
int sindx = text.LastIndexOf("<START]", foundMatch.MyMatch.Index);
if (sindx > -1)
{
int eindx = text.IndexOf("[END>",sindx + 1);
bool isRo = eindx > sindx && text.Substring(sindx, eindx - sindx - 1).Contains("#Link:R");
if (isRo && foundMatch.MyMatch.Index > sindx && foundMatch.MyMatch.Index < eindx) return true;
}
return false;
}
private bool VerifyNoLink(string text, FoundMatch fndMatch, int offset)
{
if (text.Substring(offset + fndMatch.MyMatch.Index, fndMatch.MyMatch.Length) == "START")
@ -2542,7 +2559,7 @@ namespace VEPROMS.CSLA.Library
return false;
return true;
}
internal static bool DiffUnit(string unit,ItemInfo myItemInfo,string prefix)
internal static bool DiffUnit(string unit,ItemInfo myItemInfo,string prefix)
{
if (unit.StartsWith(prefix))
return unit.Substring(prefix.Length) != myItemInfo.MyDocVersion.DocVersionConfig.Unit_Number;

View File

@ -230,7 +230,8 @@ namespace VEPROMS.CSLA.Library
BeforeTrans = 0x80000, // Only do replace if the string occurs immediately before a transition.
BeforeList = 0x100000, // C2021-045 Only if the text ends with a colon ":"
PageList = 0x200000, // F2021-053: Do replace words in page list
FirstWord = 0x400000 // C2021-056 Do only if is the first word in the text
FirstWord = 0x400000, // C2021-056 Do only if is the first word in the text
NotInRO = 0x800000 // B2022-015 BNPPalr: Determine whether RO text should have Replace Words applied
}
public enum E_ArrowKeys : uint
{