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/mmappedfile.cr
remilib/strenum.cr
remilib/strings.cr

Constant Summary

PRETTY_SIZE_SUFFIXES_SHORT = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"]
VERSION = "0.92.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.log=(newLogger : Logger) : Nil #

[View source]
def self.mkdtemp(prefix : String = "") : String #

Creates a temporary directory using .mkdtemp() from C's standard lib. The directory is created with its permissions set to 0700. On failure, this will raise a MkdtempError exception.


[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 assert(expr) #

Unless -Dremilib_no_assertions is passed to the compiler, this evalutes expr. If it evalutes to true, then an AssertionError is raised, otherwise this does nothing.

If -Dremilib_no_assertions is NOT passed to the compiler, then this is effectively a no-op.


[View source]
macro assert(msg, expr) #

Unless -Dremilib_no_assertions is passed to the compiler, this evalutes expr. If it evalutes to true, then an AssertionError is raised with msg as a custom error message, otherwise this does nothing.

If -Dremilib_no_assertions is NOT passed to the compiler, then this is effectively a no-op.


[View source]
macro classSetonce!(*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]
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 = ' ') : Nil #

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 buildWrapped(text : String, *, indent : Int = 0, maxWidth : Int = 80, firstLineOffset : Int = 0, indentChar : Char = ' ') : String #

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

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.

DEPRECATED Use #buildWrapped without an IO


[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 sanitize(str : String, leaveExtras : Bool = false) : String #

Sanitizes str so that it's somewhat safer to print into a terminal. This essentially strips out meta characters (ESC, SUB, BEL, etc.), replacing them with textual representations.

If leaveExtras is true, then this will NOT remove additional characters such as Carriage Return and Line Feed.


[View source]
def splitAsArgs(text : String, *, removeQuotes : Bool = false) : 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

If removeQuotes is true, then the outer quotes are removed from all returned strings.


[View source]
def trimNulls(str : String, fromFirst : Bool = 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) : Nil #

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]