2012-06-02 09:44:02 -04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/encoding.h"
|
|
|
|
|
|
|
|
static VALUE sym_7bit, sym_valid, sym_unknown, sym_broken;
|
2014-04-21 06:14:46 -04:00
|
|
|
|
2012-06-02 09:44:02 -04:00
|
|
|
static VALUE
|
2014-04-21 06:14:46 -04:00
|
|
|
coderange_int2sym(int coderange)
|
2012-06-02 09:44:02 -04:00
|
|
|
{
|
2014-04-21 06:14:46 -04:00
|
|
|
switch (coderange) {
|
2012-06-02 09:44:02 -04:00
|
|
|
case ENC_CODERANGE_7BIT:
|
|
|
|
return sym_7bit;
|
|
|
|
case ENC_CODERANGE_VALID:
|
|
|
|
return sym_valid;
|
|
|
|
case ENC_CODERANGE_UNKNOWN:
|
|
|
|
return sym_unknown;
|
|
|
|
case ENC_CODERANGE_BROKEN:
|
|
|
|
return sym_broken;
|
|
|
|
}
|
2012-06-04 01:02:27 -04:00
|
|
|
rb_bug("wrong condition of coderange");
|
2012-06-02 09:44:02 -04:00
|
|
|
UNREACHABLE;
|
|
|
|
}
|
|
|
|
|
2014-04-21 06:14:46 -04:00
|
|
|
/* return coderange without scan */
|
|
|
|
static VALUE
|
|
|
|
str_coderange(VALUE str)
|
|
|
|
{
|
|
|
|
return coderange_int2sym(ENC_CODERANGE(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scan coderange and return the result */
|
|
|
|
static VALUE
|
|
|
|
str_coderange_scan(VALUE str)
|
|
|
|
{
|
|
|
|
ENC_CODERANGE_SET(str, ENC_CODERANGE_UNKNOWN);
|
|
|
|
return coderange_int2sym(rb_enc_str_coderange(str));
|
|
|
|
}
|
|
|
|
|
2012-06-02 09:44:02 -04:00
|
|
|
void
|
2017-12-03 03:02:56 -05:00
|
|
|
Init_string_coderange(VALUE klass)
|
2012-06-02 09:44:02 -04:00
|
|
|
{
|
|
|
|
sym_7bit = ID2SYM(rb_intern("7bit"));
|
|
|
|
sym_valid = ID2SYM(rb_intern("valid"));
|
|
|
|
sym_unknown = ID2SYM(rb_intern("unknown"));
|
|
|
|
sym_broken = ID2SYM(rb_intern("broken"));
|
|
|
|
rb_define_method(klass, "coderange", str_coderange, 0);
|
2014-04-21 06:14:46 -04:00
|
|
|
rb_define_method(klass, "coderange_scan", str_coderange_scan, 0);
|
2012-06-02 09:44:02 -04:00
|
|
|
}
|