module RemiLib

Overview

libremiliacr is a small library that provides utility functions and some extra batteries to Crystal. It's similar in nature (and design) to my cl-sdm library for Common Lisp.

Extended Modules

Defined in:

libremiliacr.cr
remilib/arraypool.cr
remilib/bitreader.cr
remilib/concurrency.cr
remilib/dependencygraph.cr
remilib/extensions.cr
remilib/logging.cr
remilib/strenum.cr
remilib/strings.cr

Constant Summary

HUMAN_SIZE_SUFFIXES = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
VERSION = "0.8.5"

The version of the library.

Class Method Summary

Macro Summary

Instance Method Summary

Class Method Detail

def self.log : Logger #

An instance of a Logger, provided for convenience. You may use your own instance if you wish, or this one.


[View source]
def self.withDisplacedArray(displacedTo : Array(T) | Slice(T), displacedIndexOffset : Int, size : Int, &) forall T #

Creates a "displaced array", which is a Slice that has no storage of its own, but instead points into a subsequence within displacedTo. Changes to the yielded slice will change displacedTo.

The yielded Slice's index 0 will correspond to displacedTo[displacedIndexOffset], while size is the number of elements in Slice. The total size of the yielded Slice must be less than or equal to the size of displacedTo.

http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_d.htm#displaced_array


[View source]

Macro Detail

macro defineStringEnum(name, *values) #

Defines an Enum that that allows you to map keys to specific strings. The enum keys still have numerical values just like any other Enum, but these numerical values cannot be specified.


[View source]
macro setonce!(*names) #

Defines raise-on-nil and nilable getter methods for each of the given arguments, as well as a setter method that can only be called if the current value is nil.


[View source]

Instance Method Detail

def buildWrapped(text : String, str : IO, *, indent : Int = 0, firstLineOffset : Int = 0, maxWidth : Int = 80, indentChar : Char = ' ') #

Prints text to str, wrapping the text as it goes. indent is the number of indentChars to write at the beginning of each line. maxWidth is the maximum length of a line of text.

The first line can be shorter by applying an additional offset of firstLineOffset. Thus the first line will be at most maxWidth - indent - firstLineOffset long.


[View source]
def makeWrapped(text : String, *, indent : Int = 0, maxWidth : Int = 80, firstLineOffset : Int = 0, indentChar : Char = ' ') #

Prints text to a new string, wrapping the text as it goes, then returns the new string. indent is the number of indentChars to write at the beginning of each line. maxWidth is the maximum length of a line of text.

The first line can be shorter by applying an additional offset of firstLineOffset. Thus the first line will be at most maxWidth - indent - firstLineOffset long.


[View source]
def padString(str : String, minLength : Int) : String #

Returns a new String that contains str. If the length of str is less than minLength, then additional null bytes are added until the length is equal to minLength.


[View source]
def splitAsArgs(text : String) : Array(String) #

Splits text at each space, taking into account quoted strings. This is similar to how most (all?) shells split a command line into individual arguments.

For example, calling #splitAsArgs(%{This "is a test" string}) would produce an array with these elements:

  1. This
  2. "is a test"
  3. string

[View source]
def trimNulls(str : String, fromFirst = true) : String #

Trims a null-padded string.

If fromFirst is false, this removes all trailing null characters from a string. If fromFirst is true, all characters (null or not) are removed starting from the first null character found.


[View source]
def writePaddedString(str : String, dest : IO, length : Int) #

Writes str to dest. If the length of str is less than minLength, then additional null bytes are written to dest until the length is equal to minLength.


[View source]