0

icu::UnicodeString::fromUTF8 replaces illegal input with U+FFFD. Is there a way to detect whether it has done this, so that I can throw an exception?

1 Answers1

2

Use u_strFromUTF8

UChar* u_strFromUTF8    (   UChar *     dest,
int32_t     destCapacity,
int32_t *   pDestLength,
const char *    src,
int32_t     srcLength,
UErrorCode *    pErrorCode 
)       
Convert a UTF-8 string to UTF-16.

If the input string is not well-formed, then the U_INVALID_CHAR_FOUND error code is set

http://icu-project.org/apiref/icu4c/ustring_8h.html#a5f9ff224b11166a106d1b3ac26454cd4

Roddy
  • 66,617
  • 42
  • 165
  • 277
  • A pity that a low-level C API has to be used, but this will have to do. –  Apr 06 '15 at 10:21