* Don't use 'size_t len' variable for utf8_encoded_valid_unichar()
return code as it returns negative numbers on invalid utf8 sequence.
* Don't rely only on \0, but check the current position against output
buffer size.
* Accept hex encoding like the original version.
* Use else-if to avoid unnecessary 'continue'.
Signed-off-by: Karel Zak <kzak@redhat.com>