module

Bindgen::Util

Constants

BACKREFERENCE_RX = /\\(\d)/

Matches back-references in strings.

BALANCED_PARENS_RX = /\( ( [^()]++ | (?R) )* \)/x

Matches strings with balanced parentheses. (http://www.pcre.org/original/doc/html/pcrepattern.html#SEC23)

FAIL_RX = /(?!)/

Matches absolutely nothing, not even the empty string.

Class methods

format_bytes(bytes : Int, explicit_sign = false) : String

Formats the bytes amount as nice string.

Source
mangle_instantiation_name(cpp_name : String) : String

Mangles the class template instantiation cpp_name into a valid identifier, e.g. Foo<int, -1> into Foo_int_Neg1.

Source
mangle_type_name(full_type_name : String)

Mangles the type name of full_type_name for the binding function:

  • A pointer-star is turned into X
  • A reference-ampersand is turned into R
  • Any non-word character is replaced with _
Source
mangle_type_names(full_type_names : String)

Mangles a list of type-names into a combined string.

Source
pattern_rewrite(pattern : String | Nil, groups) : String

Using the rewrite pattern, containing back-references, builds a new string. If pattern is nil, then groups[1], then groups[0] is returned (Whichever is non-nil first).

Source
replace_backreferences(string : String, captures) : String

Replaces back-references in strings with captures from an existing Array(String) or Regex::MatchData.

Source
template(haystack : String, replacement : String | Nil = nil, env = ENV) : String

Templates the string haystack, replacing occurences of % with replacement. If replacement is nil, this behaviour is disabled.

The user can also access environment variables using the syntax {NAME}, with NAME being the variable name. A default fallback, in case the NAME is unset, can be provided through a pipe symbol: {NAME|default}.

It's possible to fall back to the character expansion: {NAME|%}

Source
template_instantiation?(cpp_name : String) : Bool

Is cpp_name a class template instantiation, like Foo<int>?

Source
uniq_by(list : Array, &)

Mimics Rubys Enumerable#uniq_by. Takes a list, and makes all values in it unique by yielding all pairs, keeping only those items where the block returned a falsy value.

This method is O(n²), prefer Enumerable#uniq if possible.

Source

Nested types