Detect the encoding to use to save a document.
First try latin1, and if that fails, save as utf8.
This is the same algo as guiguts.
Detect the encoding to use to load a document. First, try utf8, and
if that fails, try latin1. This is the same algo as guiguts.