nkf(p1, p2)
public
Convert str and return
converted result. Conversion details are specified by opt as String.
require 'nkf'
output = NKF.nkf("-s", input)
Show source
static VALUE
rb_nkf_convert(VALUE obj, VALUE opt, VALUE src)
{
VALUE tmp;
reinit();
nkf_split_options(StringValueCStr(opt));
if (!output_encoding) rb_raise(rb_eArgError, "no output encoding given");
switch (nkf_enc_to_index(output_encoding)) {
case UTF_8_BOM: output_encoding = nkf_enc_from_index(UTF_8); break;
case UTF_16BE_BOM: output_encoding = nkf_enc_from_index(UTF_16BE); break;
case UTF_16LE_BOM: output_encoding = nkf_enc_from_index(UTF_16LE); break;
case UTF_32BE_BOM: output_encoding = nkf_enc_from_index(UTF_32BE); break;
case UTF_32LE_BOM: output_encoding = nkf_enc_from_index(UTF_32LE); break;
}
output_bom_f = FALSE;
incsize = INCSIZE;
input_ctr = 0;
input = (unsigned char *)StringValuePtr(src);
i_len = RSTRING_LENINT(src);
tmp = rb_str_new(0, i_len*3 + 10);
output_ctr = 0;
output = (unsigned char *)RSTRING_PTR(tmp);
o_len = RSTRING_LENINT(tmp);
*output = '\0';
/* use _result_ begin*/
result = tmp;
kanji_convert(NULL);
result = Qnil;
/* use _result_ end */
rb_str_set_len(tmp, output_ctr);
OBJ_INFECT(tmp, src);
if (mimeout_f)
rb_enc_associate(tmp, rb_usascii_encoding());
else
rb_enc_associate(tmp, rb_nkf_enc_get(nkf_enc_name(output_encoding)));
return tmp;
}