Module: KernAux

Defined in:
lib/kernaux.rb,
lib/kernaux/ntoa.rb,
lib/kernaux/assert.rb,
lib/kernaux/errors.rb,
lib/kernaux/cmdline.rb,
lib/kernaux/version.rb,
ext/default/main.c

Overview

Binding to libkernaux - auxiliary library for kernel development.

Defined Under Namespace

Modules: Version Classes: AssertError, CmdlineError, Error, InvalidNtoaBaseError, TooLongNtoaPrefixError

Constant Summary collapse

DEFAULT_ASSERT_CB =

Default callback for assertions.

See Also:

@assert_cb = lambda { |file, line, msg|
  raise AssertError, "#{file}:#{line}:#{msg}"
}
VERSION =

Gem version.

'0.7.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.assert_cbProc

Panic callback.

Returns:

  • (Proc)

See Also:



# File 'lib/kernaux/assert.rb', line 15

Class Method Details

.assert_do(file, line, msg) ⇒ nil

Raise assertion with explicit file, line and message.

Parameters:

  • file (String)

    file name, usually from __FILE__

  • line (Integer)

    line number, usually from __LINE__

  • msg (String)

    any message

Returns:

  • (nil)

Raises:

See Also:



# File 'lib/kernaux/assert.rb', line 43

.cmdline(str) ⇒ Array<String>

Parse command line.

Parameters:

  • str (String)

    command line string

Returns:

  • (Array<String>)

    command line arguments

Raises:



# File 'lib/kernaux/cmdline.rb', line 9

.itoa(number, base, prefix) ⇒ String

Convert int64_t to a string in multiple numeral systems.

Base can be a positive or negative integer between 2 and 36, or a symbol which is an alias to a valid integer value. Positive integers and lowercase symbols mean lowercase output when base is greater than 10. Negative integers and uppercase symbols mean uppercase output when base is greater than 10. Aliases are: :b, :B - 2; :o, :O - 8; :d, :D - 10; :h, :x - 16 (lowercase); :H, :X - -10 (uppercase).

Parameters:

  • number (Integer)

    a number between INT64_MIN and INT64_MAX

  • base (Integer, Symbol)

    base of a numeral system

  • prefix (nil, String)

    string to put between a sign and a number

Returns:

  • (String)

Raises:

See Also:



# File 'lib/kernaux/ntoa.rb', line 32

.itoa10(number) ⇒ String

Convert int64_t to a decimal string.

Parameters:

  • number (Integer)

    a number between INT64_MIN and INT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 105

.itoa16(number) ⇒ String

Convert int64_t to a hexadecimal string.

Parameters:

  • number (Integer)

    a number between INT64_MIN and INT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 125

.itoa2(number) ⇒ String

Convert int64_t to a binary string.

Parameters:

  • number (Integer)

    a number between INT64_MIN and INT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 65

.itoa8(number) ⇒ String

Convert int64_t to a octal string.

Parameters:

  • number (Integer)

    a number between INT64_MIN and INT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 85

.panic(msg) ⇒ nil

Raise assertion with implicit file and line, retrieved from caller, and explicit message.

Parameters:

  • msg (String)

    any message

Returns:

  • (nil)

Raises:

See Also:



38
39
40
41
# File 'lib/kernaux/assert.rb', line 38

def self.panic(msg)
  file, line = caller(1..1).first.split(':')[0..1]
  assert_do file, Integer(line), msg
end

.sprintfString

Typical printf.

Examples:

KernAux.sprintf 'foo%*scar%d', 5, 'bar', 123
#=> "foo  barcar123"

Parameters:

  • format (String)

    format string

Returns:

  • (String)

    formatted output



18
# File 'ext/default/printf.c', line 18

static VALUE rb_KernAux_sprintf(int argc, VALUE *argv, VALUE self);

.utoa(number, base, prefix) ⇒ String

Convert uint64_t to a string in multiple numeral systems.

Base can be a positive or negative integer between 2 and 36, or a symbol which is an alias to a valid integer value. Positive integers and lowercase symbols mean lowercase output when base is greater than 10. Negative integers and uppercase symbols mean uppercase output when base is greater than 10. Aliases are: :b, :B - 2; :o, :O - 8; :d, :D - 10; :h, :x - 16 (lowercase); :H, :X - -10 (uppercase).

Parameters:

  • number (Integer)

    a number between 0 and UINT64_MAX

  • base (Integer, Symbol)

    base of a numeral system

  • prefix (nil, String)

    string to put before a number

Returns:

  • (String)

Raises:

See Also:



# File 'lib/kernaux/ntoa.rb', line 9

.utoa10(number) ⇒ String

Convert uint64_t to a decimal string.

Parameters:

  • number (Integer)

    a number between 0 and UINT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 95

.utoa16(number) ⇒ String

Convert uint64_t to a hexadecimal string.

Parameters:

  • number (Integer)

    a number between 0 and UINT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 115

.utoa2(number) ⇒ String

Convert uint64_t to a binary string.

Parameters:

  • number (Integer)

    a number between 0 and UINT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 55

.utoa8(number) ⇒ String

Convert uint64_t to a octal string.

Parameters:

  • number (Integer)

    a number between 0 and UINT64_MAX

Returns:

  • (String)

Raises:

  • (RangeError)

    number is out of range



# File 'lib/kernaux/ntoa.rb', line 75