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/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
-
.log : Logger
An instance of a
Logger
, provided for convenience. -
.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
-
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 = ' ')
Prints
text
tostr
, wrapping the text as it goes. -
#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. -
#padString(str : String, minLength : Int) : String
Returns a new
String
that containsstr
. -
#splitAsArgs(text : String) : Array(String)
Splits
text
at each space, taking into account quoted strings. -
#trimNulls(str : String, fromFirst = true) : String
Trims a null-padded string.
-
#writePaddedString(str : String, dest : IO, length : Int)
Writes
str
todest
.
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 "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
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 indentChar
s 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 indentChar
s 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.
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
.
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
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
.