Skip to content
Browse files

Added rb_enc_mbclen.

  • Loading branch information...
1 parent f1f358f commit dbfeb76a1421a76f59471774dc4e956ef678053e @brixen brixen committed Dec 6, 2011
Showing with 11 additions and 0 deletions.
  1. +1 −0 vm/capi/19/include/ruby/encoding.h
  2. +10 −0 vm/capi/encoding.cpp
View
1 vm/capi/19/include/ruby/encoding.h
@@ -32,6 +32,7 @@ typedef OnigEncodingType rb_encoding;
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
+int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc);
int rb_enc_codelen(int code, rb_encoding *enc);
View
10 vm/capi/encoding.cpp
@@ -90,6 +90,16 @@ extern "C" {
return env->get_handle(Encoding::ascii_encoding(env->state()));
}
+ int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc) {
+ int n = ONIGENC_PRECISE_MBC_ENC_LEN(enc, (UChar*)p, (UChar*)e);
+ if (ONIGENC_MBCLEN_CHARFOUND_P(n) && ONIGENC_MBCLEN_CHARFOUND_LEN(n) <= e-p)
+ return ONIGENC_MBCLEN_CHARFOUND_LEN(n);
+ else {
+ int min = rb_enc_mbminlen(enc);
+ return min <= e-p ? min : (int)(e-p);
+ }
+ }
+
int rb_enc_precise_mbclen(const char* p, const char* e, rb_encoding *enc) {
int n;
if(e <= p) {

0 comments on commit dbfeb76

Please sign in to comment.
Something went wrong with that request. Please try again.