I didn’t feel like using XML for the input file of my T4 so I made this snippet that splits up a document into chunks separated by a blank line.
Am I appropriately making the carriage return optional here?
string s = @"Default
Default
CurrencyConversion
Details of currency conversions.
BudgetReportCache
Indicates wheather the budget report is taken from query results or cache.";
string oneLine = @"[\r]\n";
string twoLines = @"[\r]\n[\r]\n";
var chunks = Regex.Split(s, twoLines, RegexOptions.Multiline);
var items = chunks.Select(c=>Regex.Split(c, oneLine, RegexOptions.Multiline)).ToDictionary(c=>c[0], c=>c[1]);
Note: I would never have thought of this, but since I started using Git, I have seen it “say” things that reminded me of the unix2dos issues, which in turn made me think of Mono and finally if I needed to deal with portability (assuming the goal is perfection).
Your regular expressions doesn’t do what you think that they do. Putting
\rinside a set doesn’t accomplish anything; the expression[\r]\nmeans the same thing as just\r\n.You can make the work using the
?operator:However, I would suggest that you use the regular
String.Splitmethod instead of regular expressions: