/*
 * 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("&gt;") - 2);
                else if (unlikely(*s == '"'))
                        new_len += (sizeof("&quot;") - 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; \
}