2007-05-22 21:32:08 -04:00
|
|
|
/**********************************************************************
|
|
|
|
unicode.c - Oniguruma (regular expression library)
|
|
|
|
**********************************************************************/
|
|
|
|
/*-
|
2015-11-26 03:31:27 -05:00
|
|
|
* Copyright (c) 2002-2013 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
2007-05-22 21:32:08 -04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "regint.h"
|
|
|
|
|
|
|
|
#define ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(code,ctype) \
|
|
|
|
((EncUNICODE_ISO_8859_1_CtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
|
|
|
|
#if 0
|
|
|
|
#define ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(code,cbit) \
|
|
|
|
((EncUNICODE_ISO_8859_1_CtypeTable[code] & (cbit)) != 0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const unsigned short EncUNICODE_ISO_8859_1_CtypeTable[256] = {
|
|
|
|
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
2012-02-17 02:42:23 -05:00
|
|
|
0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,
|
2007-05-22 21:32:08 -04:00
|
|
|
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
|
|
|
0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
|
|
|
0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
|
|
|
0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
|
|
|
0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0,
|
|
|
|
0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
|
|
|
0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2,
|
|
|
|
0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
|
|
|
|
0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
|
|
|
|
0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0,
|
|
|
|
0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2,
|
|
|
|
0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
|
|
|
|
0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
|
|
|
|
0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008,
|
|
|
|
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0288, 0x0008, 0x0008,
|
|
|
|
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
|
|
|
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
|
|
|
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
|
|
|
0x0284, 0x01a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
|
|
|
|
0x00a0, 0x00a0, 0x30e2, 0x01a0, 0x00a0, 0x00a8, 0x00a0, 0x00a0,
|
|
|
|
0x00a0, 0x00a0, 0x10a0, 0x10a0, 0x00a0, 0x30e2, 0x00a0, 0x01a0,
|
|
|
|
0x00a0, 0x10a0, 0x30e2, 0x01a0, 0x10a0, 0x10a0, 0x10a0, 0x01a0,
|
|
|
|
0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
|
|
|
|
0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
|
|
|
|
0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x00a0,
|
|
|
|
0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x30e2,
|
|
|
|
0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
|
|
|
|
0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
|
|
|
|
0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x00a0,
|
|
|
|
0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int n;
|
|
|
|
OnigCodePoint code[3];
|
|
|
|
} CodePointList3;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OnigCodePoint from;
|
|
|
|
CodePointList3 to;
|
|
|
|
} CaseFold_11_Type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OnigCodePoint from;
|
|
|
|
CodePointList3 to;
|
|
|
|
} CaseUnfold_11_Type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int n;
|
|
|
|
OnigCodePoint code[2];
|
|
|
|
} CodePointList2;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OnigCodePoint from[2];
|
|
|
|
CodePointList2 to;
|
|
|
|
} CaseUnfold_12_Type;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OnigCodePoint from[3];
|
|
|
|
CodePointList2 to;
|
|
|
|
} CaseUnfold_13_Type;
|
|
|
|
|
2014-05-30 19:57:45 -04:00
|
|
|
static inline int
|
|
|
|
bits_of(const OnigCodePoint c, const int n)
|
|
|
|
{
|
|
|
|
return (c >> (2 - n) * 7) & 127;
|
|
|
|
}
|
|
|
|
|
2014-05-30 19:58:14 -04:00
|
|
|
static inline int
|
|
|
|
bits_at(const OnigCodePoint *c, const int n)
|
|
|
|
{
|
|
|
|
return bits_of(c[n / 3], n % 3);
|
|
|
|
}
|
|
|
|
|
2014-05-30 19:57:45 -04:00
|
|
|
static int
|
|
|
|
code1_equal(const OnigCodePoint x, const OnigCodePoint y)
|
|
|
|
{
|
|
|
|
if (x != y) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-30 19:58:14 -04:00
|
|
|
static int
|
|
|
|
code2_equal(const OnigCodePoint *x, const OnigCodePoint *y)
|
|
|
|
{
|
|
|
|
if (x[0] != y[0]) return 0;
|
|
|
|
if (x[1] != y[1]) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-30 19:58:24 -04:00
|
|
|
static int
|
|
|
|
code3_equal(const OnigCodePoint *x, const OnigCodePoint *y)
|
|
|
|
{
|
|
|
|
if (x[0] != y[0]) return 0;
|
|
|
|
if (x[1] != y[1]) return 0;
|
|
|
|
if (x[2] != y[2]) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-15 00:49:24 -04:00
|
|
|
/* macros related to ONIGENC_CASE flags */
|
|
|
|
/* defined here because not used in other files */
|
2016-12-10 12:47:04 -05:00
|
|
|
#define ONIGENC_CASE_SPECIALS (ONIGENC_CASE_TITLECASE | ONIGENC_CASE_IS_TITLECASE | ONIGENC_CASE_UP_SPECIAL | ONIGENC_CASE_DOWN_SPECIAL)
|
2016-03-15 00:49:24 -04:00
|
|
|
|
|
|
|
/* macros for length in CaseMappingSpecials array in enc/unicode/casefold.h */
|
|
|
|
#define SpecialsLengthOffset 25 /* needs to be higher than the 22 bits used for Unicode codepoints */
|
2016-12-10 12:47:04 -05:00
|
|
|
#define SpecialsLengthExtract(n) ((n) >> SpecialsLengthOffset)
|
|
|
|
#define SpecialsCodepointExtract(n) ((n) & ((1 << SpecialsLengthOffset) - 1))
|
|
|
|
#define SpecialsLengthEncode(n) ((n) << SpecialsLengthOffset)
|
2016-03-15 00:49:24 -04:00
|
|
|
|
2016-12-10 12:47:04 -05:00
|
|
|
#define OnigSpecialIndexMask (((1 << OnigSpecialIndexWidth) - 1) << OnigSpecialIndexShift)
|
|
|
|
#define OnigSpecialIndexEncode(n) ((n) << OnigSpecialIndexShift)
|
|
|
|
#define OnigSpecialIndexDecode(n) (((n) & OnigSpecialIndexMask) >> OnigSpecialIndexShift)
|
2016-03-15 00:49:24 -04:00
|
|
|
|
2016-03-14 05:39:54 -04:00
|
|
|
/* macros to shorten "enc/unicode/casefold.h", undefined immediately after including the file */
|
2016-02-07 23:00:31 -05:00
|
|
|
#define U ONIGENC_CASE_UPCASE
|
|
|
|
#define D ONIGENC_CASE_DOWNCASE
|
|
|
|
#define F ONIGENC_CASE_FOLD
|
2016-03-15 00:49:24 -04:00
|
|
|
#define ST ONIGENC_CASE_TITLECASE
|
|
|
|
#define SU ONIGENC_CASE_UP_SPECIAL
|
|
|
|
#define SL ONIGENC_CASE_DOWN_SPECIAL
|
2016-03-22 08:08:30 -04:00
|
|
|
#define IT ONIGENC_CASE_IS_TITLECASE
|
2016-03-16 23:09:00 -04:00
|
|
|
#define I(n) OnigSpecialIndexEncode(n)
|
2016-03-15 00:49:24 -04:00
|
|
|
#define L(n) SpecialsLengthEncode(n)
|
2016-02-07 08:10:20 -05:00
|
|
|
|
2016-07-17 07:59:26 -04:00
|
|
|
#include "casefold.h"
|
2007-05-22 21:32:08 -04:00
|
|
|
|
2016-02-07 23:00:31 -05:00
|
|
|
#undef U
|
|
|
|
#undef D
|
|
|
|
#undef F
|
2016-03-11 02:11:27 -05:00
|
|
|
#undef ST
|
|
|
|
#undef SU
|
|
|
|
#undef SL
|
2016-03-22 08:08:30 -04:00
|
|
|
#undef IT
|
2016-03-11 02:11:27 -05:00
|
|
|
#undef I
|
|
|
|
#undef L
|
2016-02-07 08:10:20 -05:00
|
|
|
|
2016-07-17 07:59:26 -04:00
|
|
|
#include "name2ctype.h"
|
2007-05-22 21:32:08 -04:00
|
|
|
|
2009-08-18 22:32:49 -04:00
|
|
|
#define CODE_RANGES_NUM numberof(CodeRanges)
|
|
|
|
|
2007-05-22 21:32:08 -04:00
|
|
|
extern int
|
2008-01-19 10:37:06 -05:00
|
|
|
onigenc_unicode_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
|
2007-05-22 21:32:08 -04:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
#ifdef USE_UNICODE_PROPERTIES
|
|
|
|
ctype <= ONIGENC_MAX_STD_CTYPE &&
|
|
|
|
#endif
|
|
|
|
code < 256) {
|
|
|
|
return ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(code, ctype);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctype >= CODE_RANGES_NUM) {
|
2008-01-03 10:55:04 -05:00
|
|
|
return ONIGERR_TYPE_BUG;
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return onig_is_in_code_range((UChar* )CodeRanges[ctype], code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onigenc_unicode_ctype_code_range(int ctype, const OnigCodePoint* ranges[])
|
|
|
|
{
|
|
|
|
if (ctype >= CODE_RANGES_NUM) {
|
2008-01-03 10:55:04 -05:00
|
|
|
return ONIGERR_TYPE_BUG;
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*ranges = CodeRanges[ctype];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2008-01-03 10:55:04 -05:00
|
|
|
onigenc_utf16_32_get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
|
2008-01-08 01:40:33 -05:00
|
|
|
const OnigCodePoint* ranges[],
|
2014-06-01 18:06:11 -04:00
|
|
|
OnigEncoding enc ARG_UNUSED)
|
2007-05-22 21:32:08 -04:00
|
|
|
{
|
|
|
|
*sb_out = 0x00;
|
|
|
|
return onigenc_unicode_ctype_code_range(ctype, ranges);
|
|
|
|
}
|
|
|
|
|
2012-02-17 02:42:23 -05:00
|
|
|
#define PROPERTY_NAME_MAX_SIZE (MAX_WORD_LENGTH + 1)
|
2007-05-22 21:32:08 -04:00
|
|
|
|
|
|
|
extern int
|
2015-08-27 15:49:45 -04:00
|
|
|
onigenc_unicode_property_name_to_ctype(OnigEncoding enc, const UChar* name, const UChar* end)
|
2007-05-22 21:32:08 -04:00
|
|
|
{
|
2008-06-17 09:06:34 -04:00
|
|
|
int len;
|
2009-08-21 04:01:09 -04:00
|
|
|
int ctype;
|
2007-05-22 21:32:08 -04:00
|
|
|
UChar buf[PROPERTY_NAME_MAX_SIZE];
|
2015-08-27 15:49:45 -04:00
|
|
|
const UChar *p;
|
2007-05-22 21:32:08 -04:00
|
|
|
OnigCodePoint code;
|
|
|
|
|
|
|
|
len = 0;
|
2009-09-10 18:54:01 -04:00
|
|
|
for (p = name; p < end; p += enclen(enc, p, end)) {
|
2007-05-22 21:32:08 -04:00
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
2009-09-10 18:54:01 -04:00
|
|
|
if (code == ' ' || code == '-' || code == '_')
|
|
|
|
continue;
|
2007-05-22 21:32:08 -04:00
|
|
|
if (code >= 0x80)
|
|
|
|
return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
|
|
|
|
2012-02-17 02:42:23 -05:00
|
|
|
buf[len++] = ONIGENC_ASCII_CODE_TO_LOWER_CASE(code);
|
2007-05-22 21:32:08 -04:00
|
|
|
if (len >= PROPERTY_NAME_MAX_SIZE)
|
|
|
|
return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[len] = 0;
|
|
|
|
|
2009-08-21 04:01:09 -04:00
|
|
|
if ((ctype = uniname2ctype(buf, len)) < 0) {
|
2007-05-22 21:32:08 -04:00
|
|
|
return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
|
|
|
}
|
|
|
|
|
2009-08-21 04:01:09 -04:00
|
|
|
return ctype;
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
|
2014-05-30 19:57:45 -04:00
|
|
|
#define onigenc_unicode_fold_lookup onigenc_unicode_CaseFold_11_lookup
|
2014-05-30 19:58:01 -04:00
|
|
|
#define onigenc_unicode_unfold1_lookup onigenc_unicode_CaseUnfold_11_lookup
|
2014-05-30 19:58:14 -04:00
|
|
|
#define onigenc_unicode_unfold2_lookup onigenc_unicode_CaseUnfold_12_lookup
|
2014-05-30 19:58:24 -04:00
|
|
|
#define onigenc_unicode_unfold3_lookup onigenc_unicode_CaseUnfold_13_lookup
|
2014-05-23 00:44:15 -04:00
|
|
|
|
2016-02-08 00:01:00 -05:00
|
|
|
enum {
|
|
|
|
I_WITH_DOT_ABOVE = 0x0130,
|
|
|
|
DOTLESS_i = 0x0131,
|
|
|
|
DOT_ABOVE = 0x0307
|
|
|
|
};
|
|
|
|
|
2007-05-22 21:32:08 -04:00
|
|
|
extern int
|
|
|
|
onigenc_unicode_mbc_case_fold(OnigEncoding enc,
|
2008-01-03 10:55:04 -05:00
|
|
|
OnigCaseFoldType flag ARG_UNUSED, const UChar** pp, const UChar* end,
|
|
|
|
UChar* fold)
|
2007-05-22 21:32:08 -04:00
|
|
|
{
|
2014-05-23 00:37:02 -04:00
|
|
|
const CodePointList3 *to;
|
2007-05-22 21:32:08 -04:00
|
|
|
OnigCodePoint code;
|
2008-09-18 08:53:25 -04:00
|
|
|
int i, len, rlen;
|
2007-05-22 21:32:08 -04:00
|
|
|
const UChar *p = *pp;
|
|
|
|
|
2008-09-18 08:53:25 -04:00
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
|
|
|
len = enclen(enc, p, end);
|
2007-05-22 21:32:08 -04:00
|
|
|
*pp += len;
|
|
|
|
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
2016-02-08 00:01:00 -05:00
|
|
|
if (code == 'I') {
|
|
|
|
return ONIGENC_CODE_TO_MBC(enc, DOTLESS_i, fold);
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
2016-02-08 00:01:00 -05:00
|
|
|
else if (code == I_WITH_DOT_ABOVE) {
|
|
|
|
return ONIGENC_CODE_TO_MBC(enc, 'i', fold);
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-23 00:44:15 -04:00
|
|
|
if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
|
2016-01-27 03:55:40 -05:00
|
|
|
if (OnigCodePointCount(to->n) == 1) {
|
2011-05-15 07:55:52 -04:00
|
|
|
return ONIGENC_CODE_TO_MBC(enc, to->code[0], fold);
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* NO NEEDS TO CHECK */
|
2009-08-25 20:48:49 -04:00
|
|
|
else if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0)
|
2007-05-22 21:32:08 -04:00
|
|
|
#else
|
2009-08-25 20:48:49 -04:00
|
|
|
else
|
2007-05-22 21:32:08 -04:00
|
|
|
#endif
|
2009-08-25 20:48:49 -04:00
|
|
|
{
|
2007-05-22 21:32:08 -04:00
|
|
|
rlen = 0;
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
len = ONIGENC_CODE_TO_MBC(enc, to->code[i], fold);
|
|
|
|
fold += len;
|
|
|
|
rlen += len;
|
|
|
|
}
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
*fold++ = *p++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onigenc_unicode_apply_all_case_fold(OnigCaseFoldType flag,
|
2007-10-10 11:05:32 -04:00
|
|
|
OnigApplyAllCaseFoldFunc f, void* arg,
|
2008-01-19 10:37:06 -05:00
|
|
|
OnigEncoding enc ARG_UNUSED)
|
2007-05-22 21:32:08 -04:00
|
|
|
{
|
|
|
|
const CaseUnfold_11_Type* p11;
|
|
|
|
OnigCodePoint code;
|
|
|
|
int i, j, k, r;
|
|
|
|
|
2009-08-18 22:32:49 -04:00
|
|
|
for (i = 0; i < numberof(CaseUnfold_11); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
p11 = &CaseUnfold_11[i];
|
2016-01-27 03:55:40 -05:00
|
|
|
for (j = 0; j < OnigCodePointCount(p11->to.n); j++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
code = p11->from;
|
|
|
|
r = (*f)(p11->to.code[j], &code, 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
code = p11->to.code[j];
|
|
|
|
r = (*f)(p11->from, &code, 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
for (k = 0; k < j; k++) {
|
|
|
|
r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]), 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]), 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
2016-02-08 00:01:00 -05:00
|
|
|
code = DOTLESS_i;
|
|
|
|
r = (*f)('I', &code, 1, arg);
|
2007-05-22 21:32:08 -04:00
|
|
|
if (r != 0) return r;
|
2016-02-08 00:01:00 -05:00
|
|
|
code = 'I';
|
|
|
|
r = (*f)(DOTLESS_i, &code, 1, arg);
|
2007-05-22 21:32:08 -04:00
|
|
|
if (r != 0) return r;
|
|
|
|
|
2016-02-08 00:01:00 -05:00
|
|
|
code = I_WITH_DOT_ABOVE;
|
|
|
|
r = (*f)('i', &code, 1, arg);
|
2007-05-22 21:32:08 -04:00
|
|
|
if (r != 0) return r;
|
2016-02-08 00:01:00 -05:00
|
|
|
code = 'i';
|
|
|
|
r = (*f)(I_WITH_DOT_ABOVE, &code, 1, arg);
|
2007-05-22 21:32:08 -04:00
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
2009-08-18 22:32:49 -04:00
|
|
|
for (i = 0; i < numberof(CaseUnfold_11_Locale); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
p11 = &CaseUnfold_11_Locale[i];
|
2016-01-27 03:55:40 -05:00
|
|
|
for (j = 0; j < OnigCodePointCount(p11->to.n); j++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
code = p11->from;
|
|
|
|
r = (*f)(p11->to.code[j], &code, 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
code = p11->to.code[j];
|
|
|
|
r = (*f)(p11->from, &code, 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
for (k = 0; k < j; k++) {
|
|
|
|
r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]),
|
|
|
|
1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]),
|
|
|
|
1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
2009-08-18 22:32:49 -04:00
|
|
|
for (i = 0; i < numberof(CaseUnfold_12); i++) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (j = 0; j < OnigCodePointCount(CaseUnfold_12[i].to.n); j++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
r = (*f)(CaseUnfold_12[i].to.code[j],
|
|
|
|
(OnigCodePoint* )CaseUnfold_12[i].from, 2, arg);
|
2011-05-15 07:55:52 -04:00
|
|
|
if (r != 0) return r;
|
2007-05-22 21:32:08 -04:00
|
|
|
|
2016-01-27 03:55:40 -05:00
|
|
|
for (k = 0; k < OnigCodePointCount(CaseUnfold_12[i].to.n); k++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (k == j) continue;
|
|
|
|
|
|
|
|
r = (*f)(CaseUnfold_12[i].to.code[j],
|
|
|
|
(OnigCodePoint* )(&CaseUnfold_12[i].to.code[k]), 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) == 0) {
|
|
|
|
#endif
|
2009-08-18 22:32:49 -04:00
|
|
|
for (i = 0; i < numberof(CaseUnfold_12_Locale); i++) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (j = 0; j < OnigCodePointCount(CaseUnfold_12_Locale[i].to.n); j++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
|
|
|
|
(OnigCodePoint* )CaseUnfold_12_Locale[i].from, 2, arg);
|
2011-05-15 07:55:52 -04:00
|
|
|
if (r != 0) return r;
|
2007-05-22 21:32:08 -04:00
|
|
|
|
2016-01-27 03:55:40 -05:00
|
|
|
for (k = 0; k < OnigCodePointCount(CaseUnfold_12_Locale[i].to.n); k++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (k == j) continue;
|
|
|
|
|
|
|
|
r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
|
|
|
|
(OnigCodePoint* )(&CaseUnfold_12_Locale[i].to.code[k]),
|
|
|
|
1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-18 22:32:49 -04:00
|
|
|
for (i = 0; i < numberof(CaseUnfold_13); i++) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (j = 0; j < OnigCodePointCount(CaseUnfold_13[i].to.n); j++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
r = (*f)(CaseUnfold_13[i].to.code[j],
|
|
|
|
(OnigCodePoint* )CaseUnfold_13[i].from, 3, arg);
|
2011-05-15 07:55:52 -04:00
|
|
|
if (r != 0) return r;
|
2007-05-22 21:32:08 -04:00
|
|
|
|
2016-01-27 03:55:40 -05:00
|
|
|
for (k = 0; k < OnigCodePointCount(CaseUnfold_13[i].to.n); k++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (k == j) continue;
|
|
|
|
|
|
|
|
r = (*f)(CaseUnfold_13[i].to.code[j],
|
|
|
|
(OnigCodePoint* )(&CaseUnfold_13[i].to.code[k]), 1, arg);
|
|
|
|
if (r != 0) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:35:54 -05:00
|
|
|
#define CodePointListValidP(x) (OnigCodePointCount((x)->n) <= numberof((x)->code))
|
2016-03-11 20:15:31 -05:00
|
|
|
|
2007-05-22 21:32:08 -04:00
|
|
|
extern int
|
|
|
|
onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
|
|
|
OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end,
|
|
|
|
OnigCaseFoldCodeItem items[])
|
|
|
|
{
|
2008-09-18 08:53:25 -04:00
|
|
|
int n, i, j, k, len;
|
2007-05-22 21:32:08 -04:00
|
|
|
OnigCodePoint code, codes[3];
|
2014-05-23 00:37:02 -04:00
|
|
|
const CodePointList3 *to, *z3;
|
|
|
|
const CodePointList2 *z2;
|
2007-05-22 21:32:08 -04:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
|
2008-09-18 08:53:25 -04:00
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
|
|
|
len = enclen(enc, p, end);
|
2007-05-22 21:32:08 -04:00
|
|
|
|
|
|
|
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
|
|
|
if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
2016-02-08 00:01:00 -05:00
|
|
|
switch (code) {
|
|
|
|
case 'I':
|
2007-05-22 21:32:08 -04:00
|
|
|
items[0].byte_len = len;
|
|
|
|
items[0].code_len = 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
items[0].code[0] = DOTLESS_i;
|
2007-05-22 21:32:08 -04:00
|
|
|
return 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
case I_WITH_DOT_ABOVE:
|
2007-05-22 21:32:08 -04:00
|
|
|
items[0].byte_len = len;
|
|
|
|
items[0].code_len = 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
items[0].code[0] = 'i';
|
2007-05-22 21:32:08 -04:00
|
|
|
return 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
case DOTLESS_i:
|
2007-05-22 21:32:08 -04:00
|
|
|
items[0].byte_len = len;
|
|
|
|
items[0].code_len = 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
items[0].code[0] = 'I';
|
2007-05-22 21:32:08 -04:00
|
|
|
return 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
case 'i':
|
2007-05-22 21:32:08 -04:00
|
|
|
items[0].byte_len = len;
|
|
|
|
items[0].code_len = 1;
|
2016-02-08 00:01:00 -05:00
|
|
|
items[0].code[0] = I_WITH_DOT_ABOVE;
|
2007-05-22 21:32:08 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-23 00:44:15 -04:00
|
|
|
if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
|
2020-05-03 23:10:04 -04:00
|
|
|
if (OnigCodePointCount(to->n) == 0) {
|
|
|
|
/* any codepoint should not be empty */
|
|
|
|
UNREACHABLE_RETURN(0);
|
|
|
|
}
|
2016-01-27 03:55:40 -05:00
|
|
|
if (OnigCodePointCount(to->n) == 1) {
|
2007-05-22 21:32:08 -04:00
|
|
|
OnigCodePoint orig_code = code;
|
|
|
|
|
|
|
|
items[0].byte_len = len;
|
|
|
|
items[0].code_len = 1;
|
|
|
|
items[0].code[0] = to->code[0];
|
|
|
|
n++;
|
|
|
|
|
|
|
|
code = to->code[0];
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0 &&
|
|
|
|
CodePointListValidP(to)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (to->code[i] != orig_code) {
|
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = to->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
|
|
|
OnigCodePoint cs[3][4];
|
|
|
|
int fn, ncs[3];
|
|
|
|
|
2016-01-27 03:55:40 -05:00
|
|
|
for (fn = 0; fn < OnigCodePointCount(to->n); fn++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
cs[fn][0] = to->code[fn];
|
2014-05-23 00:44:15 -04:00
|
|
|
if ((z3 = onigenc_unicode_unfold1_lookup(cs[fn][0])) != 0) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(z3->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
cs[fn][i+1] = z3->code[i];
|
|
|
|
}
|
2016-01-27 03:55:40 -05:00
|
|
|
ncs[fn] = OnigCodePointCount(z3->n) + 1;
|
2007-05-22 21:32:08 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ncs[fn] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fn == 2) {
|
|
|
|
for (i = 0; i < ncs[0]; i++) {
|
|
|
|
for (j = 0; j < ncs[1]; j++) {
|
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 2;
|
|
|
|
items[n].code[0] = cs[0][i];
|
|
|
|
items[n].code[1] = cs[1][j];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((z2 = onigenc_unicode_unfold2_lookup(to->code)) != 0 &&
|
|
|
|
CodePointListValidP(z2)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (z2->code[i] == code) continue;
|
|
|
|
|
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = z2->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; i < ncs[0]; i++) {
|
|
|
|
for (j = 0; j < ncs[1]; j++) {
|
|
|
|
for (k = 0; k < ncs[2]; k++) {
|
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 3;
|
|
|
|
items[n].code[0] = cs[0][i];
|
|
|
|
items[n].code[1] = cs[1][j];
|
|
|
|
items[n].code[2] = cs[2][k];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((z2 = onigenc_unicode_unfold3_lookup(to->code)) != 0 &&
|
|
|
|
CodePointListValidP(z2)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
if (z2->code[i] == code) continue;
|
|
|
|
|
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = z2->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* multi char folded code is not head of another folded multi char */
|
|
|
|
flag = 0; /* DISABLE_CASE_FOLD_MULTI_CHAR(flag); */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0 &&
|
|
|
|
CodePointListValidP(to)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = to->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
|
|
|
p += len;
|
|
|
|
if (p < end) {
|
|
|
|
int clen;
|
|
|
|
|
|
|
|
codes[0] = code;
|
2008-09-18 08:53:25 -04:00
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
2014-05-23 00:44:15 -04:00
|
|
|
if ((to = onigenc_unicode_fold_lookup(code)) != 0
|
2016-01-27 03:55:40 -05:00
|
|
|
&& OnigCodePointCount(to->n) == 1) {
|
2007-05-22 21:32:08 -04:00
|
|
|
codes[1] = to->code[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
codes[1] = code;
|
|
|
|
|
2008-09-18 08:53:25 -04:00
|
|
|
clen = enclen(enc, p, end);
|
2007-05-22 21:32:08 -04:00
|
|
|
len += clen;
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((z2 = onigenc_unicode_unfold2_lookup(codes)) != 0 &&
|
|
|
|
CodePointListValidP(z2)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = z2->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p += clen;
|
|
|
|
if (p < end) {
|
2008-09-18 08:53:25 -04:00
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
2014-05-23 00:44:15 -04:00
|
|
|
if ((to = onigenc_unicode_fold_lookup(code)) != 0
|
2016-01-27 03:55:40 -05:00
|
|
|
&& OnigCodePointCount(to->n) == 1) {
|
2007-05-22 21:32:08 -04:00
|
|
|
codes[2] = to->code[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
codes[2] = code;
|
|
|
|
|
2008-09-18 08:53:25 -04:00
|
|
|
clen = enclen(enc, p, end);
|
2007-05-22 21:32:08 -04:00
|
|
|
len += clen;
|
2016-03-11 20:15:31 -05:00
|
|
|
if ((z2 = onigenc_unicode_unfold3_lookup(codes)) != 0 &&
|
|
|
|
CodePointListValidP(z2)) {
|
2016-01-27 03:55:40 -05:00
|
|
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
2007-05-22 21:32:08 -04:00
|
|
|
items[n].byte_len = len;
|
|
|
|
items[n].code_len = 1;
|
|
|
|
items[n].code[0] = z2->code[i];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
2016-01-15 20:24:03 -05:00
|
|
|
|
|
|
|
/* length in bytes for three characters in UTF-32; e.g. needed for ffi (U+FB03) */
|
|
|
|
#define CASE_MAPPING_SLACK 12
|
2016-01-17 03:42:16 -05:00
|
|
|
#define MODIFIED (flags |= ONIGENC_CASE_MODIFIED)
|
2016-01-15 20:24:03 -05:00
|
|
|
extern int
|
2016-01-16 03:24:58 -05:00
|
|
|
onigenc_unicode_case_map(OnigCaseFoldType* flagP,
|
2016-01-15 20:24:03 -05:00
|
|
|
const OnigUChar** pp, const OnigUChar* end,
|
|
|
|
OnigUChar* to, OnigUChar* to_end,
|
|
|
|
const struct OnigEncodingTypeST* enc)
|
|
|
|
{
|
2016-12-10 12:47:04 -05:00
|
|
|
OnigCodePoint code;
|
|
|
|
OnigUChar *to_start = to;
|
|
|
|
OnigCaseFoldType flags = *flagP;
|
|
|
|
int codepoint_length;
|
|
|
|
|
|
|
|
to_end -= CASE_MAPPING_SLACK;
|
|
|
|
/* copy flags ONIGENC_CASE_UPCASE and ONIGENC_CASE_DOWNCASE over to
|
|
|
|
* ONIGENC_CASE_UP_SPECIAL and ONIGENC_CASE_DOWN_SPECIAL */
|
|
|
|
flags |= (flags & (ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE)) << ONIGENC_CASE_SPECIAL_OFFSET;
|
|
|
|
|
|
|
|
while (*pp < end && to <= to_end) {
|
|
|
|
codepoint_length = ONIGENC_PRECISE_MBC_ENC_LEN(enc, *pp, end);
|
|
|
|
if (codepoint_length < 0)
|
|
|
|
return codepoint_length; /* encoding invalid */
|
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, *pp, end);
|
|
|
|
*pp += codepoint_length;
|
|
|
|
|
|
|
|
if (code <= 'z') { /* ASCII comes first */
|
|
|
|
if (code >= 'a' && code <= 'z') {
|
|
|
|
if (flags & ONIGENC_CASE_UPCASE) {
|
|
|
|
MODIFIED;
|
|
|
|
if (flags & ONIGENC_CASE_FOLD_TURKISH_AZERI && code == 'i')
|
|
|
|
code = I_WITH_DOT_ABOVE;
|
enc/unicode.c: 'a' is bigger than 'A'
In ASCII, 'a' is bigger than 'A'. Which means 'A' - 'a' is a negative
number (-32, to be precise). In C, the type of 'a' and 'A' are signed
int (cf: ISO/IEC 9899:1990 section 6.1.3.4). So 'A' - 'a' is also a
signed int. It is `(signed int)-32`.
The problem is, OnigCodePoint is unsigned int. Adding a negative
number to a variable of OnigCodepoint (`code` here) introduces an
unintentional cast of `(unsigned)(signed)-32`, which is
4,294,967,264. Adding this value to code then overflows, and the
result eventually becomes normal codepoint.
The series of operations are not a serious problem but because
`code >= 'a'` holds, we can `(code - 'a') + 'A'` to reroute this.
See also: https://github.com/k-takata/Onigmo/pull/107
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-15 21:34:00 -05:00
|
|
|
else {
|
|
|
|
code -= 'a';
|
|
|
|
code += 'A';
|
|
|
|
}
|
2016-01-16 03:24:58 -05:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
}
|
|
|
|
else if (code >= 'A' && code <= 'Z') {
|
|
|
|
if (flags & (ONIGENC_CASE_DOWNCASE | ONIGENC_CASE_FOLD)) {
|
|
|
|
MODIFIED;
|
|
|
|
if (flags & ONIGENC_CASE_FOLD_TURKISH_AZERI && code == 'I')
|
|
|
|
code = DOTLESS_i;
|
|
|
|
else
|
|
|
|
code += 'a' - 'A';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(flags & ONIGENC_CASE_ASCII_ONLY) && code >= 0x00B5) { /* deal with non-ASCII; micron sign (U+00B5) is lowest affected */
|
|
|
|
const CodePointList3 *folded;
|
|
|
|
|
|
|
|
if (code == I_WITH_DOT_ABOVE) {
|
|
|
|
if (flags & (ONIGENC_CASE_DOWNCASE | ONIGENC_CASE_FOLD)) {
|
|
|
|
MODIFIED;
|
|
|
|
code = 'i';
|
|
|
|
if (!(flags & ONIGENC_CASE_FOLD_TURKISH_AZERI)) { /* make dot above explicit */
|
|
|
|
to += ONIGENC_CODE_TO_MBC(enc, code, to);
|
|
|
|
code = DOT_ABOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (code == DOTLESS_i) { /* handle this manually, because it isn't involved in folding */
|
|
|
|
if (flags & ONIGENC_CASE_UPCASE) {
|
|
|
|
MODIFIED;
|
|
|
|
code = 'I';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((folded = onigenc_unicode_fold_lookup(code)) != 0) { /* data about character found in CaseFold_11_Table */
|
implement special behavior for Georgian for String#capitalize
The modern Georgian script is special in that it has an 'uppercase'
variant called MTAVRULI which can be used for emphasis of whole words,
for screamy headlines, and so on. However, in contrast to all other
bicameral scripts, there is no usage of capitalizing the first letter
in a word or a sentence. Words with mixed capitalization are not used
at all.
We therefore implement special behavior for String#capitalize. Formally,
we define String#capitalize as first applying String#downcase for the
whole string, then using titlecase on the first letter. Because Georgian
defines titlecase as the identity function both for MTAVRULI ('uppercase')
and Mkhedruli (lowercase), this results in String#capitalize being
equivalent to String#downcase for Georgian. This avoids undesirable
mixed case.
* enc/unicode.c: Actual implementation
* string.c: Add mention of this special case for documentation
* test/ruby/enc/test_case_mapping.rb: Add two tests, a general one
that uses String#capitalize on some (including nonsensical)
combinations of MTAVRULI and Mkhedruli, and a canary test to
detect the potential assignment of characters to the currently
open slots (holes) at U+1CBB and U+1CBC.
* test/ruby/enc/test_case_comprehensive.rb: Tweak generation of
expectation data.
Together with r65933, this closes issue #14839.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-09 18:14:29 -05:00
|
|
|
if ((flags & ONIGENC_CASE_TITLECASE) && code>=0x1C90 && code<=0x1CBF) { /* Georgian MTAVRULI */
|
|
|
|
MODIFIED;
|
|
|
|
code += 0x10D0 - 0x1C90;
|
|
|
|
}
|
|
|
|
else if ((flags & ONIGENC_CASE_TITLECASE) /* Titlecase needed, */
|
2016-12-10 12:47:04 -05:00
|
|
|
&& (OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_IS_TITLECASE)) { /* but already Titlecase */
|
|
|
|
/* already Titlecase, no changes needed */
|
|
|
|
}
|
|
|
|
else if (flags & OnigCaseFoldFlags(folded->n)) { /* needs and data availability match */
|
|
|
|
const OnigCodePoint *next;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
MODIFIED;
|
|
|
|
if (flags & OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_SPECIALS) { /* special */
|
|
|
|
const OnigCodePoint *SpecialsStart = CaseMappingSpecials + OnigSpecialIndexDecode(folded->n);
|
|
|
|
|
|
|
|
if (OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_IS_TITLECASE) { /* swapCASE available */
|
|
|
|
if ((flags & (ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE))
|
|
|
|
== (ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE)) /* swapCASE needed */
|
|
|
|
goto SpecialsCopy;
|
|
|
|
else /* swapCASE not needed */
|
|
|
|
SpecialsStart += SpecialsLengthExtract(*SpecialsStart);
|
2016-05-25 06:07:19 -04:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
if (OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_TITLECASE) { /* Titlecase available */
|
|
|
|
if (flags & ONIGENC_CASE_TITLECASE) /* Titlecase needed, but not yet Titlecase */
|
|
|
|
goto SpecialsCopy;
|
|
|
|
else /* Titlecase not needed */
|
|
|
|
SpecialsStart += SpecialsLengthExtract(*SpecialsStart);
|
2016-02-06 00:37:29 -05:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
if (OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_DOWN_SPECIAL) {
|
|
|
|
if (!(flags & ONIGENC_CASE_DOWN_SPECIAL))
|
|
|
|
SpecialsStart += SpecialsLengthExtract(*SpecialsStart);
|
2016-02-18 22:45:32 -05:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
/* here, we know we use ONIGENC_CASE_UP_SPECIAL, and the position is right */
|
|
|
|
SpecialsCopy:
|
|
|
|
count = SpecialsLengthExtract(*SpecialsStart);
|
|
|
|
next = SpecialsStart;
|
|
|
|
code = SpecialsCodepointExtract(*next++);
|
|
|
|
}
|
|
|
|
else { /* no specials */
|
|
|
|
count = OnigCodePointCount(folded->n);
|
|
|
|
next = folded->code;
|
|
|
|
code = *next++;
|
|
|
|
}
|
|
|
|
if (count == 1)
|
|
|
|
;
|
|
|
|
else if (count == 2) {
|
|
|
|
to += ONIGENC_CODE_TO_MBC(enc, code, to);
|
|
|
|
code = *next;
|
|
|
|
}
|
|
|
|
else { /* count == 3 */
|
|
|
|
to += ONIGENC_CODE_TO_MBC(enc, code, to);
|
|
|
|
to += ONIGENC_CODE_TO_MBC(enc, *next++, to);
|
|
|
|
code = *next;
|
|
|
|
}
|
2016-01-15 20:24:03 -05:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
}
|
2018-11-25 05:12:45 -05:00
|
|
|
else if ((folded = onigenc_unicode_unfold1_lookup(code)) != 0) { /* data about character found in CaseUnfold_11_Table */
|
|
|
|
if ((flags & ONIGENC_CASE_TITLECASE) /* Titlecase needed, */
|
|
|
|
&& (OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_IS_TITLECASE)) { /* but already Titlecase */
|
|
|
|
/* already Titlecase, no changes needed */
|
|
|
|
}
|
|
|
|
else if (flags & OnigCaseFoldFlags(folded->n)) { /* needs and data availability match */
|
|
|
|
MODIFIED;
|
|
|
|
code = folded->code[(flags & OnigCaseFoldFlags(folded->n) & ONIGENC_CASE_TITLECASE) ? 1 : 0];
|
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
}
|
2016-01-15 20:24:03 -05:00
|
|
|
}
|
2016-12-10 12:47:04 -05:00
|
|
|
to += ONIGENC_CODE_TO_MBC(enc, code, to);
|
|
|
|
/* switch from titlecase to lowercase for capitalize */
|
|
|
|
if (flags & ONIGENC_CASE_TITLECASE)
|
|
|
|
flags ^= (ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE | ONIGENC_CASE_TITLECASE |
|
|
|
|
ONIGENC_CASE_UP_SPECIAL | ONIGENC_CASE_DOWN_SPECIAL);
|
|
|
|
}
|
|
|
|
*flagP = flags;
|
|
|
|
return (int )(to - to_start);
|
2016-01-15 20:24:03 -05:00
|
|
|
}
|
2016-05-16 06:46:32 -04:00
|
|
|
|
2018-10-15 09:48:20 -04:00
|
|
|
#if 0
|
2016-07-17 07:59:26 -04:00
|
|
|
const char onigenc_unicode_version_string[] =
|
|
|
|
#ifdef ONIG_UNICODE_VERSION_STRING
|
|
|
|
ONIG_UNICODE_VERSION_STRING
|
|
|
|
#endif
|
|
|
|
"";
|
|
|
|
|
|
|
|
const int onigenc_unicode_version_number[3] = {
|
|
|
|
#ifdef ONIG_UNICODE_VERSION_MAJOR
|
|
|
|
ONIG_UNICODE_VERSION_MAJOR,
|
|
|
|
ONIG_UNICODE_VERSION_MINOR,
|
|
|
|
ONIG_UNICODE_VERSION_TEENY,
|
|
|
|
#else
|
|
|
|
0
|
|
|
|
#endif
|
|
|
|
};
|
2018-10-15 09:48:20 -04:00
|
|
|
#endif
|