micro
micro copied to clipboard
Support `-bom` in `encoding` option and detect BOM
BOM is read and written in files if encoding
option ends in -bom
in this pull request. There are not much encodings supporting BOM so the encoding has to be checked when BOM is used. A new option where usage of BOM is enabled is not added because both options cannot be validated when one is set.
The option is set when BOM is detected using utfbom so utfbom is added as a dependency package. Setting encoding
to UTF-32 is not supported so the option is not set when UTF-32 is detected. Bytes that are not valid UTF-8 text are modified so UTF-32 BOM is intentionally not included in buffer.
BOM is not written in empty files when transform.Writer.Close
is not called in overwriteFile
in internal/buffer/save.go
so the method is called. It has been not tested if there is an unexpected bug with calling the method.
Closes #3369