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.crremilib/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
-
.log : Logger
An instance of a
Logger
, provided for convenience. - .log=(newLogger : Logger) : Nil
-
.mkdtemp(prefix : String = "") : String
Creates a temporary directory using
.mkdtemp()
from C's standard lib. -
.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 withindisplacedTo
.
Macro Summary
-
assert(expr)
Unless
-Dremilib_no_assertions
is passed to the compiler, this evalutesexpr
. -
assert(msg, expr)
Unless
-Dremilib_no_assertions
is passed to the compiler, this evalutesexpr
. -
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
. -
defineStringEnum(name, *values)
Defines an
Enum
that that allows you to map keys to specific strings. -
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
.
Instance Method Summary
-
#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.
- #buildWrapped(text : String, *, indent : Int = 0, maxWidth : Int = 80, firstLineOffset : Int = 0, indentChar : Char = ' ') : String
-
#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.
DEPRECATED Use #buildWrapped without an IO
-
#padString(str : String, minLength : Int) : String
Returns a new
String
that contains str. -
#sanitize(str : String, leaveExtras : Bool = false) : String
Sanitizes str so that it's somewhat safer to print into a terminal.
-
#splitAsArgs(text : String, *, removeQuotes : Bool = false) : Array(String)
Splits
text
at each space, taking into account quoted strings. -
#trimNulls(str : String, fromFirst : Bool = true) : String
Trims a null-padded string.
-
#writePaddedString(str : String, dest : IO, length : Int) : Nil
Writes str to dest.
Class Method Detail
An instance of a Logger
, provided for convenience. You may use your own
instance if you wish, or this one.
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.
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
Macro Detail
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.
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.
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
.
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.
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
.
Instance Method Detail
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.
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
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.
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.
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:
- This
- "is a test"
- string
If removeQuotes is true
, then the outer quotes are removed from all
returned strings.
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.
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.