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

unsigned mcharset__encode_char ( MCharset charset,
int  c 
)

Return the code point of character C in CHARSET. If CHARSET does not contain C, return MCHAR_INVALID_CODE.

Definition at line 533 of file charset.c.

References ENCODE_CHAR, and MERROR.

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

  if (charset->method == Msubset)
    {
      MCharset *parent = charset->parents[0];
      unsigned code = ENCODE_CHAR (parent, c);

      if (code == MCHAR_INVALID_CODE)
      return code;
      code += charset->subset_offset;
      if (code >= charset->min_code && code <= charset->max_code)
      return code;
      return MCHAR_INVALID_CODE;
    }

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

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

        if (code != MCHAR_INVALID_CODE)
          return code;
      }
      return MCHAR_INVALID_CODE;
    }

  if (c < charset->min_char || c > charset->max_char)
    return MCHAR_INVALID_CODE;

  if (charset->method == Mmap)
    return (unsigned) mchartable_lookup (charset->encoder, c);

  if (charset->method == Munify)
    {
      if (c > charset->unified_max)
      {
        c -= charset->unified_max - 1;
        return INDEX_TO_CODE_POINT (charset, c);
      }
      return (unsigned) mchartable_lookup (charset->encoder, c);
    }

  /* Now charset->method should be Moffset */
  c -= charset->min_char;
  return INDEX_TO_CODE_POINT (charset, c);
}


Generated by  Doxygen 1.6.0   Back to index