Module: Clojure

Defined in:
lib/clj.rb,
lib/clj/types.rb,
lib/clj/parser.rb

Overview

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                  Version 2, December 2004

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

++

Defined Under Namespace

Modules: Metadata Classes: List, Map, Parser, Set, Symbol, Vector

Constant Summary collapse

UNESCAPE_REGEX =
%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n
UNESCAPE_MAP =

Unescape characters in strings.

Hash.new { |h, k| h[k] = k.chr }
EMPTY_8BIT_STRING =
''
UNICODE_REGEX =
UNICODE_REGEX
OCTAL_REGEX =
OCTAL_REGEX

Class Method Summary collapse

Class Method Details

.dump(what, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/clj.rb', line 16

def self.dump (what, options = {})
  raise ArgumentError, 'cannot convert the passed value to clojure' unless what.respond_to? :to_clj

  what.to_clj(options)
end

.parse(*args) ⇒ Object



12
13
14
# File 'lib/clj.rb', line 12

def self.parse (*args)
  Clojure::Parser.new(*args).parse
end

.unescape(string) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/clj.rb', line 44

def self.unescape (string)
  string.gsub(UNESCAPE_REGEX) {|escape|
    if u = UNESCAPE_MAP[$&[1]]
      next u
    end

    bytes = EMPTY_8BIT_STRING.dup

    i = 0
    while escape[6 * i] == ?\\ && escape[6 * i + 1] == ?u
      bytes << escape[6 * i + 2, 2].to_i(16) << escape[6 * i + 4, 2].to_i(16)

      i += 1
    end

    if bytes.respond_to? :force_encoding
      bytes.force_encoding 'UTF-16be'
      bytes.encode 'UTF-8'
    else
      bytes
    end
  }
end