method
undump
v2_5_5 -
Show latest stable
-
0 notes -
Class: String
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
Related methods
- Class methods (3)
- new
- try_convert
- yaml_new (<= v1_9_1_378)
- Instance methods (168)
- <<
- <=>
- =~
- ==
- ===
- -@
- []
- []=
- *
- %
- +
- +@
- ascii_only?
- b
- block_scanf
- bytes
- bytesize
- byteslice
- capitalize
- capitalize!
- casecmp
- casecmp?
- center
- chars
- chomp
- chomp!
- chop
- chop!
- chr
- clear
- codepoints
- concat
- count
- crypt
- delete
- delete!
- delete_prefix
- delete_prefix!
- delete_suffix
- delete_suffix!
- downcase
- downcase!
- dump
- each (<= v1_8_7_330)
- each_byte
- each_char
- each_codepoint
- each_grapheme_cluster
- each_line
- empty?
- encode
- encode!
- encoding
- end_regexp (<= v1_8_7_330)
- end_with?
- eql?
- _expand_ch (<= v1_8_7_330)
- expand_ch_hash (<= v1_8_7_330)
- ext (<= v2_2_9)
- force_encoding
- freeze
- getbyte
- grapheme_clusters
- gsub
- gsub!
- hash
- hex
- include?
- index
- initialize_copy
- insert
- inspect
- intern
- is_binary_data? (<= v1_9_1_378)
- is_complex_yaml? (<= v1_9_1_378)
- iseuc
- isjis
- issjis
- isutf8
- jcount (<= v1_8_7_330)
- jlength (<= v1_8_7_330)
- jsize (<= v1_8_7_330)
- kconv
- length
- lines
- ljust
- lstrip
- lstrip!
- match
- match?
- mbchar? (<= v1_8_7_330)
- next
- next!
- oct
- ord
- original_succ (<= v1_8_7_330)
- original_succ! (<= v1_8_7_330)
- parse_csv
- partition
- pathmap (<= v2_2_9)
- pathmap_explode (<= v2_2_9)
- pathmap_partial (<= v2_2_9)
- pathmap_replace (<= v2_2_9)
- prepend
- pretty_print
- quote (<= v1_8_6_287)
- _regex_quote (<= v1_8_7_330)
- replace
- reverse
- reverse!
- rindex
- rjust
- rpartition
- rstrip
- rstrip!
- scan
- scanf
- scrub
- scrub!
- setbyte
- shellescape
- shellsplit
- size
- slice
- slice!
- split
- squeeze
- squeeze!
- start_with?
- strip
- strip!
- sub
- sub!
- succ
- succ!
- sum
- swapcase
- swapcase!
- to_c
- to_d
- toeuc
- to_f
- to_i
- tojis
- tolocale
- to_r
- to_s
- tosjis
- to_str
- to_sym
- toutf16
- toutf32
- toutf8
- to_yaml (<= v1_9_1_378)
- tr
- tr!
- tr_s
- tr_s!
- undump
- unicode_normalize
- unicode_normalize!
- unicode_normalized?
- unpack
- unpack1
- upcase
- upcase!
- upto
- valid_encoding?
= private
= protected
undump()
public
Produces unescaped version of str. See also String#dump because String#undump does inverse of String#dump.
"\"hello \\n ''\"".undump #=> "hello \n ''"
Show source
static VALUE str_undump(VALUE str) { const char *s = RSTRING_PTR(str); const char *s_end = RSTRING_END(str); rb_encoding *enc = rb_enc_get(str); VALUE undumped = rb_enc_str_new(s, 0L, enc); bool utf8 = false; bool binary = false; int w; rb_must_asciicompat(str); if (rb_str_is_ascii_only_p(str) == Qfalse) { rb_raise(rb_eRuntimeError, "non-ASCII character detected"); } if (!str_null_check(str, &w)) { rb_raise(rb_eRuntimeError, "string contains null byte"); } if (RSTRING_LEN(str) < 2) goto invalid_format; if (*s != '"') goto invalid_format; /* strip '"' at the start */ s++; for (;;) { if (s >= s_end) { rb_raise(rb_eRuntimeError, "unterminated dumped string"); } if (*s == '"') { /* epilogue */ s++; if (s == s_end) { /* ascii compatible dumped string */ break; } else { const char *encname; int encidx; ptrdiff_t size; if (utf8) { rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding"); } size = rb_strlen_lit(".force_encoding(\""); if (s_end - s <= size) goto invalid_format; if (memcmp(s, ".force_encoding(\"", size) != 0) goto invalid_format; s += size; encname = s; s = memchr(s, '"', s_end-s); size = s - encname; if (!s) goto invalid_format; if (s_end - s != 2) goto invalid_format; if (s[0] != '"' || s[1] != ')') goto invalid_format; encidx = rb_enc_find_index2(encname, (long)size); if (encidx < 0) { rb_raise(rb_eRuntimeError, "dumped string has unknown encoding name"); } rb_enc_associate_index(undumped, encidx); } break; } if (*s == '\\') { s++; if (s >= s_end) { rb_raise(rb_eRuntimeError, "invalid escape"); } undump_after_backslash(undumped, &s, s_end, &enc, &utf8, &binary); } else { rb_str_cat(undumped, s++, 1); } } OBJ_INFECT(undumped, str); return undumped; invalid_format: rb_raise(rb_eRuntimeError, "invalid dumped string; not wrapped with '\"' nor '\"...\".force_encoding(\"...\")' form"); }