2008-08-23 21:58:18 -04:00
|
|
|
/**********************************************************************
|
|
|
|
emacs_mule.c - Oniguruma (regular expression library)
|
|
|
|
**********************************************************************/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-12-10 12:47:04 -05:00
|
|
|
#include "regenc.h"
|
2008-08-23 21:58:18 -04:00
|
|
|
|
|
|
|
|
2011-01-30 01:13:25 -05:00
|
|
|
#define emacsmule_islead(c) ((UChar )(c) < 0x9e)
|
2008-08-23 21:58:18 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
CHARACTER := ASCII_CHAR | MULTIBYTE_CHAR
|
|
|
|
MULTIBYTE_CHAR := PRIMARY_CHAR_1 | PRIMARY_CHAR_2
|
|
|
|
| SECONDARY_CHAR_1 | SECONDARY_CHAR_2
|
|
|
|
PRIMARY_CHAR_1 := LEADING_CODE_PRI C1
|
|
|
|
PRIMARY_CHAR_2 := LEADING_CODE_PRI C1 C2
|
|
|
|
SECONDARY_CHAR_1 := LEADING_CODE_SEC LEADING_CODE_EXT C1
|
|
|
|
SECONDARY_CHAR_2 := LEADING_CODE_SEC LEADING_CODE_EXT C1 C2
|
|
|
|
ASCII_CHAR := 0 | 1 | ... | 127
|
|
|
|
LEADING_CODE_PRI := 129 | 130 | ... | 153
|
|
|
|
LEADING_CODE_SEC := 154 | 155 | 156 | 157
|
|
|
|
C1, C2, LEADING_CODE_EXT := 160 | 161 | ... | 255
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const int EncLen_EmacsMule[] = {
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1, S2, S3, S4, S5, S6 } state_t;
|
|
|
|
#define A ACCEPT
|
|
|
|
#define F FAILURE
|
|
|
|
static const signed char trans[][0x100] = {
|
|
|
|
{ /* S0 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* 8 */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* 9 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 5, 6, F, F,
|
|
|
|
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
|
|
|
},
|
|
|
|
{ /* S1 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
|
|
|
/* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
|
2011-05-15 07:55:52 -04:00
|
|
|
/* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A
|
2008-08-23 21:58:18 -04:00
|
|
|
},
|
|
|
|
{ /* S2 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
2011-05-15 07:55:52 -04:00
|
|
|
/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
2008-08-23 21:58:18 -04:00
|
|
|
},
|
|
|
|
{ /* S3 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
|
|
|
},
|
|
|
|
{ /* S4 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
/* f */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F
|
|
|
|
},
|
|
|
|
{ /* S5 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* f */ 2, 2, 2, 2, 2, F, F, F, F, F, F, F, F, F, F, F
|
|
|
|
},
|
|
|
|
{ /* S6 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* a */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* b */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* c */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* d */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* e */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
|
|
|
|
/* f */ F, F, F, F, F, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, F
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
#undef A
|
|
|
|
#undef F
|
|
|
|
|
|
|
|
static int
|
|
|
|
mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
|
|
|
int firstbyte = *p++;
|
|
|
|
state_t s;
|
|
|
|
s = trans[0][firstbyte];
|
|
|
|
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
|
|
|
|
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
|
|
|
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-1);
|
|
|
|
s = trans[s][*p++];
|
|
|
|
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
|
|
|
|
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
|
|
|
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-2);
|
|
|
|
s = trans[s][*p++];
|
|
|
|
if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
|
|
|
|
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
|
|
|
if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-3);
|
|
|
|
s = trans[s][*p++];
|
|
|
|
return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4) :
|
|
|
|
ONIGENC_CONSTRUCT_MBCLEN_INVALID();
|
|
|
|
}
|
|
|
|
|
|
|
|
static OnigCodePoint
|
2008-09-18 08:53:25 -04:00
|
|
|
mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
|
2008-08-23 21:58:18 -04:00
|
|
|
{
|
2008-09-18 08:53:25 -04:00
|
|
|
int c, i, len;
|
|
|
|
OnigCodePoint n;
|
|
|
|
|
|
|
|
len = enclen(enc, p, end);
|
|
|
|
n = (OnigCodePoint )*p++;
|
|
|
|
if (len == 1) return n;
|
|
|
|
|
|
|
|
for (i = 1; i < len; i++) {
|
|
|
|
if (p >= end) break;
|
|
|
|
c = *p++;
|
|
|
|
n <<= 8; n += c;
|
|
|
|
}
|
|
|
|
return n;
|
2008-08-23 21:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
|
|
|
if (ONIGENC_IS_CODE_ASCII(code)) return 1;
|
|
|
|
else if (code > 0xffffffff) return 0;
|
|
|
|
else if ((code & 0xff000000) >= 0x80000000) return 4;
|
|
|
|
else if ((code & 0xff0000) >= 0x800000) return 3;
|
|
|
|
else if ((code & 0xff00) >= 0x8000) return 2;
|
|
|
|
else
|
|
|
|
return ONIGERR_INVALID_CODE_POINT_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
|
|
|
|
{
|
|
|
|
UChar *p = buf;
|
|
|
|
|
2008-09-11 06:34:59 -04:00
|
|
|
if ((code & 0xff000000) != 0) *p++ = (UChar )(((code >> 24) & 0xff));
|
2008-08-23 21:58:18 -04:00
|
|
|
if ((code & 0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
|
|
|
|
if ((code & 0xff00) != 0) *p++ = (UChar )(((code >> 8) & 0xff));
|
|
|
|
*p++ = (UChar )(code & 0xff);
|
|
|
|
|
|
|
|
if (enclen(enc, buf, p) != (p - buf))
|
|
|
|
return ONIGERR_INVALID_CODE_POINT_VALUE;
|
2011-01-05 15:16:32 -05:00
|
|
|
return (int)(p - buf);
|
2008-08-23 21:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mbc_case_fold(OnigCaseFoldType flag,
|
|
|
|
const UChar** pp, const UChar* end, UChar* lower,
|
|
|
|
OnigEncoding enc)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
const UChar* p = *pp;
|
|
|
|
|
|
|
|
if (ONIGENC_IS_MBC_ASCII(p)) {
|
|
|
|
*lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
|
|
|
|
(*pp)++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
|
2008-08-24 18:10:57 -04:00
|
|
|
len = mbc_enc_len(p, end, enc);
|
2008-08-23 21:58:18 -04:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
*lower++ = *p++;
|
|
|
|
}
|
|
|
|
(*pp) += len;
|
|
|
|
return len; /* return byte length of converted char to lower */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static UChar*
|
2008-09-13 15:23:52 -04:00
|
|
|
left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
|
2008-08-23 21:58:18 -04:00
|
|
|
{
|
|
|
|
const UChar *p;
|
|
|
|
|
|
|
|
if (s <= start) return (UChar* )s;
|
|
|
|
p = s;
|
|
|
|
|
|
|
|
while (!emacsmule_islead(*p) && p > start) p--;
|
2008-08-24 18:10:57 -04:00
|
|
|
return (UChar* )p;
|
2008-08-23 21:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
|
|
|
|
{
|
2008-08-24 18:10:57 -04:00
|
|
|
if (code < 128)
|
|
|
|
return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
|
|
|
|
else
|
|
|
|
return (code_to_mbclen(code, enc) > 1 ? TRUE : FALSE);
|
2008-08-23 21:58:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: Emacs-Mule
|
|
|
|
* Link: http://www.m17n.org/mule/pricai96/mule.en.html
|
|
|
|
*/
|
|
|
|
OnigEncodingDefine(emacs_mule, Emacs_Mule) = {
|
|
|
|
mbc_enc_len,
|
|
|
|
"Emacs-Mule", /* name */
|
|
|
|
4, /* max enc length */
|
|
|
|
1, /* min enc length */
|
|
|
|
onigenc_is_mbc_newline_0x0a,
|
|
|
|
mbc_to_code,
|
|
|
|
code_to_mbclen,
|
|
|
|
code_to_mbc,
|
|
|
|
mbc_case_fold,
|
|
|
|
onigenc_ascii_apply_all_case_fold,
|
|
|
|
onigenc_ascii_get_case_fold_codes_by_str,
|
2008-08-24 18:10:57 -04:00
|
|
|
onigenc_minimum_property_name_to_ctype,
|
2008-08-23 21:58:18 -04:00
|
|
|
is_code_ctype,
|
2008-08-24 18:10:57 -04:00
|
|
|
onigenc_not_support_get_ctype_code_range,
|
2008-08-23 21:58:18 -04:00
|
|
|
left_adjust_char_head,
|
2008-08-24 18:10:57 -04:00
|
|
|
onigenc_always_true_is_allowed_reverse_match,
|
2016-12-10 12:47:04 -05:00
|
|
|
onigenc_ascii_only_case_map,
|
2012-02-17 02:42:23 -05:00
|
|
|
0,
|
|
|
|
ONIGENC_FLAG_NONE,
|
2008-08-23 21:58:18 -04:00
|
|
|
};
|
|
|
|
|
2008-09-07 11:05:12 -04:00
|
|
|
ENC_REPLICATE("stateless-ISO-2022-JP", "Emacs-Mule")
|