Fix replacing colors with "0x" prefix with length different than 6

We used to assume that if the selected text started with "0x" when
inserting a color, we had to replace exactly 6 bytes after the "0x"
prefix.  Although this is generally the case as most color formats use
6 hexadecimal digits, it still would erase either too many or too few
characters if actually replacing something shorter (i.e. "0xfff") or
longer (i.e. "0xffffffffffff").

It could even partially override multi-byte characters if the 8th byte
after the selection start was in the middle of a character, as the
length was in bytes and not characters.

Fix this by honoring the actual selection end.
Export: don't try to read past the document end

A faulty bound checking resulted in reading a byte past the document
end, which resulted in Scintilla returning byte 0 because the position
was invalid.  By adding this NUL byte to the string used to build the
body, the body was truncated after the last document byte (as C strings
are NUL-terminated), leading to any format structure after it to be
missing from the output.

This broke HTML and LaTeX export if the last line didn't end with a
newline, as the last line's style closing structure were missing.
Export: don't include unused, random styles

Fix the bounds checking on included styles only to check for inclusion
actually defined styles, not to include random styles based on
uninitialized array indices.
Export: fix LaTeX export for more than 2 consecutive '-', '<' or '>'

Fix escaping of '-', '<' and '>' characters to properly handle inputs
with more than 2 consecutive identical characters of this set.
Export: use `DOC_FILENAME()` instead of re-implementing it manually
Export: escape file name in case it contains HTML control characters
Merge branch 'export/fixes'
Update NEWS