37onig_error_code_to_format(OnigPosition code)
41 if (code >= 0)
return (UChar* )0;
45 p =
"mismatch";
break;
46 case ONIG_NO_SUPPORT_CONFIG:
47 p =
"no support in this configuration";
break;
49 p =
"failed to allocate memory";
break;
50 case ONIGERR_TYPE_BUG:
51 p =
"undefined type (bug)";
break;
52 case ONIGERR_PARSER_BUG:
53 p =
"internal parser error (bug)";
break;
54 case ONIGERR_STACK_BUG:
55 p =
"stack error (bug)";
break;
56 case ONIGERR_UNDEFINED_BYTECODE:
57 p =
"undefined bytecode (bug)";
break;
58 case ONIGERR_UNEXPECTED_BYTECODE:
59 p =
"unexpected bytecode (bug)";
break;
60 case ONIGERR_MATCH_STACK_LIMIT_OVER:
61 p =
"match-stack limit over";
break;
62 case ONIGERR_PARSE_DEPTH_LIMIT_OVER:
63 p =
"parse depth limit over";
break;
64 case ONIGERR_DEFAULT_ENCODING_IS_NOT_SET:
65 p =
"default multibyte-encoding is not set";
break;
66 case ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR:
67 p =
"can't convert to wide-char on specified multibyte-encoding";
break;
68 case ONIGERR_INVALID_ARGUMENT:
69 p =
"invalid argument";
break;
70 case ONIGERR_END_PATTERN_AT_LEFT_BRACE:
71 p =
"end pattern at left brace";
break;
72 case ONIGERR_END_PATTERN_AT_LEFT_BRACKET:
73 p =
"end pattern at left bracket";
break;
74 case ONIGERR_EMPTY_CHAR_CLASS:
75 p =
"empty char-class";
break;
76 case ONIGERR_PREMATURE_END_OF_CHAR_CLASS:
77 p =
"premature end of char-class";
break;
78 case ONIGERR_END_PATTERN_AT_ESCAPE:
79 p =
"end pattern at escape";
break;
80 case ONIGERR_END_PATTERN_AT_META:
81 p =
"end pattern at meta";
break;
82 case ONIGERR_END_PATTERN_AT_CONTROL:
83 p =
"end pattern at control";
break;
84 case ONIGERR_META_CODE_SYNTAX:
85 p =
"invalid meta-code syntax";
break;
86 case ONIGERR_CONTROL_CODE_SYNTAX:
87 p =
"invalid control-code syntax";
break;
88 case ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE:
89 p =
"char-class value at end of range";
break;
90 case ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE:
91 p =
"char-class value at start of range";
break;
92 case ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS:
93 p =
"unmatched range specifier in char-class";
break;
94 case ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED:
95 p =
"target of repeat operator is not specified";
break;
96 case ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID:
97 p =
"target of repeat operator is invalid";
break;
98 case ONIGERR_NESTED_REPEAT_OPERATOR:
99 p =
"nested repeat operator";
break;
100 case ONIGERR_UNMATCHED_CLOSE_PARENTHESIS:
101 p =
"unmatched close parenthesis";
break;
102 case ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS:
103 p =
"end pattern with unmatched parenthesis";
break;
104 case ONIGERR_END_PATTERN_IN_GROUP:
105 p =
"end pattern in group";
break;
106 case ONIGERR_UNDEFINED_GROUP_OPTION:
107 p =
"undefined group option";
break;
108 case ONIGERR_INVALID_POSIX_BRACKET_TYPE:
109 p =
"invalid POSIX bracket type";
break;
110 case ONIGERR_INVALID_LOOK_BEHIND_PATTERN:
111 p =
"invalid pattern in look-behind";
break;
112 case ONIGERR_INVALID_REPEAT_RANGE_PATTERN:
113 p =
"invalid repeat range {lower,upper}";
break;
114 case ONIGERR_INVALID_CONDITION_PATTERN:
115 p =
"invalid conditional pattern";
break;
116 case ONIGERR_TOO_BIG_NUMBER:
117 p =
"too big number";
break;
118 case ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE:
119 p =
"too big number for repeat range";
break;
120 case ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE:
121 p =
"upper is smaller than lower in repeat range";
break;
122 case ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS:
123 p =
"empty range in char class";
break;
124 case ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE:
125 p =
"mismatch multibyte code length in char-class range";
break;
126 case ONIGERR_TOO_MANY_MULTI_BYTE_RANGES:
127 p =
"too many multibyte code ranges are specified";
break;
128 case ONIGERR_TOO_SHORT_MULTI_BYTE_STRING:
129 p =
"too short multibyte code string";
break;
130 case ONIGERR_TOO_BIG_BACKREF_NUMBER:
131 p =
"too big backref number";
break;
132 case ONIGERR_INVALID_BACKREF:
133#ifdef USE_NAMED_GROUP
134 p =
"invalid backref number/name";
break;
136 p =
"invalid backref number";
break;
138 case ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED:
139 p =
"numbered backref/call is not allowed. (use name)";
break;
140 case ONIGERR_TOO_SHORT_DIGITS:
141 p =
"too short digits";
break;
142 case ONIGERR_TOO_LONG_WIDE_CHAR_VALUE:
143 p =
"too long wide-char value";
break;
144 case ONIGERR_EMPTY_GROUP_NAME:
145 p =
"group name is empty";
break;
146 case ONIGERR_INVALID_GROUP_NAME:
147 p =
"invalid group name <%n>";
break;
148 case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
149#ifdef USE_NAMED_GROUP
150 p =
"invalid char in group name <%n>";
break;
152 p =
"invalid char in group number <%n>";
break;
154 case ONIGERR_UNDEFINED_NAME_REFERENCE:
155 p =
"undefined name <%n> reference";
break;
156 case ONIGERR_UNDEFINED_GROUP_REFERENCE:
157 p =
"undefined group <%n> reference";
break;
158 case ONIGERR_MULTIPLEX_DEFINED_NAME:
159 p =
"multiplex defined name <%n>";
break;
160 case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
161 p =
"multiplex definition name <%n> call";
break;
162 case ONIGERR_NEVER_ENDING_RECURSION:
163 p =
"never ending recursion";
break;
164 case ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY:
165 p =
"group number is too big for capture history";
break;
166 case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
167 p =
"invalid character property name {%n}";
break;
168 case ONIGERR_TOO_MANY_CAPTURE_GROUPS:
169 p =
"too many capture groups are specified";
break;
170 case ONIGERR_INVALID_CODE_POINT_VALUE:
171 p =
"invalid code point value";
break;
172 case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
173 p =
"too big wide-char value";
break;
174 case ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION:
175 p =
"not supported encoding combination";
break;
176 case ONIGERR_INVALID_COMBINATION_OF_OPTIONS:
177 p =
"invalid combination of options";
break;
180 p =
"undefined error code";
break;
186static void sprint_byte(
char* s,
unsigned int v)
188 xsnprintf(s, 3,
"%02x", (v & 0377));
191static void sprint_byte_with_x(
char* s,
unsigned int v)
193 xsnprintf(s, 5,
"\\x%02x", (v & 0377));
196static int to_ascii(
OnigEncoding enc, UChar *s, UChar *end,
197 UChar buf[],
int buf_size,
int *is_over)
203 if (ONIGENC_MBC_MINLEN(enc) > 1) {
207 code = ONIGENC_MBC_TO_CODE(enc, p, end);
209 if (code > 0xffff &&
len + 10 <= buf_size) {
210 sprint_byte_with_x((
char*)(&(buf[
len])), (
unsigned int)(code >> 24));
211 sprint_byte((
char*)(&(buf[
len+4])), (
unsigned int)(code >> 16));
212 sprint_byte((
char*)(&(buf[
len+6])), (
unsigned int)(code >> 8));
213 sprint_byte((
char*)(&(buf[
len+8])), (
unsigned int)code);
216 else if (
len + 6 <= buf_size) {
217 sprint_byte_with_x((
char*)(&(buf[
len])), (
unsigned int)(code >> 8));
218 sprint_byte((
char*)(&(buf[
len+4])), (
unsigned int)code);
226 buf[
len++] = (UChar )code;
229 p += enclen(enc, p, end);
230 if (
len >= buf_size)
break;
233 *is_over = ((p < end) ? 1 : 0);
236 len = (int )MIN((end - s), buf_size);
237 xmemcpy(buf, s, (
size_t )
len);
238 *is_over = ((buf_size < (end - s)) ? 1 : 0);
246#define MAX_ERROR_PAR_LEN 50
249onig_error_code_to_str(UChar* s, OnigPosition code, ...)
255 UChar parbuf[MAX_ERROR_PAR_LEN];
258 va_start(vargs, code);
261 case ONIGERR_UNDEFINED_NAME_REFERENCE:
262 case ONIGERR_UNDEFINED_GROUP_REFERENCE:
263 case ONIGERR_MULTIPLEX_DEFINED_NAME:
264 case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
265 case ONIGERR_INVALID_GROUP_NAME:
266 case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
267 case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
269 len = to_ascii(einfo->enc, einfo->par, einfo->par_end,
270 parbuf, MAX_ERROR_PAR_LEN - 3, &is_over);
271 q = onig_error_code_to_format(code);
277 xmemcpy(p, parbuf,
len);
280 xmemcpy(p,
"...", 3);
298 q = onig_error_code_to_format(code);
300 len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, q);
314onig_vsnprintf_with_pattern(UChar buf[],
int bufsize,
OnigEncoding enc,
315 UChar* pat, UChar* pat_end,
const char *fmt, va_list args)
322 n = xvsnprintf((
char* )buf, bufsize, (
const char* )fmt, args);
324 need = (pat_end - pat) * 4 + 4;
326 if (n + need < (
size_t )bufsize) {
327 static const char sep[] =
": /";
328 memcpy((
char* )buf + n, sep,
sizeof(sep));
329 s = buf + onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, buf);
332 while (p < pat_end) {
333 if (ONIGENC_IS_MBC_HEAD(enc, p, pat_end)) {
334 len = enclen(enc, p, pat_end);
335 if (ONIGENC_MBC_MINLEN(enc) == 1) {
336 while (
len-- > 0) *s++ = *p++;
342 sprint_byte_with_x((
char* )bs, (
unsigned int )(*p++));
343 blen = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
345 while (blen-- > 0) *s++ = *bp++;
349 else if (*p ==
'\\') {
351 len = enclen(enc, p, pat_end);
352 while (
len-- > 0) *s++ = *p++;
354 else if (*p ==
'/') {
355 *s++ = (
unsigned char )
'\\';
358 else if (!ONIGENC_IS_CODE_PRINT(enc, *p) &&
359 (!ONIGENC_IS_CODE_SPACE(enc, *p) ||
360 ONIGENC_IS_CODE_CNTRL(enc, *p))) {
361 sprint_byte_with_x((
char* )bs, (
unsigned int )(*p++));
362 len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs);
364 while (
len-- > 0) *s++ = *bp++;
378onig_snprintf_with_pattern(UChar buf[],
int bufsize,
OnigEncoding enc,
379 UChar* pat, UChar* pat_end,
const char *fmt, ...)
383 onig_vsnprintf_with_pattern(buf, bufsize, enc,
384 pat, pat_end, fmt, args);
int len
Length of the buffer.