Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#fast_uxs_cgi ⇒ Object
Unescapes CGI, converting plus bytes ‘+’ to space ‘ ’.
-
#fast_xs ⇒ Object
escapes strings for XML The double-quote (“) character is translated to ”"“.
-
#fast_xs_cgi ⇒ Object
Compatible with CGI::escape(), this iterates through each byte, so multibyte character sets may not supported (but UTF-8 should be).
-
#fast_xs_html ⇒ Object
This is coding agnostic, and works on each byte, so some multibyte character sets may not be fully supported (but UTF-8 should be).
-
#fast_xs_url ⇒ Object
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).
Instance Method Details
#fast_uxs_cgi ⇒ Object
Unescapes CGI, converting plus bytes ‘+’ to space ‘ ’
155 156 157 158 |
# File 'ext/fast_xs_extra/fast_xs_extra.c', line 155
static VALUE fast_uxs_cgi(VALUE self)
{
return _uxs_uri(self, 1);
}
|
#fast_xs ⇒ Object
escapes strings for XML The double-quote (“) character is translated to ”"“
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/fast_xs/fast_xs.c', line 135
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 = fast_xs_buf_new(self, 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 ⇒ Object
Compatible with CGI::escape(), this iterates through each byte, so multibyte character sets may not supported (but UTF-8 should be).
109 110 111 112 |
# File 'ext/fast_xs_extra/fast_xs_extra.c', line 109
static VALUE fast_xs_cgi(VALUE self)
{
return _xs_uri_encode(self, 1);
}
|
#fast_xs_html ⇒ Object
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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'ext/fast_xs_extra/fast_xs_extra.c', line 17
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 = fast_xs_buf_new(self, new_len);
new_str = RSTRING_PTR(rv);
for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
if (unlikely(*s == '&'))
APPEND_CONST(new_str, "&");
else if (unlikely(*s == '<'))
APPEND_CONST(new_str, "<");
else if (unlikely(*s == '>'))
APPEND_CONST(new_str, ">");
else if (unlikely(*s == '"'))
APPEND_CONST(new_str, """);
else
*new_str++ = *s;
}
return rv;
}
|
#fast_xs_url ⇒ Object
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).
100 101 102 103 |
# File 'ext/fast_xs_extra/fast_xs_extra.c', line 100
static VALUE fast_xs_url(VALUE self)
{
return _xs_uri_encode(self, 0);
}
|