[ruby] use WCHAR_MAX to determine the encoding of std::wstring.
This commit is contained in:
parent
bfe7204576
commit
5722d81a09
2 changed files with 32 additions and 25 deletions
|
|
@ -1,13 +1,6 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* rubywstrings.swg
|
||||
*
|
||||
* Currently, Ruby does not support Unicode or WChar properly, so these
|
||||
* are still treated as char arrays for now.
|
||||
* There are other libraries available that add support to this in
|
||||
* ruby including WString, FXString, etc.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
|
|
@ -15,17 +8,11 @@
|
|||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc)
|
||||
{
|
||||
VALUE tmp;
|
||||
VALUE tmp = rb_str_conv_enc(obj, rb_enc_get(obj),
|
||||
rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_WSTRING_ENCODING )) );
|
||||
*alloc = SWIG_NEWOBJ;
|
||||
if(sizeof(wchar_t) == 4) {
|
||||
tmp = rb_str_conv_enc(obj, rb_enc_get(obj), rb_to_encoding(rb_str_new_cstr("UTF-32")) );
|
||||
} else if (sizeof(wchar_t) == 2) {
|
||||
tmp = rb_str_conv_enc(obj, rb_enc_get(obj), rb_to_encoding(rb_str_new_cstr("UTF-16")) );
|
||||
} else {
|
||||
rb_raise(rb_eRuntimeError, "unsupported wchar_t size");
|
||||
}
|
||||
return SWIG_AsCharPtrAndSize( tmp, (char**)cptr, psize, alloc);
|
||||
|
||||
return SWIG_AsCharPtrAndSize(tmp, (char**)cptr, psize, alloc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,18 +22,13 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
|
|||
{
|
||||
VALUE ret = SWIG_FromCharPtrAndSize( (const char*)carray, size);
|
||||
rb_encoding* enc = rb_default_internal_encoding();
|
||||
if(sizeof(wchar_t) == 4) {
|
||||
rb_enc_associate(ret, rb_to_encoding(rb_str_new_cstr("UTF-32")));
|
||||
} else if (sizeof(wchar_t) == 2) {
|
||||
rb_enc_associate(ret, rb_to_encoding(rb_str_new_cstr("UTF-16")));
|
||||
} else {
|
||||
rb_raise(rb_eRuntimeError, "unsupported wchar_t size");
|
||||
}
|
||||
|
||||
rb_enc_associate(ret, rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_WSTRING_ENCODING )) );
|
||||
|
||||
if( !enc ) {
|
||||
enc = rb_to_encoding(rb_str_new_cstr("UTF-8"));
|
||||
enc = rb_to_encoding(rb_str_new_cstr( SWIG_RUBY_INTERNAL_ENCODING ));
|
||||
}
|
||||
return rb_str_conv_enc(ret, rb_enc_get(ret), enc );
|
||||
return rb_str_conv_enc(ret, rb_enc_get(ret), enc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue