class String
Public Instance Methods
fast_uxs_cgi()
click to toggle source
Unescapes CGI, converting plus bytes '+' to space ' '
static VALUE fast_uxs_cgi(VALUE self) { return _uxs_uri(self, 1); }
fast_xs()
click to toggle source
escapes strings for XML The double-quote (“) character is translated to ”"“
static VALUE fast_xs(VALUE self) { long i; VALUE array; char *c; size_t s_len; VALUE *tmp; VALUE rv; array = rb_rescue(unpack_utf8, self, unpack_uchar, self); for (tmp = RARRAY_PTR(array), s_len = i = RARRAY_LEN(array); --i >= 0; tmp++) { int n = NUM2INT(*tmp); if (likely(n < 128)) { if (unlikely(n == '"')) s_len += (sizeof(""") - 2); if (unlikely(n == '&')) s_len += (sizeof("&") - 2); if (unlikely(n == '>' || n == '<')) s_len += (sizeof(">") - 2); continue; } CP_1252_ESCAPE(n); if (VALID_VALUE(n)) s_len += bytes_for(n) - 1; } rv = rb_str_new(NULL, s_len); c = RSTRING_PTR(rv); for (tmp = RARRAY_PTR(array), i = RARRAY_LEN(array); --i >= 0; tmp++) c += escape(c, NUM2INT(*tmp)); return rv; }
fast_xs_cgi()
click to toggle source
Compatible with CGI::escape(), this iterates through each byte, so multibyte character sets may not supported (but UTF-8 should be).
static VALUE fast_xs_cgi(VALUE self) { return _xs_uri_encode(self, 1); }
fast_xs_html()
click to toggle source
This is coding agnostic, and works on each byte, so some multibyte character sets may not be fully supported (but UTF-8 should be). This is meant to be 100% compatible with the ERB::Util::escape_html and CGI::escapeHTML methods
static VALUE fast_xs_html(VALUE self) { long i; char *s; size_t new_len = RSTRING_LEN(self); char *new_str; VALUE rv; for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) { if (unlikely(*s == '&')) new_len += (sizeof("&") - 2); else if (unlikely(*s == '<' || *s == '>')) new_len += (sizeof(">") - 2); else if (unlikely(*s == '"')) new_len += (sizeof(""") - 2); } rv = rb_str_new(NULL, new_len); new_str = RSTRING_PTR(rv); #define append_const(buf, x) do { \ buf = memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \ }
fast_xs_url()
click to toggle source
Compatible with ERB::Util::url_encode / ERB::Util::u, this iterates through each byte, so multibyte character sets may not supported (but UTF-8 should be).
static VALUE fast_xs_url(VALUE self) { return _xs_uri_encode(self, 0); }