Ruby  1.9.3p547(2014-05-14revision45962)
utf_32le.c
Go to the documentation of this file.
1 /**********************************************************************
2  utf_32le.c - Oniguruma (regular expression library)
3 **********************************************************************/
4 /*-
5  * Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #include "regenc.h"
31 
32 static int
33 utf32le_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
34  OnigEncoding enc ARG_UNUSED)
35 {
36  return 4;
37 }
38 
39 static int
40 utf32le_is_mbc_newline(const UChar* p, const UChar* end,
42 {
43  if (p + 3 < end) {
44  if (*p == 0x0a && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0)
45  return 1;
46 #ifdef USE_UNICODE_ALL_LINE_TERMINATORS
47  if ((
48 #ifndef USE_CRNL_AS_LINE_TERMINATOR
49  *p == 0x0d ||
50 #endif
51  *p == 0x85)
52  && *(p+1) == 0x00 && (p+2) == 0x00 && *(p+3) == 0x00)
53  return 1;
54  if (*(p+1) == 0x20 && (*p == 0x29 || *p == 0x28)
55  && *(p+2) == 0x00 && *(p+3) == 0x00)
56  return 1;
57 #endif
58  }
59  return 0;
60 }
61 
62 static OnigCodePoint
64  OnigEncoding enc ARG_UNUSED)
65 {
66  return (OnigCodePoint )(((p[3] * 256 + p[2]) * 256 + p[1]) * 256 + p[0]);
67 }
68 
69 static int
71  OnigEncoding enc ARG_UNUSED)
72 {
73  return 4;
74 }
75 
76 static int
79 {
80  UChar* p = buf;
81 
82  *p++ = (UChar ) (code & 0xff);
83  *p++ = (UChar )((code & 0xff00) >> 8);
84  *p++ = (UChar )((code & 0xff0000) >>16);
85  *p++ = (UChar )((code & 0xff000000) >>24);
86  return 4;
87 }
88 
89 static int
91  const UChar** pp, const UChar* end, UChar* fold,
92  OnigEncoding enc)
93 {
94  const UChar* p = *pp;
95 
96  if (ONIGENC_IS_ASCII_CODE(*p) && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) {
97 #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
98  if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
99  if (*p == 0x49) {
100  *fold++ = 0x31;
101  *fold++ = 0x01;
102  }
103  }
104  else {
105 #endif
106  *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
107  *fold++ = 0;
108 #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
109  }
110 #endif
111 
112  *fold++ = 0;
113  *fold = 0;
114  *pp += 4;
115  return 4;
116  }
117  else
118  return onigenc_unicode_mbc_case_fold(enc, flag, pp,
119  end, fold);
120 }
121 
122 #if 0
123 static int
124 utf32le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end)
125 {
126  const UChar* p = *pp;
127 
128  (*pp) += 4;
129 
130  if (*(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) {
131  int c, v;
132 
133  if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
134  return TRUE;
135  }
136 
137  c = *p;
138  v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c,
140  if ((v | BIT_CTYPE_LOWER) != 0) {
141  /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */
142  if (c >= 0xaa && c <= 0xba)
143  return FALSE;
144  else
145  return TRUE;
146  }
147  return (v != 0 ? TRUE : FALSE);
148  }
149 
150  return FALSE;
151 }
152 #endif
153 
154 static UChar*
155 utf32le_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
157 {
158  ptrdiff_t rem;
159 
160  if (s <= start) return (UChar* )s;
161 
162  rem = (s - start) % 4;
163  return (UChar* )(s - rem);
164 }
165 
166 static int
168  const OnigUChar* p, const OnigUChar* end,
169  OnigCaseFoldCodeItem items[],
170  OnigEncoding enc)
171 {
173  flag, p, end, items);
174 }
175 
176 OnigEncodingDefine(utf_32le, UTF_32LE) = {
178  "UTF-32LE", /* name */
179  4, /* max byte length */
180  4, /* min byte length */
193 };
194 ENC_ALIAS("UCS-4LE", "UTF-32LE")
int onigenc_unicode_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
Definition: unicode.c:2042
#define ARG_UNUSED
Definition: regenc.h:68
unsigned int OnigCodePoint
Definition: oniguruma.h:111
#define FALSE
Definition: nkf.h:185
OnigEncodingDefine(utf_32le, UTF_32LE)
static int utf32le_mbc_case_fold(OnigCaseFoldType flag, const UChar **pp, const UChar *end, UChar *fold, OnigEncoding enc)
Definition: utf_32le.c:90
unsigned int OnigCaseFoldType
Definition: oniguruma.h:117
static int utf32le_is_mbc_newline(const UChar *p, const UChar *end, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:40
static int utf32le_code_to_mbclen(OnigCodePoint code ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:70
#define ONIGENC_IS_ASCII_CODE(code)
#define ENC_ALIAS(name, orig)
Definition: encdb.c:18
int onigenc_unicode_property_name_to_ctype(OnigEncoding enc, UChar *name, UChar *end)
Definition: unicode.c:2086
unsigned char OnigUChar
Definition: oniguruma.h:110
Win32OLEIDispatch * p
Definition: win32ole.c:778
int onigenc_unicode_mbc_case_fold(OnigEncoding enc, OnigCaseFoldType flag ARG_UNUSED, const UChar **pp, const UChar *end, UChar *fold)
Definition: unicode.c:2219
static int utf32le_mbc_enc_len(const UChar *p ARG_UNUSED, const OnigUChar *e ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:33
#define BIT_CTYPE_UPPER
int onigenc_always_false_is_allowed_reverse_match(const UChar *s ARG_UNUSED, const UChar *end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
Definition: regenc.c:656
static int utf32le_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:77
int onigenc_unicode_apply_all_case_fold(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void *arg, OnigEncoding enc ARG_UNUSED)
Definition: unicode.c:2273
#define ONIGENC_CASE_FOLD_TURKISH_AZERI
Definition: oniguruma.h:123
static int utf32le_get_case_fold_codes_by_str(OnigCaseFoldType flag, const OnigUChar *p, const OnigUChar *end, OnigCaseFoldCodeItem items[], OnigEncoding enc)
Definition: utf_32le.c:167
#define TRUE
Definition: nkf.h:186
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:3913
#define UChar
Definition: oniguruma.h:107
static UChar * utf32le_left_adjust_char_head(const UChar *start, const UChar *s, const UChar *end, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:155
int onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar *p, const OnigUChar *end, OnigCaseFoldCodeItem items[])
Definition: unicode.c:2409
v
Definition: win32ole.c:790
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
Definition: oniguruma.h:124
#define BIT_CTYPE_LOWER
#define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c)
static OnigCodePoint utf32le_mbc_to_code(const UChar *p, const UChar *end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
Definition: utf_32le.c:63
int onigenc_utf16_32_get_ctype_code_range(OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint *ranges[], struct OnigEncodingTypeST *enc ARG_UNUSED)
Definition: unicode.c:2073
Definition: nkf.c:120