Class: StructPacking::Util
- Inherits:
-
Object
- Object
- StructPacking::Util
- Defined in:
- lib/struct_packing/util.rb
Overview
internal C-like_structure_declaration
Class Method Summary collapse
-
.internal_format_from(text) ⇒ Object
Parse declaration string into internal format.
-
.pack_template_from(text, mod = nil) ⇒ Object
Parse declaration string into pack template.
Class Method Details
.internal_format_from(text) ⇒ Object
Parse declaration string into internal format. Internal format is ...
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/struct_packing/util.rb', line 137 def self.internal_format_from(text) params = {} text.split(/[\n;]/).each do |line| line.gsub!(/^\s*/,'') line.gsub!(/\s*$/,'') idx = line.rindex(' ') type = line[0..idx-1] name = line[idx+1..line.length] if name =~ /(.*)\[\w*(\d+)\w*\]\w*/ type += "[#{$2}]" name = $1 end params[name.to_sym] = type end params end |
.pack_template_from(text, mod = nil) ⇒ Object
Parse declaration string into pack template.
130 131 132 133 |
# File 'lib/struct_packing/util.rb', line 130 def self.pack_template_from(text,mod=nil) internal = internal_format_from(text) types_to_template(internal.values,mod) end |