Logo Search packages:      
Sourcecode: m17n-lib version File versions  Download package

int mcharset__decode_char ( MCharset charset,
unsigned  code 
)

Return the character corresponding to code-point CODE in CHARSET. If CODE is invalid for CHARSET, return -1.

Definition at line 472 of file charset.c.

References CODE_POINT_TO_INDEX, DECODE_CHAR, and MERROR.

{
  int idx;

  if (code < 128 && charset->ascii_compatible)
    return (int) code;
  if (code < charset->min_code || code > charset->max_code)
    return -1;

  if (! charset->fully_loaded
      && load_charset_fully (charset) < 0)
    MERROR (MERROR_CHARSET, -1);

  if (charset->method == Msubset)
    {
      MCharset *parent = charset->parents[0];

      code -= charset->subset_offset;
      return DECODE_CHAR (parent, code);
    }

  if (charset->method == Msuperset)
    {
      int i;

      for (i = 0; i < charset->nparents; i++)
      {
        MCharset *parent = charset->parents[i];
        int c = DECODE_CHAR (parent, code);

        if (c >= 0)
          return c;
      }
      return -1;
    }

  idx = CODE_POINT_TO_INDEX (charset, code);
  if (idx < 0)
    return -1;

  if (charset->method == Mmap)
    return charset->decoder[idx];

  if (charset->method == Munify)
    {
      int c = charset->decoder[idx];

      if (c < 0)
      c = charset->unified_max + 1 + idx;
      return c;
    }

  /* Now charset->method should be Moffset.  */
  return (charset->min_char + idx);
}


Generated by  Doxygen 1.6.0   Back to index