Module: RubyHeaderParser::Util

Defined in:
lib/ruby_header_parser/util.rb

Overview

util methods

Class Method Summary collapse

Class Method Details

.find_field(array, field_name) ⇒ String?

Parameters:

  • array (Array<String>)
  • field_name (String)

Returns:

  • (String, nil)


9
10
11
12
13
14
15
# File 'lib/ruby_header_parser/util.rb', line 9

def self.find_field(array, field_name)
  array.each do |element|
    return element.delete_prefix("#{field_name}:").strip if element.start_with?("#{field_name}:")
  end

  nil
end

.sanitize_type(type) ⇒ String

Parameters:

  • type (String)

Returns:

  • (String)


25
26
27
# File 'lib/ruby_header_parser/util.rb', line 25

def self.sanitize_type(type)
  type.gsub(/(enum|volatile|const|struct|static\s+inline)\s+/i, "").gsub("const*", "").strip
end

.split_signature(signature) ⇒ Array<String>

Parameters:

  • signature (String)

Returns:

  • (Array<String>)


19
20
21
# File 'lib/ruby_header_parser/util.rb', line 19

def self.split_signature(signature)
  signature.scan(/[^,]+\([^()]*\)|[^,]+/).flatten.map(&:strip)
end