Module: CGI::Escape

Defined in:
ext/cgi/escape/escape.c

Instance Method Summary collapse

Instance Method Details

#escape(string) ⇒ String

Returns URL-escaped string (application/x-www-form-urlencoded).

Returns:

  • (String)


373
374
375
376
377
378
379
380
381
382
383
384
# File 'ext/cgi/escape/escape.c', line 373

static VALUE
cgiesc_escape(VALUE self, VALUE str)
{
    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        return optimized_escape(str, 1);
    }
    else {
        return rb_call_super(1, &str);
    }
}

#escapeHTML(string) ⇒ String

Returns HTML-escaped string.

Returns:

  • (String)


333
334
335
336
337
338
339
340
341
342
343
344
# File 'ext/cgi/escape/escape.c', line 333

static VALUE
cgiesc_escape_html(VALUE self, VALUE str)
{
    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        return optimized_escape_html(str);
    }
    else {
        return rb_call_super(1, &str);
    }
}

#escapeURIComponent(string) ⇒ String Also known as: escape_uri_component

Returns URL-escaped string following RFC 3986.

Returns:

  • (String)


424
425
426
427
428
429
430
431
432
433
434
435
# File 'ext/cgi/escape/escape.c', line 424

static VALUE
cgiesc_escape_uri_component(VALUE self, VALUE str)
{
    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        return optimized_escape(str, 0);
    }
    else {
        return rb_call_super(1, &str);
    }
}

#unescape(string, encoding = @@accept_charset) ⇒ String

Returns URL-unescaped string (application/x-www-form-urlencoded).

Returns:

  • (String)


401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'ext/cgi/escape/escape.c', line 401

static VALUE
cgiesc_unescape(int argc, VALUE *argv, VALUE self)
{
    VALUE str = (rb_check_arity(argc, 1, 2), argv[0]);

    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        VALUE enc = accept_charset(argc-1, argv+1, self);
        return optimized_unescape(str, enc, 1);
    }
    else {
        return rb_call_super(argc, argv);
    }
}

#unescapeHTML(string) ⇒ String

Returns HTML-unescaped string.

Returns:

  • (String)


353
354
355
356
357
358
359
360
361
362
363
364
# File 'ext/cgi/escape/escape.c', line 353

static VALUE
cgiesc_unescape_html(VALUE self, VALUE str)
{
    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        return optimized_unescape_html(str);
    }
    else {
        return rb_call_super(1, &str);
    }
}

#unescapeURIComponent(string, encoding = @@accept_charset) ⇒ String Also known as: unescape_uri_component

Returns URL-unescaped string following RFC 3986.

Returns:

  • (String)


444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'ext/cgi/escape/escape.c', line 444

static VALUE
cgiesc_unescape_uri_component(int argc, VALUE *argv, VALUE self)
{
    VALUE str = (rb_check_arity(argc, 1, 2), argv[0]);

    StringValue(str);

    if (rb_enc_str_asciicompat_p(str)) {
        VALUE enc = accept_charset(argc-1, argv+1, self);
        return optimized_unescape(str, enc, 0);
    }
    else {
        return rb_call_super(argc, argv);
    }
}