jehugaleahsa / FlatFiles

Reads and writes CSV, fixed-length and other flat file formats with a focus on schema definition, configuration and speed.
The Unlicense
357 stars 64 forks source link

Fixed width writer: Change truncation behavior so it respects field alignment #8

Closed lukas-shawford closed 9 years ago

lukas-shawford commented 9 years ago

Hello,

I'm considering using this library for generating reports, and noticed one issue with the truncation behavior for fixed width files. Currently, if the value is too wide to fit inside the field, the behavior is to always keep the end of the value. I think it would be a lot more intuitive to change this behavior so that it respects the Alignment value. So, if the field is normally left-aligned, then the start will be kept; if the field is right-aligned, then the end is kept.

An alternative would be to create a separate property inside Window to specify the truncation behavior (instead of reusing Alignment) - if you like this idea better, let me know and I can put up a new pull request.

jehugaleahsa commented 9 years ago

I couldn't take your request line-for-line, but it was very tempting. I can't believe I didn't think to do this earlier. The unfortunate reality is I can't switch to a different truncation policy based on the alignment automatically because it could potentially break existing code bases. Instead, I have added a new enum called OverflowTruncationPolicy that can be set on individual Windows. There is also a global property on the FixedLengthOptions class to set a global policy for the entire writer.

Hopefully this doesn't cause you too much pain to migrate to.

lukas-shawford commented 9 years ago

No problem at all - thanks for adding support for this!