From 1e217c71ecd5e970fa32a739ba688bf35ad9343f Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 21 Jan 2022 15:23:47 +0000 Subject: [PATCH] =?UTF-8?q?B2022-015:=20BNPP=20-=20Added=20an=20=E2=80=98N?= =?UTF-8?q?otInRO=20flag=E2=80=99=20for=20replace=20words=20to=20determine?= =?UTF-8?q?=20whether=20RO=20text=20should=20have=20Replace=20Words=20appl?= =?UTF-8?q?ied?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/FormatConfig.cs | 3 +- .../Extension/DisplayText.cs | 53 ++++++++++++------- PROMS/VEPROMS.CSLA.Library/Format/ENums.cs | 3 +- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Config/FormatConfig.cs b/PROMS/VEPROMS.CSLA.Library/Config/FormatConfig.cs index d1a6fdad..a60f7dc5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Config/FormatConfig.cs +++ b/PROMS/VEPROMS.CSLA.Library/Config/FormatConfig.cs @@ -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))] diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs index 389e37ff..b9ad0099 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs @@ -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(" -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; diff --git a/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs index c3b552e1..e4eefcc3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs @@ -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 {