Fixed how DoROAdjustments handles curly braces

Fixed how DoTransitionAdjustments handles curly braces
Fixed how SaveContents handles curly braces
This commit is contained in:
Rich 2014-05-28 02:15:00 +00:00
parent 9ee31d43fc
commit 7f7e3085ab
2 changed files with 48 additions and 22 deletions

View File

@ -408,13 +408,13 @@ namespace Volian.Controls.Library
// (\\[^v' \\]+)* --> look for rtf commands but exclude \' before the \v
// \\v(\\[^v \\]+)* --> look for rtf commands after the \v
// if it turns out that if ro's have any embedded unicode characters this needs expanded, such as /u8209? (hard hyphen)
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v'? \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v'? \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
MatchCollection matches = Regex.Matches(text, lookFor);
string prevValue = null;
for (int i = matches.Count - 1; i >= 0; i--)
{
Match m = matches[i];
if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject")
if (m != null && m.Groups.Count > 7 && m.Groups[7].ToString() == "ReferencedObject")
{
// if previous processed (next ro) was found, then see if it has an 'and' between it and the previous
if (prevValue != null)
@ -423,22 +423,31 @@ namespace Volian.Controls.Library
string tr = text.Substring(endIndx).Replace(@"\v0","").TrimStart();
if (!tr.ToUpper().StartsWith("AND")) prevValue = null;
}
System.Text.RegularExpressions.Group g = m.Groups[3];
string beforeRO = StaticStripRtfCommands(text.Substring(0, g.Index));
string afterRO = StaticStripRtfCommands(text.Substring(g.Index + g.Length));
int myIndex = m.Groups[4].Index;
int myLength = m.Groups[4].Length;
if (m.Groups[3].Value != " ")
{
myIndex = m.Groups[3].Index;
myLength += m.Groups[3].Length;
}
string gg = text.Substring(myIndex, myLength);
//System.Text.RegularExpressions.Group g = m.Groups[3];
string beforeRO = StaticStripRtfCommands(text.Substring(0, myIndex));
string afterRO = StaticStripRtfCommands(text.Substring(myIndex + myLength));
Match myMatch = regRefObj.Match(m.ToString());
if(m.ToString().ToUpper().Contains("<NEWID>"))
_MyLog.WarnFormat("Unprocessed RO in {0},({1})",_MyItemInfo.ShortPath,g.ToString());
_MyLog.WarnFormat("Unprocessed RO in {0},({1})",_MyItemInfo.ShortPath,gg);
int dbid = System.Convert.ToInt32(myMatch.Groups[2].Value.Substring(0, 4), 16);
int rodbid = int.Parse(myMatch.Groups[3].Value);
ROFstInfo myROFst = _MyItemInfo.MyDocVersion.GetROFst(rodbid);
bool isSetpoint=myROFst.IsSetpointDB(dbid, _MyItemInfo.MyDocVersion);
string newvalue = DoROFormatFlags(g.ToString(), beforeRO, afterRO, isSetpoint, prevValue);
string newvalue = DoROFormatFlags(gg, beforeRO, afterRO, isSetpoint, prevValue);
if (!_MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.AllUnits) prevValue = newvalue;
newvalue = DoROReplaceWords(_MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList, newvalue, _MyItemInfo.IsHigh);
if (isSetpoint) newvalue = ReplaceSpaceWithHardspace(newvalue);
if (g.ToString() != newvalue)
text = text.Substring(0, g.Index) + newvalue + text.Substring(g.Index + g.Length);
newvalue = newvalue.Replace("{", @"\{").Replace("}", @"\}");
if (gg != newvalue)
text = text.Substring(0, myIndex) + newvalue + text.Substring(myIndex + myLength);
}
}
return text;
@ -493,7 +502,7 @@ namespace Volian.Controls.Library
{
bool undtran = _MyItemInfo.ActiveFormat.PlantFormat.FormatData.TransData.Underline;
string strippedText = StaticStripRtfCommands(text);
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\u]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):[0-9]* ([0-9]*).*?\[END>");
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v \\u]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):[0-9]* ([0-9]*).*?\[END>");
MatchCollection matches = Regex.Matches(text, lookFor);
if (matches.Count == 0) return text;
string retstr = text;
@ -501,25 +510,34 @@ namespace Volian.Controls.Library
{
Match m = matches[i];
// if this transition text already has a hard space, don't add another.
if (m.Groups[3].Value.Contains("\xA0")) continue;
if (m.Groups[4].Value.Contains("\xA0")) continue;
// if the transition text does not start with a digit, don't add the hardspace.
//if (!Char.IsDigit(m.Groups[3].Value[0])) continue;
if (m != null && m.Groups.Count > 7 && m.Groups[6].ToString().StartsWith("Transition"))
if (m != null && m.Groups.Count > 8 && m.Groups[7].ToString().StartsWith("Transition"))
{
if (m.Groups[7].Value != "") // && StepTransition(int.Parse(m.Groups[7].Value)))
if (m.Groups[8].Value != "") // && StepTransition(int.Parse(m.Groups[7].Value)))
{
System.Text.RegularExpressions.Group g = m.Groups[3];
string beforeTran = retstr.Substring(0, g.Index);
string afterTran = retstr.Substring(g.Index + g.Length);
int myIndex = m.Groups[4].Index;
int myLength = m.Groups[4].Length;
if (m.Groups[3].Value != " ")
{
myIndex = m.Groups[3].Index;
myLength += m.Groups[3].Length;
}
string newvalue = text.Substring(myIndex, myLength);
newvalue = newvalue.Replace("{", @"\{").Replace("}", @"\}");
//System.Text.RegularExpressions.Group g = m.Groups[3];
string beforeTran = retstr.Substring(0, myIndex);
string afterTran = retstr.Substring(myIndex + myLength);
// if replacing text in the 'beforeTran' string, then do it here,
// i.e. there is a format flag 'BeforeTrans' that bolds text before the transition
// (in wst formats).
beforeTran = DoBeforeTransFlagSupport(beforeTran, _MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ReplaceStrList);
string newvalue = g.ToString();
//string newvalue = g.ToString();
// if this is a 'step transition' type, i.e. includes a step number, in addition to other replacements,
// we want to change a space to a hardspace.
if (StepTransition(int.Parse(m.Groups[7].Value)))
if (StepTransition(int.Parse(m.Groups[8].Value)))
{
int indexLastSpace = newvalue.LastIndexOf(' ');
if (indexLastSpace >= 0)

View File

@ -502,12 +502,12 @@ namespace Volian.Controls.Library
{
// see if there are any links and save these so that any deleted ROs or transitions in the
// steprtb can have associated usages/transitions records removed from the database.
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor);
for (int i = matches.Count - 1; i >= 0; i--)
{
Match m = matches[i];
if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString() == "ReferencedObject")
if (m != null && m.Groups.Count > 7 && m.Groups[7].ToString() == "ReferencedObject")
{
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
Match myMatch = regRefObj.Match(m.Value);
@ -517,7 +517,7 @@ namespace Volian.Controls.Library
RtfRoUsageList.Add(usgid);
}
}
if (m != null && m.Groups.Count > 6 && m.Groups[6].ToString().StartsWith("Transition"))
if (m != null && m.Groups.Count > 7 && m.Groups[7].ToString().StartsWith("Transition"))
{
Regex regRefObj = new Regex(@"\#Link\:Transition[a-zA-Z]*\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline);
Match myMatch = regRefObj.Match(m.Value);
@ -525,7 +525,15 @@ namespace Volian.Controls.Library
{
int tid = int.Parse(myMatch.Groups[2].Value);
RtfTransList.Add(tid);
if (m.Groups[3].Value.Contains("(Page ~)")) RtfTransPageNumList.Add(tid);
int myIndex = m.Groups[4].Index;
int myLength = m.Groups[4].Length;
if (m.Groups[3].Value != " ")
{
myIndex = m.Groups[3].Index;
myLength += m.Groups[3].Length;
}
string gg = ((string)MyFlexGrid[r, c]).Substring(myIndex, myLength);
if (gg.Contains("(Page ~)")) RtfTransPageNumList.Add(tid);
}
}
}