Ticket #1671: to_charset_binary.patch

File to_charset_binary.patch, 1.4 KB (added by NotFound, 4 years ago)
  • src/string/charset/binary.c

     
    147147 
    148148=item C<static STRING* to_charset(PARROT_INTERP, const STRING *src)> 
    149149 
    150 Converts the STRING C<src> to STRING C<dest> in binary mode. Throws 
    151 an exception if a suitable conversion function is not found. 
     150Converts the STRING C<src> to STRING C<dest> in binary mode.  
     151Just a byte image of the string content regardless its charset 
     152and encoding. The user is supposed to know what is doing. 
    152153 
    153154=cut 
    154155 
     
    159160to_charset(PARROT_INTERP, ARGIN(const STRING *src)) 
    160161{ 
    161162    ASSERT_ARGS(to_charset) 
    162     charset_converter_t conversion_func = 
    163         Parrot_find_charset_converter(interp, src->charset, Parrot_binary_charset_ptr); 
    164163 
    165     if (conversion_func) 
    166          return conversion_func(interp, src); 
    167  
    168     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, 
    169         "to_charset for binary not implemented"); 
     164    const UINTVAL bytel = src->bufused; 
     165    STRING *r = Parrot_gc_new_string_header(interp, 0); 
     166    Parrot_gc_allocate_string_storage(interp, r, bytel); 
     167    r->strlen = bytel; 
     168    r->bufused = bytel; 
     169    r->charset = Parrot_binary_charset_ptr; 
     170    r->encoding = Parrot_fixed_8_encoding_ptr; 
     171    mem_sys_memcopy(r->strstart, src->strstart, bytel); 
     172    return r; 
    170173} 
    171174 
    172175/*