replace back quote and other special character in RO values during data conversion

This commit is contained in:
John Jenko 2009-09-01 13:03:25 +00:00
parent 47d6925187
commit efe1ddf609
3 changed files with 176 additions and 5 deletions

View File

@ -25,7 +25,7 @@ namespace DataLoader
{
public partial class Loader
{
private string MigrateRos(OleDbConnection cn, string textm, string seqcvt, Content content, DocVersion docver)
private string MigrateRos(OleDbConnection cn, string textm, string seqcvt, Content content, DocVersion docver, bool conv_caret)
{
StringBuilder rotxt = new StringBuilder();
int instance = 0;
@ -65,10 +65,19 @@ namespace DataLoader
try
{
string rov = rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper());
//jsj string rov = TextConvert.ConvertText(rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()));
//string results = string.Format(@"{0}{1}\v #Link:ReferencedObject:{2} {3} {4}\v0",
// '\x15', rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()), ro.ROUsageID, ROID, rodb.RODbID);
string results = string.Format(@"\v <START]\v0 {0}\v #Link:ReferencedObject:{1} {2} {3}\v0 \v [END>\v0 ",
rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()), ro.ROUsageID, ROID, rodb.RODbID);
// TODO: NEED TO PASS IN ConvertCaret FORMAT FLAG
string roval = TextConvert.ReplaceUnicode(rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()), conv_caret);
//if (roval.Contains("\r") || roval.Contains("\n"))
// Console.WriteLine("RO has new Lines");
//string results = string.Format(@"\v <START]\v0 {0}\v #Link:ReferencedObject:{1} {2} {3}\v0 \v [END>\v0 ",
// rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()), ro.ROUsageID, ROID, rodb.RODbID);
string results = string.Format(@"\v <START]\v0\cf1 {0}\cf0\v #Link:ReferencedObject:{1} {2} {3}\v0 \v [END>\v0 ",
roval.Replace("\r\n","\\par\r\n"), ro.ROUsageID, ROID, rodb.RODbID);
rotxt.Append(results);
}
catch (Exception ex)

View File

@ -76,7 +76,7 @@ namespace DataLoader
if (tokrt > -1)
{
txtdirty = true;
stptext = MigrateRos(cn, stptext, seqcvt, content, docver);
stptext = MigrateRos(cn, stptext, seqcvt, content, docver, conv_caret);
stptext = stptext.TrimEnd(" ".ToCharArray());
}

View File

@ -120,10 +120,14 @@ namespace DataLoader
return ConvertText(s2);
}
public static string ReplaceUnicode(string s2)
{
return ReplaceUnicode(s2, false);
}
public static string ReplaceUnicode(string s2, bool DoCaret)
{
char[] tmp;
tmp = s2.ToCharArray();
s2 = s2.Replace("`", "\'b0"); // convert backquote to degree - left over from DOS days.
s2 = s2.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days.
s2 = s2.Replace("\xa0",@"\u160?"); // hardspace
s2 = s2.Replace("\xb0", @"\'b0"); // degree
s2 = s2.Replace("\x7f", @"\u916?"); // delta
@ -160,12 +164,170 @@ namespace DataLoader
s2 = s2.Replace("\x2193", @"\u8595?");
s2 = s2.Replace("\x2207", @"\u8711?");
if (DoCaret) s2 = s2.Replace("^", @"\u916");
//s2 = s2.Replace("^", @"\u916");
s2 = ConvertDOSSuperAndSubScripts(s2);
s2 = ConvertFortranFormatToScienctificNotation(s2);
// Convert dash to a non-breaking dash. This is a unicode character.
// This character will be used in veproms rather than a dash.
s2 = s2.Replace("-", @"\u8209?");
return s2;
}
private static string ConvertFortranFormatToScienctificNotation(string str)
{
string outstr = "";
int orglen = str.Length;
int cnt = 0;
int ptr;
int nbytes;
int tstr, tstr2, rptr, start = 0;
while (cnt < orglen)
{
// position up to the the next number, sign, or period
ptr = str.IndexOfAny("+-0123456789.".ToCharArray(), cnt);
if (ptr == -1)
{
outstr += str.Substring(cnt);
break; // jump out of while loop - nothing else to process
}
if ((ptr - cnt) > 0)
{
outstr += str.Substring(cnt, ptr - cnt);
cnt = ptr;
}
if (cnt > start && str[cnt - 1] == '\'')
{
//B2003-053: only remove the single quote character
// if str ptr is not at the end of the string or
// the next char (after the str ptr) is not a space
// or newline... (as per Paul Linn on 7/17/03)
int len = orglen - cnt;
if (len <= 1 || str[cnt + 1] == ' ' || str[cnt + 1] == '\n')
start = cnt;
else
start = cnt - 1;
}
else start = cnt;
tstr = cnt;
//Skip preceeding signs
if (str[cnt] == '+' || str[cnt] == '-')
cnt++;
cnt = NextNonNumber(str, cnt);
if ((cnt < str.Length -1) && str[cnt] == '.')
{
cnt = NextNonNumber(str, cnt + 1);
if (str[start] == '\'')
{
start++;
}
else if (str[cnt] == 'E' && cnt > tstr)
{
nbytes = (cnt - tstr); // don't include the 'E'
outstr += str.Substring(tstr, nbytes);
cnt++;
rptr = outstr.Length - 1;
while (outstr[rptr] == '0') rptr--;
if (outstr[rptr] != '.') rptr++;
if (rptr < (outstr.Length - 1))
outstr = outstr.Substring(0, rptr + 1); // trim trailing 0's
int poutstr = 0;
if (outstr[poutstr] == '+' || outstr[poutstr] == '-') poutstr++;
if (!outstr[poutstr].Equals("1"))
{
outstr += "x1";
}
outstr += "0\\super ";
tstr2 = cnt;
if (str[cnt] == '+' || str[cnt] == '-') cnt++;
cnt = NextNonNumber(str, cnt);
if (str[cnt] == '.' && char.IsDigit(str, cnt + 1))
cnt = NextNonNumber(str, cnt + 1);
nbytes = cnt - tstr2; // +1;
outstr += str.Substring(tstr2, nbytes);
outstr += "\\nosupersub ";
if (!char.IsLetterOrDigit(str, cnt) && !char.IsWhiteSpace(str, cnt))
return (str.Substring(tstr));
}
else if (cnt > 0)
{
outstr += str.Substring(start, cnt - start + ((cnt < str.Length) ? 1 : 0));
}
}
else
{
outstr += str.Substring(start, cnt - start + ((cnt < str.Length)?1:0));
cnt++;
}
}
return (outstr);
}
private static int NextNonNumber(string str, int cnt)
{
int rtn = 0;
string tstr = str.Substring(cnt);
int len = tstr.Length;
while (rtn < len && char.IsDigit(tstr, rtn)) rtn++;
return rtn + cnt;
}
private static string ConvertDOSSuperAndSubScripts(string instr)
{
string outstr = "";
string tstr = instr;
int cnt = 0;
int ptr = 0;
bool issupper = false, issub = false;
while (tstr != null && (ptr = tstr.IndexOfAny("#~".ToCharArray(), cnt)) >= 0)
{
if (ptr > cnt)
outstr += tstr.Substring(cnt, ptr - cnt);
switch (tstr[ptr])
{
case '#':
if (issub || issupper)
outstr += "\\nosupersub ";
else
outstr += "\\super ";
issupper = !issupper;
issub = false;
break;
case '~':
if (issupper || issub)
outstr += "\\nosupersub ";
else
outstr += "\\sub ";
issub = !issub;
issupper = false;
break;
}
cnt = ptr + 1;
if (cnt >= tstr.Length)
tstr = null;
else
tstr = instr.Substring(cnt);
cnt = 0;
}
if (tstr != null)
outstr += tstr;
return outstr;
}
public static string ConvertText(string s1)
{
string s2 = s1;