diff options
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 13 |
1 files changed, 11 insertions, 2 deletions
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) { |