diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-03 15:55:04 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-03 15:55:04 +0000 |
commit | 52ed8c4edd880e9b9482748e9692b1e22917bf92 (patch) | |
tree | c329bf309196494f598e017a21f9a819a34fc6be /regerror.c | |
parent | 1aaf8b171373f6862fa8c523923b98ef6feb1c65 (diff) |
* include/ruby/oniguruma.h: Oniguruma 1.9.1 merged.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regerror.c')
-rw-r--r-- | regerror.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/regerror.c b/regerror.c index cf80bbfc99..2bc2da4c71 100644 --- a/regerror.c +++ b/regerror.c @@ -142,8 +142,8 @@ onig_error_code_to_format(int code) p = "too big wide-char value"; break; case ONIGERR_TOO_LONG_WIDE_CHAR_VALUE: p = "too long wide-char value"; break; - case ONIGERR_INVALID_WIDE_CHAR_VALUE: - p = "invalid wide-char value"; break; + case ONIGERR_INVALID_CODE_POINT_VALUE: + p = "invalid code point value"; break; case ONIGERR_EMPTY_GROUP_NAME: p = "group name is empty"; break; case ONIGERR_INVALID_GROUP_NAME: @@ -182,6 +182,15 @@ onig_error_code_to_format(int code) return (UChar* )p; } +static void sprint_byte(char* s, unsigned int v) +{ + sprintf(s, "%02x", (v & 0377)); +} + +static void sprint_byte_with_x(char* s, unsigned int v) +{ + sprintf(s, "\\x%02x", (v & 0377)); +} static int to_ascii(OnigEncoding enc, UChar *s, UChar *end, UChar buf[], int buf_size, int *is_over) @@ -196,10 +205,17 @@ static int to_ascii(OnigEncoding enc, UChar *s, UChar *end, while (p < end) { code = ONIGENC_MBC_TO_CODE(enc, p, end); if (code >= 0x80) { - if (len + 5 <= buf_size) { - sprintf((char* )(&(buf[len])), "\\x%02X", - (unsigned int )(code & 0377)); - len += 5; + if (code > 0xffff && len + 10 <= buf_size) { + sprint_byte_with_x((char*)(&(buf[len])), (unsigned int)(code >> 24)); + sprint_byte((char*)(&(buf[len+4])), (unsigned int)(code >> 16)); + sprint_byte((char*)(&(buf[len+6])), (unsigned int)(code >> 8)); + sprint_byte((char*)(&(buf[len+8])), (unsigned int)code); + len += 10; + } + else if (len + 6 <= buf_size) { + sprint_byte_with_x((char*)(&(buf[len])), (unsigned int)(code >> 8)); + sprint_byte((char*)(&(buf[len+4])), (unsigned int)code); + len += 6; } else { break; @@ -209,7 +225,7 @@ static int to_ascii(OnigEncoding enc, UChar *s, UChar *end, buf[len++] = (UChar )code; } - p += enc_len(enc, p, end); + p += enclen(enc, p, end); if (len >= buf_size) break; } @@ -330,7 +346,7 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist) while (p < pat_end) { if (*p == '\\') { *s++ = *p++; - len = enc_len(enc, p, pat_end); + len = enclen(enc, p, pat_end); while (len-- > 0) *s++ = *p++; } else if (*p == '/') { @@ -338,7 +354,7 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist) *s++ = *p++; } else if (ONIGENC_IS_MBC_HEAD(enc, p, pat_end)) { - len = enc_len(enc, p, pat_end); + len = enclen(enc, p, pat_end); if (ONIGENC_MBC_MINLEN(enc) == 1) { while (len-- > 0) *s++ = *p++; } @@ -346,7 +362,7 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist) int blen; while (len-- > 0) { - sprintf((char* )bs, "\\x%02X", *p++ & 0377); + sprint_byte_with_x((char* )bs, (unsigned int )(*p++)); blen = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs); bp = bs; while (blen-- > 0) *s++ = *bp++; @@ -355,7 +371,7 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist) } else if (!ONIGENC_IS_CODE_PRINT(enc, *p) && !ONIGENC_IS_CODE_SPACE(enc, *p)) { - sprintf((char* )bs, "\\x%02X", *p++ & 0377); + sprint_byte_with_x((char* )bs, (unsigned int )(*p++)); len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs); bp = bs; while (len-- > 0) *s++ = *bp++; |