|
|
|
@@ -1184,6 +1184,16 @@ namespace Volian.Controls.Library
|
|
|
|
|
}
|
|
|
|
|
return "";//Strip All
|
|
|
|
|
}
|
|
|
|
|
private static Regex reg1 = new Regex(@"\\par\r\n(?!\\)");
|
|
|
|
|
private static Regex reg2 = new Regex(@"[\r\n]", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
private static Regex reg3 = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
private static Regex reg4 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
private static Regex reg5 = new Regex( @"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
private static Regex reg6 = new Regex(@"(\\[^' \\?\r\n\t]+)(?=\\)"); // add space after token if followed by token
|
|
|
|
|
private static Regex reg7 = new Regex(@"(\\[^' \\?\r\n\t]+ )"); // take backslash xyz and evaluates them
|
|
|
|
|
private static Regex reg8 = new Regex( @"(\\[^' \\?\r\n\t]+) (?=\\)"); // remove space between tokens
|
|
|
|
|
private static Regex reg9 = new Regex( @"(\\[^' \\?\r\n\t]+) (?=\r\n)"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
public string StripRtfCommands(string rtf)
|
|
|
|
|
{
|
|
|
|
|
// replace \{ & \} with (![ & (!] respectively and then redo at end. The curly braces
|
|
|
|
@@ -1193,16 +1203,28 @@ namespace Volian.Controls.Library
|
|
|
|
|
|
|
|
|
|
// remove carriage return/newlines after \par commands (these are introduced by rtb
|
|
|
|
|
// for hard returns, goes into rtb as \par and comes out as \par\r\n):
|
|
|
|
|
retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
|
|
|
|
|
retval = reg1.Replace(retval, "\\par ");
|
|
|
|
|
retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
|
|
|
|
|
retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
|
|
|
|
|
retval = reg2.Replace(retval, ""); // Strip Carriage Returns and Newlines
|
|
|
|
|
retval = reg3.Replace(retval, "$1"); // Strip Opening and Closing Braces
|
|
|
|
|
retval = reg4.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = reg5.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = reg6.Replace(retval, "$1 "); // add space after token if followed by token
|
|
|
|
|
retval = reg7.Replace(retval, new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
retval = reg8.Replace(retval, "$1"); // remove space between tokens
|
|
|
|
|
retval = reg9.Replace(retval, "$1"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
|
|
|
|
|
//retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
|
|
|
|
|
//retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
//retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
// remove \r\n at end of string if the string has 2 or more characters
|
|
|
|
|
if (retval.EndsWith("\r\n")) retval = retval.Remove(retval.Length - 2, 2);
|
|
|
|
|
if (retval.Length == 0) return "";
|
|
|
|
@@ -1213,6 +1235,18 @@ namespace Volian.Controls.Library
|
|
|
|
|
retval = retval.TrimEnd(' ');
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Regex sreg1 = new Regex(@"\\par\r\n(?!\\)");
|
|
|
|
|
private static Regex sreg2 = new Regex(@"[\r\n]",RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
private static Regex sreg3 = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
private static Regex sreg4 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
private static Regex sreg5 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
private static Regex sreg6 = new Regex(@"(\\[^' \\?\r\n\t]+)(?=\\)"); // add space after token if followed by token
|
|
|
|
|
private static Regex sreg7 = new Regex(@"(\\[^ \\?\r\n\t]+ )"); // take backslash xyz and evaluates them
|
|
|
|
|
private static Regex sreg8 = new Regex(@"(\\[^ \\?\r\n\t]+) (?=\\)"); // remove space between tokens
|
|
|
|
|
private static Regex sreg9 = new Regex(@"(\\[^ \\?\r\n\t]+) (?=\r\n)"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This is used in the DataLoader
|
|
|
|
|
public static string StaticStripRtfCommands(string rtf)
|
|
|
|
|
{
|
|
|
|
@@ -1231,26 +1265,39 @@ namespace Volian.Controls.Library
|
|
|
|
|
|
|
|
|
|
// remove carriage return/newlines after \par commands (these are introduced by rtb
|
|
|
|
|
// for hard returns, goes into rtb as \par and comes out as \par\r\n):
|
|
|
|
|
retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\par\r\n(?=\\)", "\\par");
|
|
|
|
|
retval = sreg1.Replace(retval, "\\par ");
|
|
|
|
|
|
|
|
|
|
retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
|
|
|
|
|
retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)\\f[0-9] ", "$1 "); // remove font command - if next to another command, keep other command and space
|
|
|
|
|
// OLD: The following two lines are replaced by the more generic replace above.
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\v\\f[0-9] ", "\\v "); // remove font command - if next to Comment keep space
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\line\\f[0-9] ", "\\line "); // remove font command - if next to Line keep space
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\f[0-9] ", ""); // remove font command with ending space
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\f[0-9]", ""); // remove font command without ending space
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\par ", "\r\n");
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)(\\)", "$1 $2"); // take backslash xyz and evaluates them
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
|
|
|
|
|
retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
|
|
|
|
|
retval = sreg2.Replace(retval,""); // Strip Carriage Returns and Newlines
|
|
|
|
|
retval = sreg3.Replace(retval, "$1"); // Strip Opening and Closing Braces
|
|
|
|
|
retval = sreg4.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = sreg5.Replace(retval, ""); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
retval = sreg6.Replace(retval,"$1 "); // add space after token if followed by token
|
|
|
|
|
retval = sreg7.Replace(retval, new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
retval = sreg8.Replace(retval, "$1"); // remove space between tokens
|
|
|
|
|
retval = sreg9.Replace(retval, "$1"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
//retval = Regex.Replace(retval, @"\\par\r\n(?!\\)", "\\par ");
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\par\r\n(?=\\)", "\\par");
|
|
|
|
|
|
|
|
|
|
//retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment
|
|
|
|
|
//retval = Regex.Replace(retval, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
|
|
|
|
|
//retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
//retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
|
|
|
|
|
////retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)\\f[0-9] ", "$1 "); // remove font command - if next to another command, keep other command and space
|
|
|
|
|
//// OLD: The following two lines are replaced by the more generic replace above.
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\v\\f[0-9] ", "\\v "); // remove font command - if next to Comment keep space
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\line\\f[0-9] ", "\\line "); // remove font command - if next to Line keep space
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\f[0-9] ", ""); // remove font command with ending space
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\f[0-9]", ""); // remove font command without ending space
|
|
|
|
|
////retval = Regex.Replace(retval, @"\\par ", "\r\n");
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^' \\?\r\n\t]+)(?=\\)", "$1 "); // add space after token if followed by token
|
|
|
|
|
////retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+)(\\)", "$1 $2"); // take backslash xyz and evaluates them
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+ )", new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\\)", "$1"); // remove space between tokens
|
|
|
|
|
//retval = Regex.Replace(retval, @"(\\[^ \\?\r\n\t]+) (?=\r\n)", "$1"); // remove space before /r/n
|
|
|
|
|
|
|
|
|
|
// remove a space if there is one as the first character or the last character
|
|
|
|
|
//if (retval[0] == ' ') retval = retval.Remove(0, 1);
|
|
|
|
|
//retval = retval.TrimEnd(' ');
|
|
|
|
|