From 799af1166458a3b85267b4b4495ee5cc42c9d58d Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 23 Nov 2021 14:07:17 +0000 Subject: [PATCH] F2021-093: BNPP1 & BNPPalr - replace space with hard space between number & units F2021-093: replace space with hard space between number & units --- PROMS/Formats/fmtall/BNPP1all.xml | Bin 189430 -> 194262 bytes PROMS/Formats/fmtall/BNPPalrall.xml | Bin 204520 -> 208166 bytes .../Extension/DisplayText.cs | 172 ++++++++++++------ 3 files changed, 113 insertions(+), 59 deletions(-) diff --git a/PROMS/Formats/fmtall/BNPP1all.xml b/PROMS/Formats/fmtall/BNPP1all.xml index eca9b25d1dd7b08488b01623ed193f305a07ee14..a0d254899a08ce414fc5d7acab9914f5b1f84159 100644 GIT binary patch delta 1405 zcmbu9%S!@L6voe~MAQnQMFg6~U?uia!%c*^iKrGX+LT3zJqQwtY#Z$g+%>`dGui}E z5{<7J6C!F6E`r*Jg`0Lk*I~S%%|mE0n{($ozw`L+{g!Mm72EM8jtcx<%1_R2aHVGy z1|R}4*oIA5gdI45Bq>~DfE$4j48blWVH##23ahX|zj0Ut50z}ucz{&zku&=s2$K*Z zV`&`b-w&tcycU+1TuA64)-=wuLrtht7fK#QeB5J;)HQ+b#B~-E8F;^z&ktewNn_VNPJRUJ!!RF9h1Hg1R#g1{xr=<}u$x#j*eUdl@%OKXnYo3b@Y5GJVD+#;WNJ pyBS-igSj#%VX`Hs8ABjCuAOBJfUqnsFm|*X++y5raEob~3;^hmE`$I8 diff --git a/PROMS/Formats/fmtall/BNPPalrall.xml b/PROMS/Formats/fmtall/BNPPalrall.xml index 01304d722c5aac9a377829f6d9a23161eb35d255..314f990ab1fcdf6ac31295765c9a1a68c9d58bad 100644 GIT binary patch delta 759 zcma))&npCB7{{Nl$f}XJNy?g5wk8-STfx6~CoFLW0JIBb&gQU;^ zZO|r7(iAPxGL^hDL`BL{AFX-!W31I6w~o>TjgZ3M8Xmc>;YH-r(Rr2f;dIqOH!tY8 zVd)$Vf#{7yaHkHLuWM)yCYUpD&s}=5c-lZF9G^8jfqugmh z_blA;w22gtSMZv|L@|*Sto9HqAbli(EL#3R!8*1qJafUqmx#v{x=Q~lF&*@{UL}_h zfY?S=#+kp`G)p_%aS@>Ggk&~UI{ LcHowsrWN%E*`~iv delta 143 zcmZ2>i|55&o`x-qcNR|fTEX~c`i0Gma@+4LWaMB4GpEm3#rOikdb9?{GFZ>ZGJV4i zBraH=+Vm+K8Q*OOnjpXk(xNgwY#ZYTh-S9kj9(xuu;!e-FbNR1{nUQO?WguL#pD72 DB#c5q diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs index f50d846f..cbc47b55 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs @@ -2061,58 +2061,57 @@ namespace VEPROMS.CSLA.Library // F2021-053: BNPP Alarm - need ability to have super/sub scripts in the text of Alarm Tables (ROs). // if doing replace words for Page List items, the current item is not a step, use _DoReplWordInPageList flags this if (_MyItemInfo.MyContent.Type < 20000 && !_DoReplWordInPageList) return Text; // for now only replace in steps. + FormatConfig.ReplaceStrData rsl = _MyFormat.PlantFormat.UCFandOrigReplaceStrData; + if (rsl.Count == 1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return Text; + + // F2021-093: Handle partials first and then plain replace words. Need to do this so that the words don't get processed by plain replace + // words then not found when hitting the partials, for example cm2 (plain replaced to superscript 2) and then Kg/cm2 for partials is + // not found. Note that when this was done (11/2021) only BGE & BNPP had partials and BGE's were very limited. + Text = DoReplacePartials(Text, rsl); + VE_Font vf = _MyItemInfo.MyContent.Type >= 20000 ? _MyItemInfo.FormatStepData.Font : _MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font; FoundMatches myMatches = new FoundMatches(Text,vf,_MyItemInfo); // Exclude Link Text from Replace Word process myMatches.AddLink(regFindLink, _MyFormat.PlantFormat.FormatData.SectData.ReplaceWordsInROs, _MyItemInfo.MyProcedure.MyDocVersion); - FormatConfig.ReplaceStrData rsl = _MyFormat.PlantFormat.UCFandOrigReplaceStrData; - - // ReplaceStrData xml node is empty, it does the inheritance and gets the 'base' format's list. - if (rsl.Count==1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return Text; // Loop through text looking for words to be replaced - Dictionary partialReplaceList = new Dictionary(); Dictionary shouldReplace = new Dictionary(); //int profileDepth = ProfileTimer.Push(">>>> DoReplaceWords2.ForLoop"); - foreach (FormatConfig.ReplaceStr rs in rsl) + foreach (FormatConfig.ReplaceStr rs in rsl) { bool dopartial = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.Partials) == E_ReplaceFlags.Partials; - bool onlyDoList = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.BeforeList) == E_ReplaceFlags.BeforeList; // C2021-045 - bool onlyIfFirstWord = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.FirstWord) == E_ReplaceFlags.FirstWord; // C2021-056 - bool doInPagelist = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.PageList) == E_ReplaceFlags.PageList; // B2021-132 - //B2021-132 only do replacewords in paglist if the replaceword pagelist flag is set - if (_DoReplWordInPageList && !doInPagelist) continue; + if (!dopartial) // F2021-093: Partials moved into their own method and done first + { + bool onlyDoList = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.BeforeList) == E_ReplaceFlags.BeforeList; // C2021-045 + bool onlyIfFirstWord = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.FirstWord) == E_ReplaceFlags.FirstWord; // C2021-056 + bool doInPagelist = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.PageList) == E_ReplaceFlags.PageList; // B2021-132 + //B2021-132 only do replacewords in paglist if the replaceword pagelist flag is set + if (_DoReplWordInPageList && !doInPagelist) continue; - // note that the order of this check is important. Check in this order... - // background here - if (!shouldReplace.ContainsKey((E_ReplaceFlags)rs.Flag)) - { - //int profileDepth2 = ProfileTimer.Push(">>>> Before ShouldReplaceIt"); - shouldReplace.Add((E_ReplaceFlags)rs.Flag, ShouldReplaceIt((E_ReplaceFlags)rs.Flag)); - //ProfileTimer.Pop(profileDepth2); - } - bool replaceit = shouldReplace[(E_ReplaceFlags)rs.Flag]; - - if (replaceit) - { - // C2021-045 if the BeforeList ReplaceWords flag is set, only do the replace word if the text ends with a colon - if (onlyDoList && !Text.EndsWith(":")) - replaceit = false; // text does not end with a colon so don't replace this word - // C2021-056 if FirstWord ReplaceWords flag is set, only do if the replace word is the first word in the text - if (onlyIfFirstWord && !Text.StartsWith(rs.ReplaceWord)) - replaceit = false; - } - if (!replaceit && _DoReplWordInPageList) replaceit = true; // F2021-053: Do replace words in page list - if (replaceit) - { - if (!dicReplaceRegex.ContainsKey(rs)) + // note that the order of this check is important. Check in this order... + // background here + if (!shouldReplace.ContainsKey((E_ReplaceFlags)rs.Flag)) { - RegexOptions myOptions = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; - if (dopartial) - { - dicReplaceRegex.Add(rs, new Regex(rs.ReplaceWord, myOptions)); - } - else + //int profileDepth2 = ProfileTimer.Push(">>>> Before ShouldReplaceIt"); + shouldReplace.Add((E_ReplaceFlags)rs.Flag, ShouldReplaceIt((E_ReplaceFlags)rs.Flag)); + //ProfileTimer.Pop(profileDepth2); + } + bool replaceit = shouldReplace[(E_ReplaceFlags)rs.Flag]; + + if (replaceit) + { + // C2021-045 if the BeforeList ReplaceWords flag is set, only do the replace word if the text ends with a colon + if (onlyDoList && !Text.EndsWith(":")) + replaceit = false; // text does not end with a colon so don't replace this word + // C2021-056 if FirstWord ReplaceWords flag is set, only do if the replace word is the first word in the text + if (onlyIfFirstWord && !Text.StartsWith(rs.ReplaceWord)) + replaceit = false; + } + if (!replaceit && _DoReplWordInPageList) replaceit = true; // F2021-053: Do replace words in page list + if (replaceit) + { + if (!dicReplaceRegex.ContainsKey(rs)) { + RegexOptions myOptions = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; //int profileDepth3 = ProfileTimer.Push(">>>> DoReplaceWords2.BuildMatch"); // 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; @@ -2128,19 +2127,17 @@ namespace VEPROMS.CSLA.Library dicReplaceRegex.Add(rs, new Regex(pat, myOptions)); //ProfileTimer.Pop(profileDepth3); } + try + { + //int profileDepth4 = ProfileTimer.Push(">>>> DoReplaceWords2.Partial"); + myMatches.Add(dicReplaceRegex[rs], rs); + //ProfileTimer.Pop(profileDepth4); + } + catch (Exception ex) + { + Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message); + } } - try - { - //int profileDepth4 = ProfileTimer.Push(">>>> DoReplaceWords2.Partial"); - if (!dopartial) myMatches.Add(dicReplaceRegex[rs], rs); - else partialReplaceList.Add(rs, dicReplaceRegex[rs]); - //ProfileTimer.Pop(profileDepth4); - } - catch (Exception ex) - { - Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message); - } - dopartial = false; } } //ProfileTimer.Pop(profileDepth); @@ -2148,14 +2145,71 @@ namespace VEPROMS.CSLA.Library Text = myMatches.ReplaceMatches(); //ProfileTimer.Pop(profileDepth5); Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space - try + return Text; + } + // F2021-093: separate out partial replace words so that they can all be done before normal replace words. Partials read in the 'repword', use + // it as-is as a dotnet regular expression to do replacement. Aside from the dotnet regular expression process, the rest of this + // code is similar to plain regular expressions, in terms of processing flags for which steps, etc. + private string DoReplacePartials(string Text, FormatConfig.ReplaceStrData rsl) + { + Dictionary partialReplaceList = new Dictionary(); + Dictionary shouldReplace = new Dictionary(); + foreach (FormatConfig.ReplaceStr rs in rsl) { - foreach (FormatConfig.ReplaceStr prs in partialReplaceList.Keys) - Text = partialReplaceList[prs].Replace(Text, prs.ReplaceWith); - } - catch (Exception ex) // Don't crash on a format issue. - { - _MyLog.WarnFormat("{0} - {1}", ex.GetType().Name, ex.Message); + bool dopartial = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.Partials) == E_ReplaceFlags.Partials; + if (dopartial) + { + bool onlyDoList = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.BeforeList) == E_ReplaceFlags.BeforeList; // C2021-045 + bool onlyIfFirstWord = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.FirstWord) == E_ReplaceFlags.FirstWord; // C2021-056 + bool doInPagelist = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.PageList) == E_ReplaceFlags.PageList; // B2021-132 + //B2021-132 only do replacewords in paglist if the replaceword pagelist flag is set + if (_DoReplWordInPageList && !doInPagelist) continue; + + // note that the order of this check is important. Check in this order... + if (!shouldReplace.ContainsKey((E_ReplaceFlags)rs.Flag)) + { + shouldReplace.Add((E_ReplaceFlags)rs.Flag, ShouldReplaceIt((E_ReplaceFlags)rs.Flag)); + } + bool replaceit = shouldReplace[(E_ReplaceFlags)rs.Flag]; + + if (replaceit) + { + // C2021-045 if the BeforeList ReplaceWords flag is set, only do the replace word if the text ends with a colon + if (onlyDoList && !Text.EndsWith(":")) + replaceit = false; // text does not end with a colon so don't replace this word + // C2021-056 if FirstWord ReplaceWords flag is set, only do if the replace word is the first word in the text + if (onlyIfFirstWord && !Text.StartsWith(rs.ReplaceWord)) + replaceit = false; + } + if (!replaceit && _DoReplWordInPageList) replaceit = true; // F2021-053: Do replace words in page list + if (replaceit) + { + if (!dicReplaceRegex.ContainsKey(rs)) + { + RegexOptions myOptions = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; + dicReplaceRegex.Add(rs, new Regex(rs.ReplaceWord, myOptions)); + } + try + { + partialReplaceList.Add(rs, dicReplaceRegex[rs]); + } + catch (Exception ex) + { + Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message); + } + } + } + Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space + try + { + foreach (FormatConfig.ReplaceStr prs in partialReplaceList.Keys) + Text = partialReplaceList[prs].Replace(Text, prs.ReplaceWith); + //if (partialReplaceList.Count>0) GC.Collect(); // microsoft had a memory leak in regular expression code - this REALLY slows it down though + } + catch (Exception ex) // Don't crash on a format issue. + { + _MyLog.WarnFormat("{0} - {1}", ex.GetType().Name, ex.Message); + } } return Text; }