ext/iodine/iodine_helpers.c
/**
Decodes a URL encoded String, returning a new String with the decoded data.

This variation matches the Rack::Utils.unescape signature by accepting and
mostly ignoring an optional Encoding argument.
*/
Decodes a URL encoded String, returning a new String with the decoded data.
This variation matches the Rack::Utils.unescape signature by accepting and
mostly ignoring an optional Encoding argument.
Decodes a URL encoded String returning a new String with the decoded data . This variation matches the Rack :: Utils . unescape signature by accepting and mostly ignoring an optional Encoding argument .
static VALUE unescape(int argc, VALUE *argv, VALUE self) {
  if (argc < 1 || argc > 2)
    rb_raise(rb_eArgError,
             "wrong number of arguments (given %d, expected 1..2).", argc);
  VALUE str = argv[0];
  Check_Type(str, T_STRING);
  VALUE str2 = rb_str_buf_new(RSTRING_LEN(str));
  ssize_t len =
      http_decode_url(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str));
  if (len < 0)
    rb_raise(rb_eRuntimeError, "Malformed URL path string - couldn't decode.");
  rb_str_set_len(str2, len);
  rb_encoding *enc = IodineUTF8Encoding;
  if (argc == 2 && argv[1] != Qnil && argv[1] != Qfalse) {
    enc = rb_enc_get(argv[1]);
    if (!enc)
      enc = IodineUTF8Encoding;
  }
  rb_enc_associate(str2, enc);
  return str2;
  (void)self;
}
static VALUE unescape ( int argc , VALUE * argv , VALUE self ) { if ( argc < 1 || argc > 2 ) rb_raise ( rb_eArgError , " " , argc ) ; VALUE str = argv [ 0 ] ; Check_Type ( str , T_STRING ) ; VALUE str2 = rb_str_buf_new ( RSTRING_LEN ( str ) ) ; ssize_t len = http_decode_url ( RSTRING_PTR ( str2 ) , RSTRING_PTR ( str ) , RSTRING_LEN ( str ) ) ; if ( len < 0 ) rb_raise ( rb_eRuntimeError , " " ) ; rb_str_set_len ( str2 , len ) ; rb_encoding * enc = IodineUTF8Encoding ; if ( argc == 2 && argv [ 1 ] != Qnil && argv [ 1 ] != Qfalse ) { enc = rb_enc_get ( argv [ 1 ] ) ; if ( ! enc ) enc = IodineUTF8Encoding ; } rb_enc_associate ( str2 , enc ) ; return str2 ; ( void ) self ; }
Decodes a URL encoded String, returning a new String with the decoded data.
Decodes a URL encoded String returning a new String with the decoded data .