B2018-046 - Fix code so that duplicate ROs will not cause problems when they are converted to text during import.

This commit is contained in:
Rich 2018-03-14 15:23:23 +00:00
parent f9ef66880b
commit c10da98204

View File

@ -3270,41 +3270,49 @@ namespace VEPROMS
string lookFor = string.Format(@"^<START\](\\[^v \\]+)*\\v0(\\[^v '?{{}}~\\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v'?{{}}~ \\]+)*\\v(\\[^v \\]+)* #Link:ReferencedObject:{0} .*?\[END>$", rousageid);
int lastIndex = 0;
string newText = content.Text;
foreach (Match mm in ms)
// B2018-046 This loop repeats code to convert duplicate ROs in text to text
int originalCount = 0;
while (ms.Count > 0 && (originalCount == 0 || ms.Count < originalCount))
{
int offset = mm.Index;
Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline);
if (m != null && m.Groups.Count > 1)
originalCount = ms.Count;
foreach (Match mm in ms)
{
string prefix = GetMyPrefix(content.Text, mm.Index, lastIndex);
string suffix = GetMySuffix(content.Text, mm.Index + mm.Length);
int myIndex = m.Groups[4].Index + mm.Index;
int myLength = m.Groups[4].Length;
if (m.Groups[3].Value != " ")
int offset = mm.Index;
Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline);
if (m != null && m.Groups.Count > 1)
{
myIndex = m.Groups[3].Index + mm.Index;
myLength += m.Groups[3].Length;
string prefix = GetMyPrefix(content.Text, mm.Index, lastIndex);
string suffix = GetMySuffix(content.Text, mm.Index + mm.Length);
int myIndex = m.Groups[4].Index + mm.Index;
int myLength = m.Groups[4].Length;
if (m.Groups[3].Value != " ")
{
myIndex = m.Groups[3].Index + mm.Index;
myLength += m.Groups[3].Length;
}
string gg = newText.Substring(myIndex, myLength);
gg = gg.Replace("{", @"\{").Replace("}", @"\}");
string part1 = newText.Substring(0, mm.Index);
string part2 = gg;
string part3 = newText.Substring(mm.Index + mm.Length);
//modify part1 based on prefix
if (prefix == @"\v ")
part1 = part1.Substring(0, part1.Length - 3);
else
part1 = part1.Substring(0, part1.Length - 3) + " ";
//modify part3 based on suffix
if (suffix == @"\v0 ")
part3 = part3.Substring(4);
else
part3 = suffix.Replace(@"\v0", "") + part3.Substring(suffix.Length);
content.Text = part1 + part2 + part3;
ROToTextAnnotation(content, part2); // B2016-225 (follow through) add annotation when RO is converted to text
_DidProcessROs = true; // B2017-076 flag that ROs where processed
break; // B2018-046 If it finds a match try again
}
string gg = newText.Substring(myIndex, myLength);
gg = gg.Replace("{", @"\{").Replace("}", @"\}");
string part1 = newText.Substring(0, mm.Index);
string part2 = gg;
string part3 = newText.Substring(mm.Index + mm.Length);
//modify part1 based on prefix
if (prefix == @"\v ")
part1 = part1.Substring(0, part1.Length - 3);
else
part1 = part1.Substring(0, part1.Length - 3) + " ";
//modify part3 based on suffix
if (suffix == @"\v0 ")
part3 = part3.Substring(4);
else
part3 = suffix.Replace(@"\v0", "") + part3.Substring(suffix.Length);
content.Text = part1 + part2 + part3;
ROToTextAnnotation(content, part2); // B2016-225 (follow through) add annotation when RO is converted to text
_DidProcessROs = true; // B2017-076 flag that ROs where processed
lastIndex = mm.Index + mm.Length;
}
lastIndex = mm.Index + mm.Length;
ms = Regex.Matches(content.Text, findLink); // B2018-046 Look for match again
}
}
content.Save();