summaryrefslogtreecommitdiff
path: root/regerror.c
diff options
context:
space:
mode:
authorkosako <kosako@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-28 11:15:41 (GMT)
committerkosako <kosako@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-28 11:15:41 (GMT)
commit92d805753bf9264d35bb6ac44a740f71898654ab (patch)
tree8ab3ae4ad2b7b20268a97cdd8d2255a797342135 /regerror.c
parent972cb0fb5b18349a8dbae1d56f1819a20304a00e (diff)
merge Oniguruma 4.4.5
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regerror.c')
-rw-r--r--regerror.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/regerror.c b/regerror.c
index ad73b76..d6ec918 100644
--- a/regerror.c
+++ b/regerror.c
@@ -183,6 +183,48 @@ onig_error_code_to_format(int code)
}
+static int to_ascii(OnigEncoding enc, UChar *s, UChar *end,
+ UChar buf[], int buf_size, int *is_over)
+{
+ int len;
+ UChar *p;
+ OnigCodePoint code;
+
+ if (ONIGENC_MBC_MINLEN(enc) > 1) {
+ p = s;
+ len = 0;
+ while (p < end) {
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (code >= 0x80) {
+ if (len + 5 <= buf_size) {
+ sprintf((char* )(&(buf[len])), "\\%03o",
+ (unsigned int)(code & 0377));
+ len += 5;
+ }
+ else {
+ break;
+ }
+ }
+ else {
+ buf[len++] = (UChar )code;
+ }
+
+ p += enc_len(enc, p);
+ if (len >= buf_size) break;
+ }
+
+ *is_over = ((p < end) ? 1 : 0);
+ }
+ else {
+ len = MIN((end - s), buf_size);
+ xmemcpy(buf, s, (size_t )len);
+ *is_over = ((buf_size < (end - s)) ? 1 : 0);
+ }
+
+ return len;
+}
+
+
/* for ONIG_MAX_ERROR_MESSAGE_LEN */
#define MAX_ERROR_PAR_LEN 30
@@ -198,7 +240,8 @@ onig_error_code_to_str(s, code, va_alist)
{
UChar *p, *q;
OnigErrorInfo* einfo;
- int len;
+ int len, is_over;
+ UChar parbuf[MAX_ERROR_PAR_LEN];
va_list vargs;
va_init_list(vargs, code);
@@ -212,23 +255,20 @@ onig_error_code_to_str(s, code, va_alist)
case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
einfo = va_arg(vargs, OnigErrorInfo*);
- len = einfo->par_end - einfo->par;
+ len = to_ascii(einfo->enc, einfo->par, einfo->par_end,
+ parbuf, MAX_ERROR_PAR_LEN - 3, &is_over);
q = onig_error_code_to_format(code);
p = s;
while (*q != '\0') {
if (*q == '%') {
q++;
if (*q == 'n') { /* '%n': name */
- if (len > MAX_ERROR_PAR_LEN) {
- xmemcpy(p, einfo->par, MAX_ERROR_PAR_LEN - 3);
- p += (MAX_ERROR_PAR_LEN - 3);
+ xmemcpy(p, parbuf, len);
+ p += len;
+ if (is_over != 0) {
xmemcpy(p, "...", 3);
p += 3;
}
- else {
- xmemcpy(p, einfo->par, len);
- p += len;
- }
q++;
}
else