Blame src/utf32_be.c

Packit Service bd74e6
/**********************************************************************
Packit Service bd74e6
  utf32_be.c -  Oniguruma (regular expression library)
Packit Service bd74e6
**********************************************************************/
Packit Service bd74e6
/*-
Packit Service bd74e6
 * Copyright (c) 2002-2018  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
Packit Service bd74e6
 * All rights reserved.
Packit Service bd74e6
 *
Packit Service bd74e6
 * Redistribution and use in source and binary forms, with or without
Packit Service bd74e6
 * modification, are permitted provided that the following conditions
Packit Service bd74e6
 * are met:
Packit Service bd74e6
 * 1. Redistributions of source code must retain the above copyright
Packit Service bd74e6
 *    notice, this list of conditions and the following disclaimer.
Packit Service bd74e6
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service bd74e6
 *    notice, this list of conditions and the following disclaimer in the
Packit Service bd74e6
 *    documentation and/or other materials provided with the distribution.
Packit Service bd74e6
 *
Packit Service bd74e6
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit Service bd74e6
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service bd74e6
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service bd74e6
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit Service bd74e6
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service bd74e6
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service bd74e6
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service bd74e6
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service bd74e6
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service bd74e6
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service bd74e6
 * SUCH DAMAGE.
Packit Service bd74e6
 */
Packit Service bd74e6
Packit Service bd74e6
#include "regenc.h"
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_mbc_enc_len(const UChar* p ARG_UNUSED)
Packit Service bd74e6
{
Packit Service bd74e6
  return 4;
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
is_valid_mbc_string(const UChar* s, const UChar* end)
Packit Service bd74e6
{
Packit Service bd74e6
  return onigenc_length_check_is_valid_mbc_string(ONIG_ENCODING_UTF32_BE, s, end);
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_is_mbc_newline(const UChar* p, const UChar* end)
Packit Service bd74e6
{
Packit Service bd74e6
  if (p + 3 < end) {
Packit Service bd74e6
    if (*(p+3) == 0x0a && *(p+2) == 0 && *(p+1) == 0 && *p == 0)
Packit Service bd74e6
      return 1;
Packit Service bd74e6
#ifdef USE_UNICODE_ALL_LINE_TERMINATORS
Packit Service bd74e6
    if ((
Packit Service bd74e6
#ifndef USE_CRNL_AS_LINE_TERMINATOR
Packit Service bd74e6
         *(p+3) == 0x0d ||
Packit Service bd74e6
#endif
Packit Service bd74e6
         *(p+3) == 0x85)
Packit Service bd74e6
        && *(p+2) == 0 && *(p+1) == 0 && *p == 0x00)
Packit Service bd74e6
      return 1;
Packit Service bd74e6
Packit Service bd74e6
    if (*(p+2) == 0x20 && (*(p+3) == 0x29 || *(p+3) == 0x28)
Packit Service bd74e6
        && *(p+1) == 0 && *p == 0)
Packit Service bd74e6
      return 1;
Packit Service bd74e6
#endif
Packit Service bd74e6
  }
Packit Service bd74e6
  return 0;
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static OnigCodePoint
Packit Service bd74e6
utf32be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
Packit Service bd74e6
{
Packit Service bd74e6
  return (OnigCodePoint )(((p[0] * 256 + p[1]) * 256 + p[2]) * 256 + p[3]);
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_code_to_mbclen(OnigCodePoint code ARG_UNUSED)
Packit Service bd74e6
{
Packit Service bd74e6
  return 4;
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_code_to_mbc(OnigCodePoint code, UChar *buf)
Packit Service bd74e6
{
Packit Service bd74e6
  UChar* p = buf;
Packit Service bd74e6
Packit Service bd74e6
  *p++ = (UChar )((code & 0xff000000) >>24);
Packit Service bd74e6
  *p++ = (UChar )((code & 0xff0000)   >>16);
Packit Service bd74e6
  *p++ = (UChar )((code & 0xff00)     >> 8);
Packit Service bd74e6
  *p++ = (UChar ) (code & 0xff);
Packit Service bd74e6
  return 4;
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_mbc_case_fold(OnigCaseFoldType flag,
Packit Service bd74e6
		      const UChar** pp, const UChar* end, UChar* fold)
Packit Service bd74e6
{
Packit Service bd74e6
  const UChar* p = *pp;
Packit Service bd74e6
Packit Service bd74e6
  if (ONIGENC_IS_ASCII_CODE(*(p+3)) && *(p+2) == 0 && *(p+1) == 0 && *p == 0) {
Packit Service bd74e6
    *fold++ = 0;
Packit Service bd74e6
    *fold++ = 0;
Packit Service bd74e6
Packit Service bd74e6
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
Packit Service bd74e6
    if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
Packit Service bd74e6
      if (*(p+3) == 0x49) {
Packit Service bd74e6
        *fold++ = 0x01;
Packit Service bd74e6
        *fold   = 0x31;
Packit Service bd74e6
        (*pp) += 4;
Packit Service bd74e6
        return 4;
Packit Service bd74e6
      }
Packit Service bd74e6
    }
Packit Service bd74e6
#endif
Packit Service bd74e6
Packit Service bd74e6
    *fold++ = 0;
Packit Service bd74e6
    *fold   = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*(p+3));
Packit Service bd74e6
    *pp += 4;
Packit Service bd74e6
    return 4;
Packit Service bd74e6
  }
Packit Service bd74e6
  else
Packit Service bd74e6
    return onigenc_unicode_mbc_case_fold(ONIG_ENCODING_UTF32_BE, flag, pp, end,
Packit Service bd74e6
					 fold);
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
#if 0
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end)
Packit Service bd74e6
{
Packit Service bd74e6
  const UChar* p = *pp;
Packit Service bd74e6
Packit Service bd74e6
  (*pp) += 4;
Packit Service bd74e6
Packit Service bd74e6
  if (*(p+2) == 0 && *(p+1) == 0 && *p == 0) {
Packit Service bd74e6
    int c, v;
Packit Service bd74e6
Packit Service bd74e6
    p += 3;
Packit Service bd74e6
    if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
Packit Service bd74e6
      return TRUE;
Packit Service bd74e6
    }
Packit Service bd74e6
Packit Service bd74e6
    c = *p;
Packit Service bd74e6
    v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c,
Packit Service bd74e6
                       (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER));
Packit Service bd74e6
    if ((v | BIT_CTYPE_LOWER) != 0) {
Packit Service bd74e6
      /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */
Packit Service bd74e6
      if (c >= 0xaa && c <= 0xba)
Packit Service bd74e6
        return FALSE;
Packit Service bd74e6
      else
Packit Service bd74e6
        return TRUE;
Packit Service bd74e6
    }
Packit Service bd74e6
    return (v != 0 ? TRUE : FALSE);
Packit Service bd74e6
  }
Packit Service bd74e6
Packit Service bd74e6
  return FALSE;
Packit Service bd74e6
}
Packit Service bd74e6
#endif
Packit Service bd74e6
Packit Service bd74e6
static UChar*
Packit Service bd74e6
utf32be_left_adjust_char_head(const UChar* start, const UChar* s)
Packit Service bd74e6
{
Packit Service bd74e6
  int rem;
Packit Service bd74e6
Packit Service bd74e6
  if (s <= start) return (UChar* )s;
Packit Service bd74e6
Packit Service bd74e6
  rem = (s - start) % 4;
Packit Service bd74e6
  return (UChar* )(s - rem);
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
static int
Packit Service bd74e6
utf32be_get_case_fold_codes_by_str(OnigCaseFoldType flag,
Packit Service bd74e6
    const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[])
Packit Service bd74e6
{
Packit Service bd74e6
  return onigenc_unicode_get_case_fold_codes_by_str(ONIG_ENCODING_UTF32_BE,
Packit Service bd74e6
						    flag, p, end, items);
Packit Service bd74e6
}
Packit Service bd74e6
Packit Service bd74e6
OnigEncodingType OnigEncodingUTF32_BE = {
Packit Service bd74e6
  utf32be_mbc_enc_len,
Packit Service bd74e6
  "UTF-32BE",   /* name */
Packit Service bd74e6
  4,            /* max enc length */
Packit Service bd74e6
  4,            /* min enc length */
Packit Service bd74e6
  utf32be_is_mbc_newline,
Packit Service bd74e6
  utf32be_mbc_to_code,
Packit Service bd74e6
  utf32be_code_to_mbclen,
Packit Service bd74e6
  utf32be_code_to_mbc,
Packit Service bd74e6
  utf32be_mbc_case_fold,
Packit Service bd74e6
  onigenc_unicode_apply_all_case_fold,
Packit Service bd74e6
  utf32be_get_case_fold_codes_by_str,
Packit Service bd74e6
  onigenc_unicode_property_name_to_ctype,
Packit Service bd74e6
  onigenc_unicode_is_code_ctype,
Packit Service bd74e6
  onigenc_utf16_32_get_ctype_code_range,
Packit Service bd74e6
  utf32be_left_adjust_char_head,
Packit Service bd74e6
  onigenc_always_false_is_allowed_reverse_match,
Packit Service bd74e6
  NULL, /* init */
Packit Service bd74e6
  NULL, /* is_initialized */
Packit Service bd74e6
  is_valid_mbc_string,
Packit Service bd74e6
  ENC_FLAG_UNICODE,
Packit Service bd74e6
  0, 0
Packit Service bd74e6
};