This commit is contained in:
2010-07-22 14:19:45 +00:00
parent 40a0cd2d24
commit 6fb88b406b
5 changed files with 388 additions and 178 deletions

View File

@@ -624,6 +624,7 @@ namespace Volian.Controls.Library
string outstr = instr;
outstr = outstr.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days.
//outstr = outstr.Replace(" ", @"\u160?"); // KBR TRY THIS
outstr = outstr.Replace("\xa0", @"\u160?"); // hardspace
outstr = outstr.Replace("\xb0", @"\'b0"); // degree
outstr = outstr.Replace("\x7f", @"\u916?"); // delta
@@ -666,186 +667,11 @@ namespace Volian.Controls.Library
// OLD: This function is now handled in the ConvertFortranFormatToScienctificNotation
//outstr = ConvertDOSSuperAndSubScripts(outstr);
outstr = ConvertFortranFormatToScienctificNotation(outstr);
outstr = ROFSTLookup.ConvertFortranFormatToScienctificNotation(outstr);
return outstr;
}
//public 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 (str[cnt] == '.')
// {
// cnt = NextNonNumber(str, cnt + 1);
// if (cnt >= str.Length) //jsj bug fix
// {
// outstr += str.Substring(tstr);
// break; // jump out of while loop - nothing else to process
// }
// 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
// //outstr = outstr.TrimEnd(".".ToCharArray());
// int poutstr = 0;
// if (outstr[poutstr] == '+' || outstr[poutstr] == '-') poutstr++;
// if (!outstr.Substring(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
// {
// outstr += str.Substring(start, cnt - start + 1);
// 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;
//}
public static string ConvertFortranFormatToScienctificNotation(string str)
{
// Convert E style numbers to RTF with \super and \nosupersub
string retval = Regex.Replace(str, "([+-]?)([0-9]+)[.]([0-9]*?)0*E([+-]?[0-9]+)", new MatchEvaluator(FixFortranNumber));
//retval = Regex.Replace(retval, "[#](.*?)[#]", "\\super $1\\nosupersub ");// DOS Superscript
//retval = Regex.Replace(retval, "[~](.*?)[~]", "\\sub $1\\nosupersub ");// DOS Subscript
retval = Regex.Replace(retval, "[#](.*?)[#]", "\\up3 $1\\up0 ");// DOS Superscript
retval = Regex.Replace(retval, "[~](.*?)[~]", "\\dn3 $1\\dn0 ");// DOS Subscript
return retval;
}
private static string FixFortranNumber(Match match)
{
StringBuilder sb = new StringBuilder(match.Groups[1].Value);
if (match.Groups[3].Length == 0) // Nothing to the right of the decimal
if (match.Groups[2].Value != "1") // Other than "1", multiply it times 10 raised to a power
sb.Append(match.Groups[2].Value + "x10");
else // The number is simply 1 so it can be ignored and 10 can be raised to a power
sb.Append("10");
else // A number with a decimal point
sb.Append(match.Groups[2].Value + "." + match.Groups[3].Value + "x10");
// Add the exponent as superscript
return sb.ToString() + "\\up3 " + match.Groups[4].Value + "\\up0 ";
}
//private 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;
//}
private static string _TemporaryFolder = null;
public static string TemporaryFolder
{