def self.parse(data)
data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)
return ContentTypeStruct.new('text', 'plain', []) if Mail::Utilities.blank?(data)
content_type = ContentTypeStruct.new(nil, nil, [])
# Parser state
main_type_s = sub_type_s = param_attr_s = param_attr = nil
qstr_s = qstr = param_val_s = nil
# 5.1 Variables Used by Ragel
p = 0
eof = pe = data.length
stack = []
n
|= 0
||= data.length
= start
= 0
n
tEof = false
en, _trans, _keys, _inds, _acts, _nacts = nil
to_level = 0
sume = 10
f_trans = 15
ain = 20
st_eof = 30
t = 40
le true
_goto_level <= 0
p == pe
oto_level = _test_eof
xt
cs == 0
oto_level = _out
xt
_goto_level <= _resume
ys = cs << 1
ds = _index_offsets[cs]
en = _key_spans[cs]
de = data[p].ord
ans = if ( _slen > 0 &&
trans_keys[_keys] <= _wide &&
wide <= _trans_keys[_keys + 1]
) then
indicies[ _inds + _wide - _trans_keys[_keys] ]
lse
indicies[ _inds + _slen ]
nd
= _trans_targs[_trans]
_trans_actions[_trans] != 0
e _trans_actions[_trans]
n 1 then
gin
n_type_s = p end
n 2 then
gin
tent_type.main_type = chars(data, main_type_s, p-1).downcase end
n 3 then
gin
_type_s = p end
n 19 then
gin
tent_type.sub_type = chars(data, sub_type_s, p-1).downcase end
n 4 then
gin
am_attr_s = p end
n 6 then
gin
am_attr = chars(data, param_attr_s, p-1) end
n 9 then
gin
r_s = p end
n 11 then
gin
r = chars(data, qstr_s, p-1) end
n 7 then
gin
am_val_s = p end
n 21 then
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
n 12 then
gin
nd
n 15 then
gin
nd
n 5 then
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 18 then
gin
gin
p -= 1
= stack[top]
oto_level = _again
xt
nd
n 20 then
gin
tent_type.sub_type = chars(data, sub_type_s, p-1).downcase end
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 10 then
gin
r_s = p end
gin
r = chars(data, qstr_s, p-1) end
n 8 then
gin
am_val_s = p end
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 25 then
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 13 then
gin
nd
gin
am_attr_s = p end
n 23 then
gin
nd
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
n 14 then
gin
nd
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 16 then
gin
nd
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
n 17 then
gin
nd
gin
gin
p -= 1
= stack[top]
oto_level = _again
xt
nd
n 22 then
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
n 24 then
gin
nd
gin
gin
ack[top] = cs
p+= 1
= 35
oto_level = _again
xt
nd
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
_goto_level <= _again
cs == 0
oto_level = _out
xt
= 1
p != pe
oto_level = _resume
xt
_goto_level <= _test_eof
p == eof
ase _eof_actions[cs]
n 19 then
gin
tent_type.sub_type = chars(data, sub_type_s, p-1).downcase end
n 21 then
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
n 12 then
gin
nd
n 23 then
gin
nd
gin
if param_attr.nil?
raise Mail::Field::ParseError.new(Mail::ContentTypeElement, data, "no attribute for value")
end
# Use quoted s value if one exists, otherwise use parameter value
value = qstr || chars(data, param_val_s, p-1)
content_type.parameters << { param_attr => value }
param_attr = nil
qstr = nil
end
nd
_goto_level <= _out
eak
if p != eof || cs < 47
raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p)
end
content_type
end