Project

General

Profile

Feature #12275

String unescape

Added by asnow (Andrew Bolshov) over 1 year ago. Updated about 1 year ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:74903]

Description

I think it will be usefull to have function that convert input string as it was written in prime qouted string or in double qouted string. It's part of metaprogramming.
Example:

class String
  # Create new string like it will be writed in qoutes. Optional argument define type of qouting used: true - prime qoute, false - double qoute. Default is double qoute.
  def unescape prime = false
    eval( prime ? "'#{self}'" : "\"#{self}\"" )
  end
end

"\\\t".unescape # => "\t"

Other requests:
http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape
http://stackoverflow.com/questions/4265928/how-do-i-unescape-c-style-escape-sequences-from-ruby
http://stackoverflow.com/questions/8639642/best-way-to-escape-and-unescape-strings-in-ruby

Realized
http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape


Related issues

Related to Ruby trunk - Feature #12419: Improve String#dump for Unicode output (from "\u{130}" to "\u0130")Closed

History

#1 [ruby-core:74904] Updated by asnow (Andrew Bolshov) over 1 year ago

  • Description updated (diff)

#2 [ruby-core:74905] Updated by asnow (Andrew Bolshov) over 1 year ago

  • Description updated (diff)

#3 [ruby-core:75040] Updated by shyouhei (Shyouhei Urabe) over 1 year ago

  • Status changed from Open to Feedback

We looked at this ticket on this month's developer meeting. I then started to think that the "escape" you refer to is not that concrete.

Unescaping cannot work out without escaping. In ruby, there already is a method called String#dump. Is this what you want to negate?

irb(main):001:0> puts "\u5b57".encode('CP932').dump
"\x8E\x9A"
=> nil

#4 [ruby-core:75474] Updated by asnow (Andrew Bolshov) over 1 year ago

I think yes, inverse of String#dump. I have user inputed string without qoutes, but it don't metter much.

#5 [ruby-core:75483] Updated by shyouhei (Shyouhei Urabe) over 1 year ago

  • Status changed from Feedback to Open

Thank you. That makes sense to me because String#dump has no corresponding undump method now.

#6 [ruby-core:76411] Updated by matz (Yukihiro Matsumoto) about 1 year ago

String#undump sounds reasonable. If someone implement, it's OK to add.

Matz.

#7 Updated by duerst (Martin Dürst) about 1 year ago

  • Related to Feature #12419: Improve String#dump for Unicode output (from "\u{130}" to "\u0130") added

Also available in: Atom PDF