From 91e5ba1cb865a2385d3e1cbfacd824496898e098 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 19 May 2009 16:59:22 +0000 Subject: * encoding.c (rb_enc_codepoint_len): combine rb_enc_codepoint() and rb_enc_codelen() in one function to reduce calls. * encoding.c (rb_enc_codepoint): compatibility function. * sprintf.c (rb_str_format): use rb_enc_codepoint_len(). * string.c (rb_str_inspect, rb_str_upcase_bang, rb_str_downcase_bang, rb_str_capitalize_bang, rb_str_swapcase_bang, trnext, tr_trans, rb_str_delete_bang, rb_str_squeeze_bang, rb_str_count, rb_str_split_m, rb_str_each_line, rb_str_each_codepoint, rb_str_lstrip_bang, sym_printable): ditto. * transcode.c (make_econv_exception): use rb_enc_mbc_to_codepoint() git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- encoding.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'encoding.c') diff --git a/encoding.c b/encoding.c index 0193575711..223eace375 100644 --- a/encoding.c +++ b/encoding.c @@ -774,18 +774,27 @@ rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc) } unsigned int -rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc) +rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc) { int r; if (e <= p) rb_raise(rb_eArgError, "empty string"); r = rb_enc_precise_mbclen(p, e, enc); - if (MBCLEN_CHARFOUND_P(r)) + if (MBCLEN_CHARFOUND_P(r)) { + if (len_p) *len_p = MBCLEN_CHARFOUND_LEN(r); return rb_enc_mbc_to_codepoint(p, e, enc); + } else rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); } +#undef rb_enc_codepoint +unsigned int +rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc) +{ + return rb_enc_codepoint_len(p, e, 0, enc); +} + int rb_enc_codelen(int c, rb_encoding *enc) { -- cgit v1.2.3