private static Replacement RowToReplacement(DataGridViewRow dataGridRow)
{
Replacement rep = new Replacement
{
Enabled = ((bool)dataGridRow.Cells["enabled"].FormattedValue),
Minor = ((bool)dataGridRow.Cells["minor"].FormattedValue),
IsRegex = ((bool)dataGridRow.Cells["regex"].FormattedValue),
BeforeOrAfter = ((bool)dataGridRow.Cells["BeforeOrAfter"].FormattedValue)
};
if (dataGridRow.Cells["replace"].Value == null)
dataGridRow.Cells["replace"].Value = "";
string f = Encode(dataGridRow.Cells["find"].Value.ToString());
string r = Encode(dataGridRow.Cells["replace"].Value.ToString());
// in F&R newline matching is on \n, so if not a regex ensure this isn't escaped
if (!rep.IsRegex)
{
bool newlines = f.Contains("\\n");
f = Regex.Escape(f);
if (newlines)
f = f.Replace(@"\\n", "\n");
}
rep.Find = f;
rep.Replace = r;
if (!(bool)dataGridRow.Cells["casesensitive"].FormattedValue)
rep.RegularExpressionOptions |= RegexOptions.IgnoreCase;
if ((bool)dataGridRow.Cells["multi"].FormattedValue)
rep.RegularExpressionOptions |= RegexOptions.Multiline;
if ((bool)dataGridRow.Cells["single"].FormattedValue)
rep.RegularExpressionOptions |= RegexOptions.Singleline;
rep.Comment = (string)dataGridRow.Cells["comment"].FormattedValue ?? "";
return rep;
}