joka.types

The types module provides basic type definitions, compile-time functions and ASCII string helpers.

Types 38

aliasAliasArgs(A...) = A

The type of compile time alias arguments.

aliasSz = size_t

The result of sizeof.

aliasPd = ptrdiff_t

The result of pointer math.

aliasStr = char[]

A string slice of chars.

aliasStr16 = wchar[]

A string slice of wchars.

aliasStr32 = dchar[]

A string slice of dchars.

aliasIStr = const(char)[]

A string slice of constant chars.

aliasIStr16 = const(wchar)[]

A string slice of constant wchars.

aliasIStr32 = const(dchar)[]

A string slice of constant dchars.

aliasStrz = char *

A C string of chars.

aliasStrz16 = wchar *

A C string of wchars.

aliasStrz32 = dchar *

A C string of dchars.

aliasIStrz = const(char) *

A C string of constant chars.

aliasIStrz16 = const(wchar) *

A C string of constant wchars.

aliasIStrz32 = const(dchar) *

A C string of constant dchars.

aliasUnionType = ubyte

The common union type of a tagged union.

aliasGen = uint

The type of a generation.

enumFault : ubyte

A type representing error values.

noneNot an error.
someA generic error.
bugAn implementation error.
invalidAn invalid data error.
overflowAn overflow error.
rangeA range violation error.
assertionAn assertion error.
unconfiguredA missing configuration error.
unauthorizedA permission or access rights error.
unrecognizedAn unknown or unsupported type error.
cannotFindA wrong path error.
cannotCreateA creation permissions error.
cannotDestroyA destruction permissions error.
cannotOpenAn open permissions error.
cannotCloseA close permissions error.
cannotReadA read permissions error.
cannotWriteA write permissions error.
structNoData

A marker for types that support "no data" things. The Rust Result type is a good example of working with types like this.

structStaticArray(T, Sz N)

A static array. It exists because of BetterC + struct[N].

Fields
ubyte[T.sizeof * N] data
N lengthThe length of the array.
N capacityThe capacity of the array.
Methods
inout(T)[] items() inoutReturns the items of the array.
Constructors
this(const(T)[] items...)
structIndexedValue(V)

A value paired with its iteration index.

Fields
V value
Sz index
structGenIndex

A generational index.

Fields
Sz value
Gen generation
Gen.max invalidDataData indicating an error.
GenIndex(invalidData, invalidData) invalidIndexAn invalid generational index.
Methods
bool isNone()Returns true if the index is invalid.
bool isSome()Returns true if the index is valid.
structForeignSlice(T)

A slice using a foreign memory layout. It can be used to interface with languages that define slices differently.

Fields
T * ptr
Sz length
Methods
void opAssign(T[] slice)Copies the given D slice.
inout(T)[] items() inoutReturns the items of the slice.
Constructors
this(T * ptr, Sz length)Creates a slice from parts.
this(T[] slice)Copies the given D slice.
structGBitSet(T) if (__traits(isUnsigned, T))

A static bit set.

Fields
T bits
cast(T) 0 zeroTyped zero constant.
cast(T) 1 oneTyped one constant.
cast(Sz) (bits.sizeof * 8) capacityThe capacity of the bit set.
Methods
Sz length()Returns the number of set bits.
auto activeBits()Returns a range over the indices of all set bits.
int findLowestActiveBit()Returns the index of the lowest active bit, or -1 if no bits are set.
int findHighestActiveBit()Returns the index of the highest active bit, or -1 if no bits are set.
bool any()Returns true if any bit is set.
bool none()Returns true if no bit is set.
bool all()Returns true if all bits are set.
void flip(Sz i)Flips the bit at the given index.
void fill()Sets all bits.
void clear()Clears all bits.
bool opIndex(Sz i)Returns the value of a bit.
void opIndexAssign(const(bool) rhs, Sz i)Sets the value of a bit.

The common bit set data type.

The common bit set type.

structMaybe(T)

Represents an optional value with an error code. Errors are referred to as faults in Joka. The default value is an empty value.

Fields
Fault fault
T data
Methods
void opAssign(in const(T) rhs) @trustedCreates a value.
void opAssign(Fault rhs)Creates a fault.
void opAssign(in Maybe!T rhs) @trustedCopies the state of another optional value.
T xx()Returns the value without checking if it exists.
T get(ref Fault trap)Returns the value and traps the fault check to avoid an assert.
T get()Returns the value, or asserts if a fault exists.
T getOr(T other)Returns the value. Returns a default value when there is a fault.
T getOr()Returns the value. Returns a default value when there is a fault.
bool isNone() constReturns true when there is a fault.
bool isSome() constReturns true when there is a value.
void clear()Clears the value, making it none.
Constructors
this(in const(T) data)Creates a value.
this(Fault fault)Creates a fault.
this(in const(T) data, Fault fault)Creates a value if fault is none.

Maybe not.

aliasNotSure = Maybe

Not sure.

structOption(T)

Represents an optional value. Prefer using Maybe in most cases.

Note

the isSome member depends on T.

If T is a value, then isSome is a field. If T is a pointer, then isSome is a property. The default value is an empty value.

Fields
is(T : const(void) *) isPtrTrue if `T` is a pointer.
T data
Methods
void opAssign(in const(T) rhs)Creates a value.
void opAssign(in Option!T rhs)Copies the state of another optional value.
T xx()Returns the value without checking if it exists.
T get(ref bool trap)Returns the value and traps the `isSome` check to avoid an assert.
T get()Returns the value, or asserts if it does not exists.
T getOr(T other)Returns the value. Returns a default value when there is none.
T getOr()Returns the value. Returns a default value when there is none.
bool isNone() constReturns true when there is no value.
bool isSome() constReturns true when there is a value.
void clear()Clears the value, making it none.
Constructors
this(in const(T) data)Creates a value.
structResult(T, E, Sz tagSize = 0)

Represents a success or error value. Prefer using Maybe in most cases.

Fields
Tag isSome
ResultUnion data
Methods
void opAssign(in const(T) rhs)
void opAssign(in const(E) rhs)
void opAssign(in Result!(T, E) rhs)
T xx()Returns the value without checking if it exists.
T get(ref E trap)Returns the value and traps the `isSome` check to avoid an assert.
T get()Returns the value, or asserts if it does not exists.
T getOr(T other)Returns the value. Returns a default value when there is none.
T getOr()Returns the value. Returns a default value when there is none.
bool isNone() const
void clear()
Constructors
this(in const(T) value)
this(in const(E) value)
structUnion(A...) if (A.length != 0)

A tagged union.

Fields
UnionType _type
UnionData _data
/* computed */ isBaseAliasingSafeReturns true if all union members share a common first field.
Methods
@trusted auto call(IStr func, AA...)(AA args)Calls the given method for the currently active type. All types must implement this method.
UnionType type()The currently active type.
bool isType(T)()Returns true if the given type is the same as the currently active type.
Base base() refReturns the data of the first union member. Only safe to use if all union members share a common first field.
T as(T)() refReturns the data of the given type. Will assert if the type is not the same as the currently active type.
Nested Templates
typeOf(T)Returns the type of the given type.
aliastoForeign = toForeignMaybe
aliastoForeign = toForeignSlice

Path separator style.

nativeThe platform's default separator.
posixThe `/` separator.
windowsThe `\` separator.
structSep

A separator marker for printing.

Fields
IStr value
structStrPair

A string pair.

Fields
structFloating

A wrapper type for priting floats and doubles.

Fields
double value
uint precision
Methods
IStr toStr()Returns a temporary string representation.

Functions 100

fnIStr typeName(U)(in const(U) unionValue) if (is(U : Union!A, A...))Returns the current type name of the union.
fnT toUnion(T)(UnionType type) if (is(T : Union!A, A...))Returns a union from a union type.
fnT toUnion(T)(IStr typeName) if (is(T : Union!A, A...))Returns a union from a union type name.
fnOption!T toForeignMaybe(T)(Maybe!T value)Returns an option from a maybe.
fnForeignSlice!T toForeignSlice(T)(T[] value)Returns an foreign slice from a D slice.
fnForeignSlice!(const(ubyte)) toForeignBytes(const(char)[] value) @trustedReturns an foreign slice from a D slice.
fnForeignSlice!(ubyte) toForeignBytesMut(char[] value) @trustedReturns an foreign slice from a D slice.
fnbool isNan(float x)Returns true is value is NaN.
fnbool isNan(double x)Returns true is value is NaN.
fnIStr indexErrorMessage(Sz i) @trusted nothrow @nogcReturns an error message that can be used for array-like objects.
fnint findInAliasArgs(T, A...)()Returns the index of an item inside the given alias arguments or -1 on error.
fnbool isInAliasArgs(T, A...)()Returns true if an item is inside the given alias arguments.
fnIStr toStr(T)(T value) @trustedConverts the value to its string representation.
fnIStr fmtIntoBufferWithStrs(Str buffer, IStr fmtStr, IStr[] args...) @trusted nothrow @nogcFormats the given string by replacing `{}` placeholders with argument values in order. Options within placeholders are not supported. For custom formatting use a wrapper type with a `toStr` method....
fnIStr fmtIntoBuffer(A...)(Str buffer, IStr fmtStr, A args) @trustedFormats the given string by replacing `{}` placeholders with argument values in order. Options within placeholders are not supported. For custom formatting use a wrapper type with a `toStr` method....
fnIStr fmtIntoBuffer(A...)(Str buffer, InterpolationHeader header, A args, InterpolationFooter footer)
fnIStr fmt(A...)(IStr fmtStr, A args) @trustedFormats into an internal static ring buffer and returns the slice. The slice is temporary and may be overwritten by later calls to `fmt`. For details on formatting, see the `fmtIntoBuffer` function.
fnIStr fmt(A...)(InterpolationHeader header, A args, InterpolationFooter footer)
fnIStr fmtSignedGroup(IStr[] fmtStrs, long[] args...)Formats into an internal static ring buffer and returns the slice. This function can be used for types that create a lot of template bloat. Example: GVec2, GVec3, GVec4, GRect, ...
fnIStr fmtFloatingGroup(IStr[] fmtStrs, double[] args...)Formats into an internal static ring buffer and returns the slice. This function can be used for types that create a lot of template bloat. Example: GVec2, GVec3, GVec4, GRect, ...
fnnoreturn todo(IStr text, IStr file = __FILE__, Sz line = __LINE__)Halts the program with a TODO message indicating unimplemented code.
fnuint hashFnv32a(IStr text)Hashes a string using the FNV-1a algorithm with a 32-bit output.
fnulong hashFnv64a(IStr text)Hashes a string using the FNV-1a algorithm with a 64-bit output.
fnFloating flo(double value, uint precision)Wraps a floating value with formatting options.
fnbool isDigit(char c)Returns true if the character is a digit (0-9).
fnbool isUpper(char c)Returns true if the character is an uppercase letter (A-Z).
fnbool isLower(char c)Returns true the character is a lowercase letter (a-z).
fnbool isAlpha(char c)Returns true if the character is an alphabetic letter (A-Z, a-z).
fnbool isAlphaOrDigit(char c)Returns true if the character is an alphabetic letter (A-Z, a-z) or a digit (0-9).
fnbool isSpace(char c)Returns true if the character is a whitespace character (space, tab, ...).
fnbool isSymbol(char c)Returns true if the character is a symbol (!, ", ...).
fnbool isHexDigit(char c)Returns true if the character is a hexadecimal digit (0-9, A-F, a-f).
fnbool isVariableNameStart(char c)Returns true if the character can start a variable name (letter or underscore).
fnbool isVariableNamePart(char c)Returns true if the character can appear in a variable name (letter, digit, or underscore).
fnbool isVariableName(IStr str)Returns true if the string is a valid variable name (starts with a letter or underscore, followed by letters, digits, or underscores).
fnbool isStrz(IStr str)Returns true if the string represents a C string.
fnchar toUpper(char c)Converts the character to uppercase if it is a lowercase letter.
fnchar toLower(char c)Converts the character to lowercase if it is an uppercase letter.
fnStr toUpper(Str str)Converts all lowercase letters in the string to uppercase.
fnStr toLower(Str str)Converts all uppercase letters in the string to lowercase.
fnSz strzLength(IStrz str) @trustedReturns the length of the C string.
fnbool equalsNoCase(IStr str, IStr other)Returns true if the two strings are equal, ignoring case.
fnbool equalsNoCase(IStr str, char other)Returns true if the string is equal to the specified character, ignoring case.
fnbool startsWith(IStr str, IStr start)Returns true if the string starts with the specified substring.
fnbool startsWith(IStr str, char start)Returns true if the string starts with the specified character.
fnbool endsWith(IStr str, IStr end)Returns true if the string ends with the specified substring.
fnbool endsWith(IStr str, char end)Returns true if the string ends with the specified character.
fnint countItem(IStr str, IStr item)Counts the number of occurrences of the specified substring in the string.
fnint countItem(IStr str, char item)Counts the number of occurrences of the specified character in the string.
fnint findStart(IStr str, IStr item)Finds the starting index of the first occurrence of the specified substring in the string, or returns -1 if not found.
fnint findStart(IStr str, char item)Finds the starting index of the first occurrence of the specified character in the string, or returns -1 if not found.
fnint findEnd(IStr str, IStr item)Finds the ending index of the first occurrence of the specified substring in the string, or returns -1 if not found.
fnint findEnd(IStr str, char item)Finds the ending index of the first occurrence of the specified character in the string, or returns -1 if not found.
fnint findItem(IStr[] items, IStr item)Finds the first occurrence of the specified item in the slice, or returns -1 if not found.
fnint findItemThatStartsWith(IStr[] items, IStr start)Finds the first occurrence of the specified start in the slice, or returns -1 if not found.
fnint findItemThatEndsWith(IStr[] items, IStr end)Finds the first occurrence of the specified end in the slice, or returns -1 if not found.
fnIStr trimStart(IStr str)Removes whitespace characters from the beginning of the string.
fnIStr trimEnd(IStr str)Removes whitespace characters from the end of the string.
fnIStr trim(IStr str)Removes whitespace characters from both the beginning and end of the string.
fnIStr removePrefix(IStr str, IStr prefix)Removes the specified prefix from the beginning of the string if it exists.
fnIStr removeSuffix(IStr str, IStr suffix)Removes the specified suffix from the end of the string if it exists.
fnIStr advanceStr(IStr str, Sz amount)Advances the string by the specified number of characters.
fnFault copyChars(Str str, IStr source, Sz startIndex = 0) @trustedCopies characters from the source string to the destination string starting at the specified index.
fnFault copyStr(ref Str str, IStr source, Sz startIndex = 0)Copies characters from the source string to the destination string starting at the specified index and adjusts the length of the destination string.
fnIStr concatIntoBuffer(Str buffer, IStr[] args...)Concatenates the strings. Writes into the buffer and returns the result.
fnIStr concat(IStr[] args...)Concatenates the strings using a static buffer and returns the result.
fnIStr[] split(IStr str, IStr sep) @trustedSplits the string using a static buffer and returns the result.
fnIStr[] split(IStr str, char sep)Splits the string using a static buffer and returns the result.
fnbool isAbsolutePath(IStr path, PathSepStyle style = PathSepStyle.native)Returns true if the given path is absolute.
fnStrPair pathSepStrPair(PathSepStyle style)Returns the main and alternate separators for the given style.
fnIStr pathDirName(IStr path, PathSepStyle style = PathSepStyle.native)Returns the directory of the path, or "." if there is no directory.
fnIStr pathExtName(IStr path)Returns the extension of the path.
fnIStr pathBaseName(IStr path, PathSepStyle style = PathSepStyle.native)Returns the base name of the path.
fnIStr pathBaseNameNoExt(IStr path)Returns the base name of the path without the extension.
fnIStr pathTrimStart(IStr path, PathSepStyle style = PathSepStyle.native)Removes path separators from the beginning of the path.
fnIStr pathTrimEnd(IStr path, PathSepStyle style = PathSepStyle.native)Removes path separators from the end of the path.
fnIStr pathTrim(IStr path)Removes path separators from the beginning and end of the path.
fnIStr pathFmt(IStr path, PathSepStyle style = PathSepStyle.native)Formats the path to a standard form, normalizing separators.
fnIStr pathConcat(IStr[] args...)Concatenates the paths, ensuring proper path separators between them.
fnIStr pathConcat(PathSepStyle style, IStr[] args...)Concatenates the paths, ensuring proper path separators between them.
fnIStr[] pathSplit(IStr str, PathSepStyle style = PathSepStyle.native) @trustedSplits the path using a static buffer and returns the result.
fnIStr skipValue(ref inout(char)[] str, IStr sep)Skips over the next occurrence of the specified separator in the string, returning the substring before the separator and updating the input string to start after the separator.
fnIStr skipValue(ref inout(char)[] str, char sep)Skips over the next occurrence of the specified separator in the string, returning the substring before the separator and updating the input string to start after the separator.
fnIStr skipLine(ref inout(char)[] str)Skips over the next line in the string, returning the substring before the line break and updating the input string to start after the line break.
fnIStr boolToStr(bool value, bool isShortName = false, bool isLower = false)Converts the boolean value to its string representation.
fnIStr charToStr(char value)Converts the character to its string representation.
fnIStr unsignedToStr(ulong value)Converts the unsigned long value to its string representation.
fnIStr signedToStr(long value)Converts the signed long value to its string representation.
fnIStr floatingToStr(double value, uint precision = 2)Converts the double value to its string representation with the specified precision.
fnIStr strzToStr(IStrz value) @trustedConverts the C string to a string.
fnIStr enumToStr(T)(T value)Converts the enum value to its string representation.
fnMaybe!bool toBool(IStr str, bool isFullNameOnly = false, bool isUpperOnly = false)Converts the string to a bool.
fnMaybe!ulong toUnsigned(IStr str)Converts the string to a ulong.
fnMaybe!ulong toUnsigned(char c)Converts the character to a ulong.
fnMaybe!long toSigned(IStr str)Converts the string to a long.
fnMaybe!long toSigned(char c)Converts the character to a long.
fnMaybe!double toFloating(IStr str)Converts the string to a double.
fnMaybe!double toFloating(char c)Converts the character to a double.
fnMaybe!T toEnum(T, bool noCase = false, bool canIgnoreSpaceAndSymbol = false)(IStr str) if (is(T == enum)) @trustedConverts the string to an enum value.
fnMaybe!IStrz toStrz(IStr str) @trustedConverts the string to a C string.

Variables 20

enumvarkilobyte = 1024

The size of one kilobyte in bytes.

enumvarmegabyte = 1024 * kilobyte

The size of one megabyte in bytes.

enumvargigabyte = 1024 * megabyte

The size of one gigabyte in bytes.

enumvarterabyte = 1024 * gigabyte

The size of one terabyte in bytes.

enumvarpetabyte = 1024 * terabyte

The size of one petabyte in bytes.

enumvarexabyte = 1024 * petabyte

The size of one exabyte in bytes.

enumvardefaultAsciiFmtArgStr = "{}"

The format argument symbol.

enumvardigitChars = "0123456789"

The set of decimal numeric characters.

enumvarupperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

The set of uppercase letters.

enumvarlowerChars = "abcdefghijklmnopqrstuvwxyz"

The set of lowercase letters.

enumvaralphaChars = upperChars ~ lowerChars

The set of letters.

enumvarspaceChars = " \t\v\r\n\f"

The set of whitespace characters.

enumvarsymbolChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"

The set of symbol characters.

enumvarhexDigitChars = "0123456789abcdefABCDEF"

The set of hexadecimal numeric characters.

enumvarsp = Sep(" ")

Space separator.

enumvarcm = Sep(", ")

Comma + space separator.

varchar[defaultAsciiFmtArgBufferSize][defaultAsciiFmtArgBufferCount] _fmtIntoBufferDataBuffer
varIStr[defaultAsciiFmtArgBufferCount] _fmtIntoBufferSliceBuffer
varchar[defaultAsciiFmtBufferSize][defaultAsciiFmtBufferCount] _fmtBuffer
varbyte _fmtBufferIndex

Templates 2

tmplisInterLitType(TT)
tmplisInterExpType(TT)