bc.string.format

@nogc formatting utilities

Inspired by: https://github.com/weka-io/mecca/blob/master/src/mecca/lib/string.d

Sink Types: various functions in this module use "sinks" which are buffers or objects that get filled with the formatting data while the format functions are running. The following sink types are supported to be passed into these arguments: - Arrays (isArray!S && is(ForeachType!S : char))) - NullSink - Object with put(const(char)[]) and put(char) functions

Passing in arrays will make the sink @nogc pure nothrow @safe as everything will be written into that memory. Passing in arrays that are too short to hold all the data will trigger a RangeError or terminate the program in betterC.

Passing in a NullSink instance will not allocate any memory and just count the bytes that will be allocated.

Otherwise any type that contains a put method that can be called both with const(char)[] and with char arguments can be used.

Members

Aliases

Upper
alias Upper = Flag!"Upper"
Undocumented in source.

Functions

enumToStr
string enumToStr(E value)

Returns string of enum member value

formatDecimal
size_t formatDecimal(S sink, T val)
Undocumented in source. Be warned that the author may not have intended to support it.
formatDuration
size_t formatDuration(S sink, Duration val)

Formats duration. It uses custom formatter that is inspired by std.format output, but a bit shorter. Note: ISO 8601 was considered, but it's not as human readable as used format.

formatFloat
size_t formatFloat(S sink, double val)
Undocumented in source. Be warned that the author may not have intended to support it.
formatHex
size_t formatHex(S sink, ulong val)
Undocumented in source. Be warned that the author may not have intended to support it.
formatPtr
size_t formatPtr(S sink, ulong p)
Undocumented in source. Be warned that the author may not have intended to support it.
formatPtr
size_t formatPtr(S sink, void* ptr)
Undocumented in source. Be warned that the author may not have intended to support it.
formatSpec
auto formatSpec(FMT f, string spec)
Undocumented in source. Be warned that the author may not have intended to support it.
formatSysTime
size_t formatSysTime(S sink, SysTime val)

Formats SysTime as ISO extended string. Only UTC format supported.

formatUUID
size_t formatUUID(S sink, UUID val)
Undocumented in source. Be warned that the author may not have intended to support it.
getFormatSize
size_t getFormatSize(ARGS args)

Gets size needed to hold formatted string result

nogcFormat
const(char)[] nogcFormat(ARGS args)

Same as nogcFormatTo, but it internally uses static malloc buffer to write formatted string to. So be careful that next call replaces internal buffer data and previous result isn't valid anymore.

nogcFormatTo
size_t nogcFormatTo(S sink, ARGS args)

Formats values to with fmt template into provided sink. Note: it supports only a basic subset of format type specifiers, main usage is for nogc logging and error messages formatting. But more cases can be added as needed.

toChar
Char toChar(size_t i)
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

NullSink
struct NullSink

pseudosink used just for calculation of resulting string length

Templates

splitFmt
template splitFmt(string fmt)

Splits format string based on the same rules as described here: https://dlang.org/phobos/std_format.html In addition it supports 'p' as a pointer format specifier to be more compatible with printf. It supports nested arrays format specifier too.

Meta