Project

General

Profile

Actions

Feature #12275

closed

String unescape

Added by asnow (Andrew Bolshov) about 8 years ago. Updated over 6 years ago.

Status:
Closed
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


Files

benchmark.rb (193 Bytes) benchmark.rb tad (Tadashi Saito), 11/27/2017 07:55 PM
v1.patch (8.95 KB) v1.patch tad (Tadashi Saito), 11/27/2017 07:56 PM
benchmark2.rb (315 Bytes) benchmark2.rb tad (Tadashi Saito), 12/09/2017 05:46 PM
v2.patch (12.1 KB) v2.patch tad (Tadashi Saito), 12/09/2017 05:46 PM
v3.patch (12.9 KB) v3.patch tad (Tadashi Saito), 12/13/2017 08:25 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12419: Improve String#dump for Unicode output (from "\u{130}" to "\u0130")Closedduerst (Martin Dürst)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0