module Bindgen::Util

Defined in:

bindgen/util.cr
bindgen/util/create_by_name.cr
bindgen/util/find_matching.cr
bindgen/util/prefix.cr
bindgen/util/tribool.cr

Constant Summary

BACKREFERENCE_RX = /\\(\d)/

Matches back-references in strings.

Class Method Summary

Class Method Detail

def self.format_bytes(bytes : Int, explicit_sign = false) : String #

Formats the bytes amount as nice string.


[View source]
def self.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 _

[View source]
def self.mangle_type_names(full_type_names : String) #

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


[View source]
def self.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).


[View source]
def self.replace_backreferences(string : String, captures) : String #

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


[View source]
def self.template(haystack : String, replacement : String | Nil = nil, env = ENV) #

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|%}


[View source]
def self.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.


[View source]