Do case-insensitive comparison with utf-8 encoding

Also include the actual encoding specified in error message when it's
not unspecified and not utf-8.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Add tests for remaining encoding/mode interactions

I think that covers the interesting cases.

Signed-off-by: Anton Lofgren <alofgren@op5.com>