Method: U::String#dump
- Defined in:
- ext/u/rb_u_string_dump.c
#dump ⇒ U::String
Returns the receiver in a reader-friendly format, inheriting any taint and untrust.
The reader-friendly format looks like “‘“…”.u`”. Inside the “…”, any #print? characters in the ASCII range are output as-is, the following special characters are escaped according to the following table:
<table>
<thead><tr><th>Character</th><th>Dumped Sequence</th></tr></thead>
<tbody>
<tr><td>U+0022 QUOTATION MARK</td><td><code>\"</code></td></tr>
<tr><td>U+005C REVERSE SOLIDUS</td><td><code>\\</code></td></tr>
<tr><td>U+000A LINE FEED (LF)</td><td><code>\n</code></td></tr>
<tr><td>U+000D CARRIAGE RETURN (CR)</td><td><code>\r</code></td></tr>
<tr><td>U+0009 CHARACTER TABULATION</td><td><code>\t</code></td></tr>
<tr><td>U+000C FORM FEED (FF)</td><td><code>\f</code></td></tr>
<tr><td>U+000B LINE TABULATION</td><td><code>\v</code></td></tr>
<tr><td>U+0008 BACKSPACE</td><td><code>\b</code></td></tr>
<tr><td>U+0007 BELL</td><td><code>\a</code></td></tr>
<tr><td>U+001B ESCAPE</td><td><code>\e</code></td></tr>
</tbody>
</table>
the following special sequences are also escaped:
<table>
<thead><tr><th>Character</th><th>Dumped Sequence</th></tr></thead>
<tbody>
<tr><td><code>#$</code></td><td><code>\#$</code></td></tr>
<tr><td><code>#@</code></td><td><code>\#@</code></td></tr>
<tr><td><code>#{</code></td><td><code>\#{</code></td></tr>
</tbody>
</table>
any valid UTF-8 byte sequences are output as “‘\u{_n_}`”, where n is the lowercase hexadecimal representation of the code point encoded by the UTF-8 sequence, and any other byte is output as “`\x`n”, where n is the two-digit uppercase hexadecimal representation of the byte’s value.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/u/rb_u_string_dump.c', line 125 VALUE rb_u_string_dump(VALUE self) { const struct rb_u_string *string = RVAL2USTRING(self); const char *p = USTRING_STR(string); const char *end = USTRING_END(string); VALUE buffer = rb_u_buffer_new_sized(7); rb_u_buffer_append(buffer, "\"", 1); while (p < end) { unsigned char c = *p; if (!rb_u_string_dump_escape(buffer, c) && !rb_u_string_dump_hash(buffer, c, p, end) && !rb_u_string_dump_ascii_printable(buffer, c) && !rb_u_string_dump_codepoint(buffer, &p, end)) rb_u_string_dump_hex(buffer, c); p++; } rb_u_buffer_append(buffer, "\".u", 3); VALUE result = rb_u_buffer_to_u_bang(buffer); OBJ_INFECT(result, self); return result; } |