Ejemplo n.º 1
0
static VALUE stringForceUTF8(VALUE arg)
{
    if (rb_type(arg) == RUBY_T_STRING && ENCODING_IS_ASCII8BIT(arg))
        rb_enc_associate_index(arg, rb_utf8_encindex());

    return arg;
}
Ejemplo n.º 2
0
static VALUE stringForceUTF8(VALUE arg)
{
	if (RB_TYPE_P(arg, RUBY_T_STRING) && ENCODING_IS_ASCII8BIT(arg))
		rb_enc_associate_index(arg, rb_utf8_encindex());

	return arg;
}
Ejemplo n.º 3
0
/*
 * Validate and convert the contents of a String to a Verse host id
 */
inline uint8 *
rbverse_str2host_id( VALUE idstring ) {
	if ( !ENCODING_IS_ASCII8BIT(idstring) )
		rb_raise( rb_eArgError, "invalid encoding: expected ASCII-8BIT data" );

	if ( RSTRING_LEN(idstring) > V_HOST_ID_SIZE ) {
		rb_raise( rb_eArgError,
		          "hostid is too long: should be %d bytes, got %ld", 
		          V_HOST_ID_SIZE, RSTRING_LEN(idstring) );
	} else if ( RSTRING_LEN(idstring) < V_HOST_ID_SIZE ) {
		rb_raise( rb_eArgError,
		          "hostid is too short: should be %d bytes, got %ld", 
		          V_HOST_ID_SIZE, RSTRING_LEN(idstring) );
	}

	return (uint8 *)RSTRING_PTR(idstring);
}