53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/bundler/yaml_serializer.rb', line 53
def load(str)
res = {}
stack = [res]
last_hash = nil
last_empty_key = nil
str.split(/\r?\n/) do |line|
if match = HASH_REGEX.match(line)
indent, key, quote, val = match.captures
val = (val)
depth = indent.size / 2
if quote.empty? && val.empty?
new_hash = {}
stack[depth][key] = new_hash
stack[depth + 1] = new_hash
last_empty_key = key
last_hash = stack[depth]
else
val = [] if val == "[]" stack[depth][key] = val
end
elsif match = ARRAY_REGEX.match(line)
_, val = match.captures
val = (val)
last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array)
last_hash[last_empty_key].push(val)
end
end
res
end
|