public RegexColumnHandler(string regex, MapColumnHandler inner) { // Pre-Compile the Regex this.Regex = new Regex(regex, RegexOptions.Compiled); this.Inner = inner; this.Block = new String8Block(); }
public void LoadSpec() { using (ITabularReader r = new CsvReader(this.SpecFilePath, false)) { while (r.NextRow()) { string command = r.Current(0).ToString(); string columnName = r.Current(1).ToString(); switch (command.ToLowerInvariant()) { case "sample": // Sample,ColumnName,Probability this.SampleColumnName = columnName; this.SampleProbability = double.Parse(r.Current(2).ToString()); if (this.SampleProbability < 0.0 || this.SampleProbability > 1.0) { throw new UsageException($"SanitizeSpec sample probability ({r.Current(2)}) is out of range. It must be between zero and one."); } break; case "echo": // Echo,Value1,Value2,... for (int i = 1; i < r.CurrentRowColumns; ++i) { this.EchoValues.Add(r.Current(i).ToString8()); } break; case "drop": // Drop,ColumnName this.DropColumns.Add(columnName); break; case "map": // Map,ColumnName,MapperName this.HandlersByColumn.Add(columnName, new EchoColumnHandler(this.EchoValues, new MapColumnHandler(this.HashKeyHash, this.Provider.Mapper(r.Current(2).ToString())))); break; case "keep": // Keep is the default behavior, so it is in the sanispec only as a comment break; case "regex": // Regex,ColumnName,Expression,MapperName MapColumnHandler handler = new MapColumnHandler(this.HashKeyHash, this.Provider.Mapper(r.Current(3).ToString())); this.HandlersByColumn.Add(columnName, new EchoColumnHandler(this.EchoValues, new RegexColumnHandler(r.Current(2).ToString(), handler))); break; default: throw new UsageException($"SanitizeSpec mode '{command}' is unknown. Supported modes: sample, echo, drop, map, keep, regex."); } } } }