Search code examples
unicodeconvertersicuiconv

How to determine whether a codec has a const ratio 'byte number per character'?


Given an IANA codec name (or, one of those used in iconv/ICU), what is the easiest way to determine whether the codec has a fixed width representation for characters or not?


Solution

  • Use ucnv_isFixedWidth():

    UErrorCode status;
    UConverter* converter = ucnv_open("koi8-r", &status);
    if (U_SUCCESS(status)) {
      UBool is_fixed = ucnv_isFixedWidth(converter, &status);
    }