#!/usr/bin/env dub
/+ dub.sdl:
name "autological_elf_note_buildid"
targetPath "build"
platforms "linux"
lflags "--build-id"
dflags "-preview=in" "-preview=dip1000"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
+/
/**
* Reflexivity with no query engine: a program reading its own provenance out of
* its own image.
*
* This is the weakest interesting point on the reflexivity axis, and it is worth
* having precisely because it is *already deployed everywhere*. Every ELF
* toolchain on Linux emits a `PT_NOTE` segment; `ld --build-id` puts a hash of
* the linked image in an `NT_GNU_BUILD_ID` note inside it; and `debuginfod`
* turns that hash into a network-resolvable key for the separated debug info.
* The artifact carries a stable name for itself, and nothing had to change
* about the format for that to be true.
*
* The program opens `/proc/self/exe` — its own bytes, as the running kernel
* resolved them — walks the program headers to every `PT_NOTE` segment, and
* decodes each note: `n_namesz`, `n_descsz`, `n_type`, then the 4-byte-aligned
* name and descriptor. It reports the build-id, the ABI-tag note (which encodes
* the minimum kernel version the image was linked for), and any vendor notes it
* finds, such as Fedora's `.note.package` JSON.
*
* The catalog's point: this is a **stream-scanned, out-of-band-resolved** index.
* Notes are found by walking a table, the payload they name lives somewhere else
* entirely, and the toolchain maintains the correspondence by convention. That
* is the arrangement thesis 2 says formats without self-description accrete —
* and comparing the code below with a `SELECT` against a `notes` table is the
* cheapest possible statement of what a schema would buy.
*
* Note also which path is being read: under `binfmt_misc`, `/proc/self/exe`
* names the *interpreter*, not the file that was executed. That is the exact
* problem `binfmt-magic-match.d` documents and SELF has to work around.
*
* Companions:
* docs/research/autological-artifacts/embedded-provenance.md
* docs/research/autological-artifacts/debug-info-and-indexes.md
* docs/research/autological-artifacts/binfmt-misc.md
*
* Run with: `dub run --single elf-note-buildid.d [FILE]`
*
* The recipe passes `lflags "--build-id"` deliberately: a build-id is a *link
* option*, not a property of the format, and a toolchain that does not ask for
* one produces an image that cannot name itself. That opt-in is itself the
* evidence — self-description here is a convention the toolchain may decline.
*
* Portability: Linux + ELF only (`platforms "linux"` in the recipe). If the
* image carries no notes — a stripped or `--build-id=none` link — the program
* prints a `SKIP:` line and exits 0 rather than failing.
*/
module (module) autological_elf_note_buildidReflexivity with no query engine: a program reading its own provenance out of
its own image.
This is the weakest interesting point on the reflexivity axis, and it is worth
having precisely because it is already deployed everywhere. Every ELF
toolchain on Linux emits a PT_NOTE segment; ld --build-id puts a hash of
the linked image in an NT_GNU_BUILD_ID note inside it; and debuginfod
turns that hash into a network-resolvable key for the separated debug info.
The artifact carries a stable name for itself, and nothing had to change
about the format for that to be true.
The program opens /proc/self/exe — its own bytes, as the running kernel
resolved them — walks the program headers to every PT_NOTE segment, and
decodes each note: n_namesz, n_descsz, n_type, then the 4-byte-aligned
name and descriptor. It reports the build-id, the ABI-tag note (which encodes
the minimum kernel version the image was linked for), and any vendor notes it
finds, such as Fedora's .note.package JSON.
The catalog's point: this is a stream-scanned, out-of-band-resolved index.
Notes are found by walking a table, the payload they name lives somewhere else
entirely, and the toolchain maintains the correspondence by convention. That
is the arrangement thesis 2 says formats without self-description accrete —
and comparing the code below with a SELECT against a notes table is the
cheapest possible statement of what a schema would buy.
Note also which path is being read: under binfmt_misc, /proc/self/exe
names the interpreter, not the file that was executed. That is the exact
problem binfmt-magic-match.d documents and SELF has to work around.
Companions
docs/research/autological-artifacts/embedded-provenance.md
docs/research/autological-artifacts/debug-info-and-indexes.md
docs/research/autological-artifacts/binfmt-misc.md
Run with: dub run --single elf-note-buildid.d [FILE]
The recipe passes lflags "--build-id" deliberately: a build-id is a link
option, not a property of the format, and a toolchain that does not ask for
one produces an image that cannot name itself. That opt-in is itself the
evidence — self-description here is a convention the toolchain may decline.
Portability
Linux + ELF only (platforms "linux" in the recipe). If the
image carries no notes — a stripped or --build-id=none link — the program
prints a SKIP: line and exits 0 rather than failing.
autological_elf_note_buildid;
import (package) stdstd.(module) std.algorithmThis package implements generic algorithms oriented towards the processing of
sequences. Sequences processed by these functions define range-based
interfaces. See also Reference on ranges and
tutorial on ranges.
Algorithms are categorized into the following submodules:
Submodule Functions
| Searching |
all
any
balancedParens
boyerMooreFinder
canFind
commonPrefix
count
countUntil
endsWith
find
findAdjacent
findAmong
findSkip
findSplit
findSplitAfter
findSplitBefore
minCount
maxCount
minElement
maxElement
minIndex
maxIndex
minPos
maxPos
skipOver
startsWith
until
|
| Comparison |
among
castSwitch
clamp
cmp
either
equal
isPermutation
isSameLength
levenshteinDistance
levenshteinDistanceAndPath
max
min
mismatch
predSwitch
|
| Iteration |
cache
cacheBidirectional
chunkBy
cumulativeFold
each
filter
filterBidirectional
fold
group
joiner
map
mean
permutations
reduce
splitWhen
splitter
substitute
sum
uniq
|
| Sorting |
completeSort
isPartitioned
isSorted
isStrictlyMonotonic
ordered
strictlyOrdered
makeIndex
merge
multiSort
nextEvenPermutation
nextPermutation
nthPermutation
partialSort
partition
partition3
schwartzSort
sort
topN
topNCopy
topNIndex
|
| Set operations (setops) |
cartesianProduct
largestPartialIntersection
largestPartialIntersectionWeighted
multiwayMerge
multiwayUnion
setDifference
setIntersection
setSymmetricDifference
|
| Mutation |
bringToFront
copy
fill
initializeAll
move
moveAll
moveSome
moveEmplace
moveEmplaceAll
moveEmplaceSome
remove
reverse
strip
stripLeft
stripRight
swap
swapRanges
uninitializedFill
|
Many functions in this package are parameterized with a predicate.
The predicate may be any suitable callable type
(a function, a delegate, a functor, or a lambda), or a
compile-time string. The string may consist of any legal D
expression that uses the symbol a (for unary functions) or the
symbols a and b (for binary functions). These names will NOT
interfere with other homonym symbols in user code because they are
evaluated in a different context. The default for all binary
comparison predicates is "a == b" for unordered operations and
"a < b" for ordered operations.
Example
int[] a = ...;
static bool greater(int a, int b)
{
return a > b;
}
sort!greater(a); // predicate as alias
sort!((a, b) => a > b)(a); // predicate as a lambda.
sort!"a > b"(a); // predicate as string
// (no ambiguity with array name)
sort(a); // no predicate, "a < b" is implicit
Source
std/algorithm/package.d
algorithm : (alias template) autological_elf_note_buildid.filter = std.algorithm.iteration.filter(alias predicate) if (is(typeof(unaryFun!predicate)))``filter!(predicate)(range) returns a new range containing only elements x in range for
which predicate(x) returns true.
The predicate is passed to unaryFun, and can be either a string, or
any callable that can be executed via pred(element).
filter, (alias template) autological_elf_note_buildid.map = std.algorithm.iteration.map(fun...) if (fun.length >= 1)Implements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
map;
import (package) stdstd.(module) std.arrayFunctions and types that manipulate built-in arrays and associative arrays.
This module provides all kinds of functions to create, manipulate or convert arrays:
Function Name Description
| array |
Returns a copy of the input in a newly allocated dynamic array.
|
| appender |
Returns a new Appender or RefAppender initialized with a given array.
|
| assocArray |
Returns a newly allocated associative array from a range/ranges of keys and values.
|
| byPair |
Construct a range iterating over an associative array by key/value tuples.
|
| insertInPlace |
Inserts into an existing array at a given position.
|
| join |
Concatenates a range of ranges into one array.
|
| minimallyInitializedArray |
Returns a new array of type T.
|
| replace |
Returns a new array with all occurrences of a certain subrange replaced.
|
| replaceFirst |
Returns a new array with the first occurrence of a certain subrange replaced.
|
| replaceInPlace |
Replaces all occurrences of a certain subrange and puts the result into a given array.
|
| replaceInto |
Replaces all occurrences of a certain subrange and puts the result into an output range.
|
| replaceLast |
Returns a new array with the last occurrence of a certain subrange replaced.
|
| replaceSlice |
Returns a new array with a given slice replaced.
|
| replicate |
Creates a new array out of several copies of an input array or range.
|
| sameHead |
Checks if the initial segments of two arrays refer to the same
place in memory.
|
| sameTail |
Checks if the final segments of two arrays refer to the same place
in memory.
|
| split |
Eagerly split a range or string into an array.
|
| staticArray |
Creates a new static array from given data.
|
| uninitializedArray |
Returns a new array of type T without initializing its elements.
|
Source
std/array.d
array : (alias template) autological_elf_note_buildid.array = std.array.array(Range)(Range r) if (isIterable!Range && !isAutodecodableString!Range && !isInfinite!Range)Allocates an array and initializes it with copies of the elements
of range r.
Narrow strings are handled as follows:
If autodecoding is turned on (default), then they are handled as a separate overload.
If autodecoding is turned off, then this is equivalent to duplicating the array.
array;
import (package) stdstd.(module) std.asciiFunctions which operate on ASCII characters.
All of the functions in std.ascii accept Unicode characters but
effectively ignore them if they're not ASCII. All isX functions return
false for non-ASCII characters, and all toX functions do nothing
to non-ASCII characters.
For functions which operate on Unicode characters, see
std.uni.
Category Functions Validation isAlpha isAlphaNum isASCII isControl isDigit isGraphical isHexDigit isLower isOctalDigit isPrintable isPunctuation isUpper isWhite Conversions toLower toUpper Constants digits fullHexDigits hexDigits letters lowercase lowerHexDigits newline octalDigits uppercase whitespace Enums ControlChar LetterCase
References
Source
std/ascii.d
ascii : (alias) autological_elf_note_buildid.isPrintable = bool std.ascii.isPrintable(dchar c) pure nothrow @nogc @safeisPrintable;
import (package) stdstd.(module) std.convA one-stop shop for converting values from one type to another.
Category Functions Generic asOriginalType castFrom parse to toChars bitCast Strings text wtext dtext writeText writeWText writeDText hexString Numeric octal roundTo signed unsigned Exceptions ConvException ConvOverflowException
Source
std/conv.d
conv : (alias template) autological_elf_note_buildid.text = std.conv.text(T...)(T args) if (T.length > 0)Convenience functions for converting one or more arguments
of any type into text (the three character widths).
text;
import (package) stdstd.(module) std.fileUtilities for manipulating files and scanning directories. Functions
in this module handle files as a unit, e.g., read or write one file
at a time. For opening files and manipulating them via handles refer
to module std.stdio.
Category Functions General exists isDir isFile isSymlink rename thisExePath Directories chdir dirEntries getcwd mkdir mkdirRecurse rmdir rmdirRecurse tempDir Files append copy read readText remove slurp write Symlinks symlink readLink Attributes attrIsDir attrIsFile attrIsSymlink getAttributes getLinkAttributes getSize setAttributes Timestamp getTimes getTimesWin setTimes timeLastModified timeLastAccessed timeStatusChanged Other DirEntry FileException PreserveAttributes SpanMode getAvailableDiskSpace
Source
std/file.d
file : (alias template) autological_elf_note_buildid.exists = std.file.exists(R)(R name) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)Determine whether the given file (or directory) exists.
exists, (alias template) autological_elf_note_buildid.read = std.file.read(R)(R name, size_t upTo = size_t.max) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)Read entire contents of file name and returns it as an untyped
array. If the file size is larger than upTo, only upTo
bytes are read.
read;
import (package) stdstd.(module) std.stdioCategory Symbols File handles _popen File isFileHandle openNetwork stderr stdin stdout Reading chunks lines readf readfln readln Writing toFile write writef writefln writeln Misc KeepTerminator LockType StdioException
Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio
is publically imported when importing std.stdio.
There are three layers of I/O:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
stdio : (alias template) autological_elf_note_buildid.writefln = std.stdio.writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))Equivalent to writef(fmt, args, '\n').
writefln, (alias template) autological_elf_note_buildid.writeln = std.stdio.writeln(T...)(T args)Equivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
/// `p_type` values this program cares about.
enum uint (constant) uint autological_elf_note_buildid.ptNote = 4up_type values this program cares about.
ptNote = 4;
/// The note types the GNU toolchain defines under the `GNU` name.
enum uint (constant) uint autological_elf_note_buildid.ntGnuAbiTag = 1uThe note types the GNU toolchain defines under the GNU name.
ntGnuAbiTag = 1;
enum uint (constant) uint autological_elf_note_buildid.ntGnuBuildId = 3untGnuBuildId = 3;
enum uint (constant) uint autological_elf_note_buildid.ntGnuPropertyType0 = 5untGnuPropertyType0 = 5;
/// One decoded ELF note.
struct (struct) autological_elf_note_buildid.NoteOne decoded ELF note.
Note
{
(alias) object.string = stringstring (field) string autological_elf_note_buildid.Note.namename;
uint (field) uint autological_elf_note_buildid.Note.typetype;
const(ubyte)[] (field) const(ubyte)[] autological_elf_note_buildid.Note.descdesc;
(alias) object.string = stringstring (field) string autological_elf_note_buildid.Note.segmentsegment; // which PT_NOTE it came from, for reporting
}
/// Reads a little-endian unsigned integer of `T` at `offset`.
(alias) T = ulongT ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le(T)(in ubyte[] (parameter) const(ubyte[]) bb, (alias) object.size_t = ulongsize_t (parameter) ulong offsetoffset) @safe pure nothrow @nogc
in ((parameter) ulong offsetoffset + (ulong) ulongT.(constant) ulong ulong.sizeof = 8LUsizeof <= (parameter) const(ubyte[]) bb.(field) ulong const(ubyte[]).lengthlength, "read past end of image")
{
(alias) T = ulongT (local variable) ulong vv;
foreach ((local variable) ulong ii; 0 .. (ulong) ulongT.(constant) ulong ulong.sizeof = 8LUsizeof)
(local variable) ulong vv |= (ulong) ulongT((parameter) const(ubyte[]) bb[(parameter) ulong offsetoffset + (local variable) ulong ii]) << (8 * (local variable) ulong ii);
return (local variable) ulong vv;
}
/// Rounds `n` up to the next multiple of 4, as the note format requires.
(alias) object.size_t = ulongsize_t ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safeRounds n up to the next multiple of 4, as the note format requires.
align4((alias) object.size_t = ulongsize_t (parameter) ulong nn) @safe pure nothrow @nogc => ((parameter) ulong nn + 3) & ~(ulong) ulongsize_t(3);
/++
Walks every `PT_NOTE` segment and decodes the notes inside.
Only 64-bit little-endian ELF is handled; that is what the recipe's
`platforms "linux"` plus a modern toolchain produces, and widening it would add
byte-order plumbing without adding an argument.
+/
(struct) autological_elf_note_buildid.NoteOne decoded ELF note.
Note[] autological_elf_note_buildid.Note[] autological_elf_note_buildid.readNotes(in ubyte[] img) pure @safeWalks every PT_NOTE segment and decodes the notes inside.
Only 64-bit little-endian ELF is handled; that is what the recipe's
platforms "linux" plus a modern toolchain produces, and widening it would add
byte-order plumbing without adding an argument.
readNotes(in ubyte[] (parameter) const(ubyte[]) imgimg) @safe pure
{
if ((parameter) const(ubyte[]) imgimg.(field) ulong const(ubyte[]).lengthlength < 64 || (parameter) const(ubyte[]) imgimg[0 .. 4] != [0x7f, 'E', 'L', 'F'])
throw new (class) object.ExceptionThe base class of all errors that are safe to catch and handle.
In principle, only thrown objects derived from this class are safe to catch
inside a catch block. Thrown objects not derived from Exception
represent runtime errors that should not be caught, as certain runtime
guarantees may not hold, making it unsafe to continue program execution.
Examples
bool gotCaught;
try
{
throw new Exception("msg");
}
catch (Exception e)
{
gotCaught = true;
assert(e.msg == "msg");
}
assert(gotCaught);
Exception("not an ELF image");
if ((parameter) const(ubyte[]) imgimg[4] != 2 || (parameter) const(ubyte[]) imgimg[5] != 1)
throw new (class) object.ExceptionThe base class of all errors that are safe to catch and handle.
In principle, only thrown objects derived from this class are safe to catch
inside a catch block. Thrown objects not derived from Exception
represent runtime errors that should not be caught, as certain runtime
guarantees may not hold, making it unsafe to continue program execution.
Examples
bool gotCaught;
try
{
throw new Exception("msg");
}
catch (Exception e)
{
gotCaught = true;
assert(e.msg == "msg");
}
assert(gotCaught);
Exception("only 64-bit little-endian ELF is decoded here");
const (local variable) const(ulong) phoffphoff = ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!ulong((parameter) const(ubyte[]) imgimg, 0x20);
const (local variable) const(ushort) phentsizephentsize = ushort autological_elf_note_buildid.le!ushort(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!ushort((parameter) const(ubyte[]) imgimg, 0x36);
const (local variable) const(ushort) phnumphnum = ushort autological_elf_note_buildid.le!ushort(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!ushort((parameter) const(ubyte[]) imgimg, 0x38);
(struct) autological_elf_note_buildid.NoteOne decoded ELF note.
Note[] (local variable) autological_elf_note_buildid.Note[] notesnotes;
foreach ((local variable) int ii; 0 .. (local variable) const(ushort) phnumphnum)
{
const (local variable) const(ulong) phph = cast((alias) object.size_t = ulongsize_t)((local variable) const(ulong) phoffphoff + (local variable) int ii * (local variable) const(ushort) phentsizephentsize);
if (uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) imgimg, (local variable) const(ulong) phph) != (constant) uint autological_elf_note_buildid.ptNote = 4up_type values this program cares about.
ptNote)
continue;
const (local variable) const(ulong) offsetoffset = cast((alias) object.size_t = ulongsize_t) ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!ulong((parameter) const(ubyte[]) imgimg, (local variable) const(ulong) phph + 0x08);
const (local variable) const(ulong) fileszfilesz = cast((alias) object.size_t = ulongsize_t) ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!ulong((parameter) const(ubyte[]) imgimg, (local variable) const(ulong) phph + 0x20);
const (local variable) const(string) labellabel = "PT_NOTE[" ~ (local variable) int ii.string std.conv.text!int(int __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text ~ "] @0x" ~ string autological_elf_note_buildid.offsetHex(ulong v) pure @safeLowercase hex, for offsets in labels.
offsetHex((local variable) const(ulong) offsetoffset);
(alias) object.size_t = ulongsize_t (local variable) ulong cursorcursor = (local variable) const(ulong) offsetoffset;
const (local variable) const(ulong) endend = (local variable) const(ulong) offsetoffset + (local variable) const(ulong) fileszfilesz;
while ((local variable) ulong cursorcursor + 12 <= (local variable) const(ulong) endend)
{
const (local variable) const(uint) namesznamesz = uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) imgimg, (local variable) ulong cursorcursor);
const (local variable) const(uint) descszdescsz = uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) imgimg, (local variable) ulong cursorcursor + 4);
const (local variable) const(uint) typetype = uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) imgimg, (local variable) ulong cursorcursor + 8);
const (local variable) const(ulong) nameAtnameAt = (local variable) ulong cursorcursor + 12;
const (local variable) const(ulong) descAtdescAt = (local variable) const(ulong) nameAtnameAt + ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safeRounds n up to the next multiple of 4, as the note format requires.
align4((local variable) const(uint) namesznamesz);
if ((local variable) const(ulong) descAtdescAt + (local variable) const(uint) descszdescsz > (local variable) const(ulong) endend)
break;
// `n_namesz` counts the terminating NUL; drop it for display.
const (local variable) const(ubyte[]) nameBytesnameBytes = (parameter) const(ubyte[]) imgimg[(local variable) const(ulong) nameAtnameAt .. (local variable) const(ulong) nameAtnameAt + ((local variable) const(uint) namesznamesz ? (local variable) const(uint) namesznamesz - 1 : 0)];
(local variable) autological_elf_note_buildid.Note[] notesnotes ~= (struct) autological_elf_note_buildid.NoteOne decoded ELF note.
Note(cast((alias) object.string = stringstring) (local variable) const(ubyte[]) nameBytesnameBytes.immutable(ubyte)[] object.idup!(const(ubyte))(const(ubyte)[] a) pure nothrow @property @safeProvide the .idup array property, which creates an immutable duplicate.
idup, (local variable) const(uint) typetype,
(parameter) const(ubyte[]) imgimg[(local variable) const(ulong) descAtdescAt .. (local variable) const(ulong) descAtdescAt + (local variable) const(uint) descszdescsz].immutable(ubyte)[] object.idup!(const(ubyte))(const(ubyte)[] a) pure nothrow @property @safeProvide the .idup array property, which creates an immutable duplicate.
idup, (local variable) const(string) labellabel);
(local variable) ulong cursorcursor = (local variable) const(ulong) descAtdescAt + ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safeRounds n up to the next multiple of 4, as the note format requires.
align4((local variable) const(uint) descszdescsz);
}
}
return (local variable) autological_elf_note_buildid.Note[] notesnotes;
}
/// Lowercase hex, for offsets in labels.
(alias) object.string = stringstring string autological_elf_note_buildid.offsetHex(ulong v) pure @safeLowercase hex, for offsets in labels.
offsetHex((alias) object.size_t = ulongsize_t (parameter) ulong vv) @safe pure
{
import (package) stdstd.(module) std.formatThis package provides string formatting functionality using
printf style format strings.
Submodule Function Name Description package format Converts its arguments according to a format string into a string.
| package |
sformat |
Converts its arguments according to a format string into a buffer. |
| package |
FormatException |
Signals a problem while formatting. |
| write |
formattedWrite |
Converts its arguments according to a format string and writes
the result to an output range. |
| write |
formatValue |
Formats a value of any type according to a format specifier and
writes the result to an output range. |
| read |
formattedRead |
Reads an input range according to a format string and stores the read
values into its arguments. |
| read |
unformatValue |
Reads a value from the given input range and converts it according to
a format specifier. |
| spec |
FormatSpec |
A general handler for format strings. |
| spec |
singleSpec |
Helper function that returns a FormatSpec for a single format specifier. |
Limitation
This package does not support localization, but
adheres to the rounding mode of the floating point unit, if
available.
Format Strings
The functions contained in this package use format strings. A
format string describes the layout of another string for reading or
writing purposes. A format string is composed of normal text
interspersed with format specifiers. A format specifier starts
with a percentage sign '%', optionally followed by one or more
parameters and ends with a format indicator. A format
indicator may be a simple format character or a compound
indicator.
Format strings are composed according to the following grammar:
FormatString:
FormatStringItem FormatString
FormatStringItem:
Character
FormatSpecifier
FormatSpecifier:
'%' Parameters FormatIndicator
FormatIndicator:
FormatCharacter
CompoundIndicator
FormatCharacter:
see remark below
CompoundIndicator:
'(' FormatString '%)'
'(' FormatString '%|' Delimiter '%)'
Delimiter
empty
Character Delimiter
Parameters:
Position Flags Width Precision Separator
Position:
empty
Integer '$'**
*Integer* **':'** *Integer* **'$'
Integer ':' '$'**
*Flags*:
*empty*
*Flag* *Flags*
*Flag*:
**'-'**|**'+'**|**' '**|**'0'**|**'#'**|**'='**
*Width*:
*OptionalPositionalInteger*
*Precision*:
*empty*
**'.'** *OptionalPositionalInteger*
*Separator*:
*empty*
**','** *OptionalInteger*
**','** *OptionalInteger* **'?'**
*OptionalInteger*:
*empty*
*Integer*
**'*'**
*OptionalPositionalInteger*:
*OptionalInteger*
**'*'** *Integer* **'$'
Character
'%%'
AnyCharacterExceptPercent
Integer:
NonZeroDigit Digits
Digits:
empty
Digit Digits
NonZeroDigit:
'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
Digit:
'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
Note
FormatCharacter is unspecified. It can be any character
that has no other purpose in this grammar, but it is
recommended to assign (lower- and uppercase) letters.
Note
The Parameters of a CompoundIndicator are currently
limited to a '-' flag.
Format Indicator
The format indicator can either be a single character or an
expression surrounded by '%(' and '%)'. It specifies the
basic manner in which a value will be formatted and is the minimum
requirement to format a value.
The following characters can be used as format characters:
FormatCharacter Semantics 's' To be formatted in a human readable format. Can be used with all types. 'c' To be formatted as a character. 'd' To be formatted as a signed decimal integer. 'u' To be formatted as a decimal image of the underlying bit representation. 'b' To be formatted as a binary image of the underlying bit representation. 'o' To be formatted as an octal image of the underlying bit representation. 'x' / 'X' To be formatted as a hexadecimal image of the underlying bit representation. 'e' / 'E' To be formatted as a real number in decimal scientific notation. 'f' / 'F' To be formatted as a real number in decimal natural notation. 'g' / 'G' To be formatted as a real number in decimal short notation. Depending on the number, a scientific notation or a natural notation is used. 'a' / 'A' To be formatted as a real number in hexadecimal scientific notation. 'r' To be formatted as raw bytes. The output may not be printable and depends on endianness.
The compound indicator can be used to describe compound types
like arrays or structs in more detail. A compound type is enclosed
within '%(' and '%)'. The enclosed sub-format string is
applied to individual elements. The trailing portion of the
sub-format string following the specifier for the element is
interpreted as the delimiter, and is therefore omitted following the
last element. The '%|' specifier may be used to explicitly
indicate the start of the delimiter, so that the preceding portion of
the string will be included following the last element.
The format string inside of the compound indicator should
contain exactly one format specifier (two in case of associative
arrays), which specifies the formatting mode of the elements of the
compound type. This format specifier can be a compound
indicator itself.
Note
Inside a compound indicator, strings and characters are
escaped automatically. To avoid this behavior, use "%-("
instead of "%(".
Flags
There are several flags that affect the outcome of the formatting.
Flag Semantics '-' When the formatted result is shorter than the value given by the width parameter, the output is left justified. Without the '-' flag, the output remains right justified.
There are two exceptions where the '-' flag has a
different meaning: (1) with 'r' it denotes to use little
endian and (2) in case of a compound indicator it means that
no special handling of the members is applied. |
| '=' |
When the formatted result is shorter than the value
given by the width parameter, the output is centered.
If the central position is not possible it is moved slightly
to the right. In this case, if '-' flag is present in
addition to the '=' flag, it is moved slightly to the left. |
| '+' / *' '* |
Applies to numerical values. By default, positive numbers are not
formatted to include the + sign. With one of these two flags present,
positive numbers are preceded by a plus sign or a space.
When both flags are present, a plus sign is used.
In case of 'r', a big endian format is used. |
| '0' |
Is applied to numerical values that are printed right justified.
If the zero flag is present, the space left to the number is
filled with zeros instead of spaces. |
| '#' |
Denotes that an alternative output must be used. This depends on the type
to be formatted and the format character used. See the
sections below for more information. |
Width, Precision and Separator
The width parameter specifies the minimum width of the result.
The meaning of precision depends on the format indicator. For
integers it denotes the minimum number of digits printed, for
real numbers it denotes the number of fractional digits and for
strings and compound types it denotes the maximum number of elements
that are included in the output.
A separator is used for formatting numbers. If it is specified,
the output is divided into chunks of three digits, separated by a ','. The number of digits in a chunk can be given explicitly by
providing a number or a ''* after the ','.
In all three cases the number of digits can be replaced by a ''*. In this scenario, the next argument is used as the number of
digits. If the argument is a negative number, the precision and
separator parameters are considered unspecified. For width,
the absolute value is used and the '-' flag is set.
The separator can also be followed by a '?'. In that case,
an additional argument is used to specify the symbol that should be
used to separate the chunks.
Position
By default, the arguments are processed in the provided order. With
the position parameter it is possible to address arguments
directly. It is also possible to denote a series of arguments with
two numbers separated by ':', that are all processed in the same
way. The second number can be omitted. In that case the series ends
with the last argument.
It's also possible to use positional arguments for width, precision and separator by adding a number and a '$' after the ''*.
Types
This section describes the result of combining types with format
characters. It is organized in 2 subsections: a list of general
information regarding the formatting of types in the presence of
format characters and a table that contains details for every
available combination of type and format character.
When formatting types, the following rules apply:
If the format character is upper case, the resulting string will
be formatted using upper case letters.
The default precision for floating point numbers is 6 digits.
Rounding of floating point numbers adheres to the rounding mode
of the floating point unit, if available.
The floating point values NaN and Infinity are formatted as
nan and inf, possibly preceded by '+' or '-' sign.
Formatting reals is only supported for 64 bit reals and 80 bit reals.
All other reals are cast to double before they are formatted. This will
cause the result to be inf for very large numbers.
Characters and strings formatted with the 's' format character
inside of compound types are surrounded by single and double quotes
and unprintable characters are escaped. To avoid this, a '-'
flag can be specified for the compound specifier
(e.g. "%-(%s%)" instead of "%(%s%)" ).
Structs, unions, classes and interfaces are formatted by calling a
toString method if available.
See module std.format.write for more
details.
Only part of these combinations can be used for reading. See
module std.format.read for more
detailed information.
This table contains descriptions for every possible combination of
type and format character:
<th scope="col" width="20%">Type</th> <th scope="col" width="20%">Format Character</th> Formatted as... <td rowspan="1">null</td> 's' null
|<td rowspan="3">bool</td> 's' |
false or true |
| 'b', 'd', 'o', 'u', 'x', 'X' |
As the integrals 0 or 1 with the same format character.
Please note, that 'o' and 'x' with '#' flag
might produce unexpected results due to special handling of
the value 0. |
| 'r' |
\0 or \1 |
|<td rowspan="4">Integral</td> 's', 'd' |
A signed decimal number. The '#' flag is ignored. |
| 'b', 'o', 'u', 'x', 'X' |
An unsigned binary, decimal, octal or hexadecimal number.
In case of 'o' and 'x', the '#' flag
denotes that the number must be preceded by 0 and 0x, with
the exception of the value 0, where this does not apply. For
'b' and 'u' the '#' flag has no effect. |
| 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A' |
As a floating point value with the same specifier.
Default precision is large enough to add all digits
of the integral value.
In case of 'a' and 'A', the integral digit can be
any hexadecimal digit.
|
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="5">Floating Point</td> 'e', 'E' |
Scientific notation: Exactly one integral digit followed by a dot
and fractional digits, followed by the exponent.
The exponent is formatted as 'e' followed by
a '+' or '-' sign, followed by at least
two digits.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted. |
| 'f', 'F' |
Natural notation: Integral digits followed by a dot and
fractional digits.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted.
Please note: the difference between 'f' and 'F'
is only visible for NaN and Infinity. |
| 's', 'g', 'G' |
Short notation: If the absolute value is larger than 10 ^^ precision
or smaller than 0.0001, the scientific notation is used.
If not, the natural notation is applied.
In both cases precision denotes the count of all digits, including
the integral digits. Trailing zeros (including a trailing dot) are removed.
If '#' flag is present, trailing zeros are not removed. |
| 'a', 'A' |
Hexadecimal scientific notation: 0x followed by 1
(or 0 in case of value zero or denormalized number)
followed by a dot, fractional digits in hexadecimal
notation and an exponent. The exponent is build by p,
followed by a sign and the exponent in decimal notation.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted. |
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="3">Character</td> 's', 'c' |
As the character.
Inside of a compound indicator 's' is treated differently: The
character is surrounded by single quotes and non printable
characters are escaped. This can be avoided by preceding
the compound indicator with a '-' flag
(e.g. "%-(%s%)"). |
| 'b', 'd', 'o', 'u', 'x', 'X' |
As the integral that represents the character. |
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="3">String</td> 's' |
The sequence of characters that form the string.
Inside of a compound indicator the string is surrounded by double quotes
and non printable characters are escaped. This can be avoided
by preceding the compound indicator with a '-' flag
(e.g. "%-(%s%)"). |
| 'r' |
The sequence of characters, each formatted with 'r'. |
| compound |
As an array of characters. |
|<td rowspan="3">Array</td> 's' |
When the elements are characters, the array is formatted as
a string. In all other cases the array is surrounded by square brackets
and the elements are separated by a comma and a space. If the elements
are strings, they are surrounded by double quotes and non
printable characters are escaped. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="2">Associative Array</td> 's' |
As a sequence of the elements in unpredictable order. The output is
surrounded by square brackets. The elements are separated by a
comma and a space. The elements are formatted as key:value. |
| compound |
As a sequence of the elements in unpredictable order. Each element
is formatted according to the specifications given inside of the
compound specifier. The first specifier is used for formatting
the key and the second specifier is used for formatting the value.
The order can be changed with positional arguments. For example
"%(%2$s (%1$s), %)" will write the value, followed by the key in
parenthesis. |
|<td rowspan="2">Enum</td> 's' |
The name of the value. If the name is not available, the base value
is used, preceeded by a cast. |
| All, but 's' |
Enums can be formatted with all format characters that can be used
with the base value. In that case they are formatted like the base value. |
|<td rowspan="3">Input Range</td> 's' |
When the elements of the range are characters, they are written like a string.
In all other cases, the elements are enclosed by square brackets and separated
by a comma and a space. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="1">Struct</td> 's' |
When the struct has neither an applicable toString
nor is an input range, it is formatted as follows:
StructType(field1, field2, ...). |
|<td rowspan="1">Class</td> 's' |
When the class has neither an applicable toString
nor is an input range, it is formatted as the
fully qualified name of the class. |
|<td rowspan="1">Union</td> 's' |
When the union has neither an applicable toString
nor is an input range, it is formatted as its base name. |
|<td rowspan="2">Pointer</td> 's' |
A null pointer is formatted as 'null'. All other pointers are
formatted as hexadecimal numbers with the format character 'X'. |
| 'x', 'X' |
Formatted as a hexadecimal number. |
|<td rowspan="3">SIMD vector</td> 's' |
The array is surrounded by square brackets
and the elements are separated by a comma and a space. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="1">Delegate</td> 's', 'r', compound |
As the .stringof of this delegate treated as a string.
Please note: The implementation is currently buggy
and its use is discouraged. |
Source
std/format/package.d
Examples
Simple use:
// Easiest way is to use `%s` everywhere:
assert(format("I got %s %s for %s euros.", 30, "eggs", 5.27) == "I got 30 eggs for 5.27 euros.");
// Other format characters provide more control:
assert(format("I got %b %(%X%) for %f euros.", 30, "eggs", 5.27) == "I got 11110 65676773 for 5.270000 euros.");
Compound specifiers allow formatting arrays and other compound types:
/*
The trailing end of the sub-format string following the specifier for
each item is interpreted as the array delimiter, and is therefore
omitted following the last array item:
*/
assert(format("My items are %(%s %).", [1,2,3]) == "My items are 1 2 3.");
assert(format("My items are %(%s, %).", [1,2,3]) == "My items are 1, 2, 3.");
/*
The "%|" delimiter specifier may be used to indicate where the
delimiter begins, so that the portion of the format string prior to
it will be retained in the last array element:
*/
assert(format("My items are %(-%s-%|, %).", [1,2,3]) == "My items are -1-, -2-, -3-.");
/*
These compound format specifiers may be nested in the case of a
nested array argument:
*/
auto mat = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]];
assert(format("%(%(%d %) - %)", mat), "1 2 3 - 4 5 6 - 7 8 9");
assert(format("[%(%(%d %) - %)]", mat), "[1 2 3 - 4 5 6 - 7 8 9]");
assert(format("[%([%(%d %)]%| - %)]", mat), "[1 2 3] - [4 5 6] - [7 8 9]");
/*
Strings and characters are escaped automatically inside compound
format specifiers. To avoid this behavior, use "%-(" instead of "%(":
*/
assert(format("My friends are %s.", ["John", "Nancy"]) == `My friends are ["John", "Nancy"].`);
assert(format("My friends are %(%s, %).", ["John", "Nancy"]) == `My friends are "John", "Nancy".`);
assert(format("My friends are %-(%s, %).", ["John", "Nancy"]) == `My friends are John, Nancy.`);
Using parameters:
// Flags can be used to influence to outcome:
assert(format("%g != %+#g", 3.14, 3.14) == "3.14 != +3.14000");
// Width and precision help to arrange the formatted result:
assert(format(">%10.2f<", 1234.56789) == "> 1234.57<");
// Numbers can be grouped:
assert(format("%,4d", int.max) == "21,4748,3647");
// It's possible to specify the position of an argument:
assert(format("%3$s %1$s", 3, 17, 5) == "5 3");
Providing parameters as arguments:
// Width as argument
assert(format(">%*s<", 10, "abc") == "> abc<");
// Precision as argument
assert(format(">%.*f<", 5, 123.2) == ">123.20000<");
// Grouping as argument
assert(format("%,*d", 1, int.max) == "2,1,4,7,4,8,3,6,4,7");
// Grouping separator as argument
assert(format("%,3?d", '_', int.max) == "2_147_483_647");
// All at once
assert(format("%*.*,*?d", 20, 15, 6, '/', int.max) == " 000/002147/483647");
format : (alias template) format = std.format.format(Char, Args...)(in Char[] fmt, Args args) if (isSomeChar!Char)Converts its arguments according to a format string into a string.
The second version of format takes the format string as template
argument. In this case, it is checked for consistency at
compile-time and produces slightly faster code, because the length of
the output buffer can be estimated in advance.
Params:
fmt = a $(MREF_ALTTEXT format string, std,format)
args = a variadic list of arguments to be formatted
Char = character type of fmt
Args = a variadic list of types of the arguments
Returns:
The formatted string.
Throws:
A $(LREF FormatException) if formatting did not succeed.
See_Also:
$(LREF sformat) for a variant, that tries to avoid garbage collection.
format;
return string std.format.format!(char, ulong)(in char[] fmt, ulong __param_1) pure @safeConverts its arguments according to a format string into a string.
The second version of format takes the format string as template
argument. In this case, it is checked for consistency at
compile-time and produces slightly faster code, because the length of
the output buffer can be estimated in advance.
Examples
assert(format("Here are %d %s.", 3, "apples") == "Here are 3 apples.");
assert("Increase: %7.2f %%".format(17.4285) == "Increase: 17.43 %");
format("%x", (parameter) ulong vv);
}
/// Hex-encodes a descriptor, which is how a build-id is universally written.
(alias) object.string = stringstring string autological_elf_note_buildid.hex(in ubyte[] b) pure @safeHex-encodes a descriptor, which is how a build-id is universally written.
hex(in ubyte[] (parameter) const(ubyte[]) bb) @safe pure
{
import (package) stdstd.(module) std.formatThis package provides string formatting functionality using
printf style format strings.
Submodule Function Name Description package format Converts its arguments according to a format string into a string.
| package |
sformat |
Converts its arguments according to a format string into a buffer. |
| package |
FormatException |
Signals a problem while formatting. |
| write |
formattedWrite |
Converts its arguments according to a format string and writes
the result to an output range. |
| write |
formatValue |
Formats a value of any type according to a format specifier and
writes the result to an output range. |
| read |
formattedRead |
Reads an input range according to a format string and stores the read
values into its arguments. |
| read |
unformatValue |
Reads a value from the given input range and converts it according to
a format specifier. |
| spec |
FormatSpec |
A general handler for format strings. |
| spec |
singleSpec |
Helper function that returns a FormatSpec for a single format specifier. |
Limitation
This package does not support localization, but
adheres to the rounding mode of the floating point unit, if
available.
Format Strings
The functions contained in this package use format strings. A
format string describes the layout of another string for reading or
writing purposes. A format string is composed of normal text
interspersed with format specifiers. A format specifier starts
with a percentage sign '%', optionally followed by one or more
parameters and ends with a format indicator. A format
indicator may be a simple format character or a compound
indicator.
Format strings are composed according to the following grammar:
FormatString:
FormatStringItem FormatString
FormatStringItem:
Character
FormatSpecifier
FormatSpecifier:
'%' Parameters FormatIndicator
FormatIndicator:
FormatCharacter
CompoundIndicator
FormatCharacter:
see remark below
CompoundIndicator:
'(' FormatString '%)'
'(' FormatString '%|' Delimiter '%)'
Delimiter
empty
Character Delimiter
Parameters:
Position Flags Width Precision Separator
Position:
empty
Integer '$'**
*Integer* **':'** *Integer* **'$'
Integer ':' '$'**
*Flags*:
*empty*
*Flag* *Flags*
*Flag*:
**'-'**|**'+'**|**' '**|**'0'**|**'#'**|**'='**
*Width*:
*OptionalPositionalInteger*
*Precision*:
*empty*
**'.'** *OptionalPositionalInteger*
*Separator*:
*empty*
**','** *OptionalInteger*
**','** *OptionalInteger* **'?'**
*OptionalInteger*:
*empty*
*Integer*
**'*'**
*OptionalPositionalInteger*:
*OptionalInteger*
**'*'** *Integer* **'$'
Character
'%%'
AnyCharacterExceptPercent
Integer:
NonZeroDigit Digits
Digits:
empty
Digit Digits
NonZeroDigit:
'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
Digit:
'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
Note
FormatCharacter is unspecified. It can be any character
that has no other purpose in this grammar, but it is
recommended to assign (lower- and uppercase) letters.
Note
The Parameters of a CompoundIndicator are currently
limited to a '-' flag.
Format Indicator
The format indicator can either be a single character or an
expression surrounded by '%(' and '%)'. It specifies the
basic manner in which a value will be formatted and is the minimum
requirement to format a value.
The following characters can be used as format characters:
FormatCharacter Semantics 's' To be formatted in a human readable format. Can be used with all types. 'c' To be formatted as a character. 'd' To be formatted as a signed decimal integer. 'u' To be formatted as a decimal image of the underlying bit representation. 'b' To be formatted as a binary image of the underlying bit representation. 'o' To be formatted as an octal image of the underlying bit representation. 'x' / 'X' To be formatted as a hexadecimal image of the underlying bit representation. 'e' / 'E' To be formatted as a real number in decimal scientific notation. 'f' / 'F' To be formatted as a real number in decimal natural notation. 'g' / 'G' To be formatted as a real number in decimal short notation. Depending on the number, a scientific notation or a natural notation is used. 'a' / 'A' To be formatted as a real number in hexadecimal scientific notation. 'r' To be formatted as raw bytes. The output may not be printable and depends on endianness.
The compound indicator can be used to describe compound types
like arrays or structs in more detail. A compound type is enclosed
within '%(' and '%)'. The enclosed sub-format string is
applied to individual elements. The trailing portion of the
sub-format string following the specifier for the element is
interpreted as the delimiter, and is therefore omitted following the
last element. The '%|' specifier may be used to explicitly
indicate the start of the delimiter, so that the preceding portion of
the string will be included following the last element.
The format string inside of the compound indicator should
contain exactly one format specifier (two in case of associative
arrays), which specifies the formatting mode of the elements of the
compound type. This format specifier can be a compound
indicator itself.
Note
Inside a compound indicator, strings and characters are
escaped automatically. To avoid this behavior, use "%-("
instead of "%(".
Flags
There are several flags that affect the outcome of the formatting.
Flag Semantics '-' When the formatted result is shorter than the value given by the width parameter, the output is left justified. Without the '-' flag, the output remains right justified.
There are two exceptions where the '-' flag has a
different meaning: (1) with 'r' it denotes to use little
endian and (2) in case of a compound indicator it means that
no special handling of the members is applied. |
| '=' |
When the formatted result is shorter than the value
given by the width parameter, the output is centered.
If the central position is not possible it is moved slightly
to the right. In this case, if '-' flag is present in
addition to the '=' flag, it is moved slightly to the left. |
| '+' / *' '* |
Applies to numerical values. By default, positive numbers are not
formatted to include the + sign. With one of these two flags present,
positive numbers are preceded by a plus sign or a space.
When both flags are present, a plus sign is used.
In case of 'r', a big endian format is used. |
| '0' |
Is applied to numerical values that are printed right justified.
If the zero flag is present, the space left to the number is
filled with zeros instead of spaces. |
| '#' |
Denotes that an alternative output must be used. This depends on the type
to be formatted and the format character used. See the
sections below for more information. |
Width, Precision and Separator
The width parameter specifies the minimum width of the result.
The meaning of precision depends on the format indicator. For
integers it denotes the minimum number of digits printed, for
real numbers it denotes the number of fractional digits and for
strings and compound types it denotes the maximum number of elements
that are included in the output.
A separator is used for formatting numbers. If it is specified,
the output is divided into chunks of three digits, separated by a ','. The number of digits in a chunk can be given explicitly by
providing a number or a ''* after the ','.
In all three cases the number of digits can be replaced by a ''*. In this scenario, the next argument is used as the number of
digits. If the argument is a negative number, the precision and
separator parameters are considered unspecified. For width,
the absolute value is used and the '-' flag is set.
The separator can also be followed by a '?'. In that case,
an additional argument is used to specify the symbol that should be
used to separate the chunks.
Position
By default, the arguments are processed in the provided order. With
the position parameter it is possible to address arguments
directly. It is also possible to denote a series of arguments with
two numbers separated by ':', that are all processed in the same
way. The second number can be omitted. In that case the series ends
with the last argument.
It's also possible to use positional arguments for width, precision and separator by adding a number and a '$' after the ''*.
Types
This section describes the result of combining types with format
characters. It is organized in 2 subsections: a list of general
information regarding the formatting of types in the presence of
format characters and a table that contains details for every
available combination of type and format character.
When formatting types, the following rules apply:
If the format character is upper case, the resulting string will
be formatted using upper case letters.
The default precision for floating point numbers is 6 digits.
Rounding of floating point numbers adheres to the rounding mode
of the floating point unit, if available.
The floating point values NaN and Infinity are formatted as
nan and inf, possibly preceded by '+' or '-' sign.
Formatting reals is only supported for 64 bit reals and 80 bit reals.
All other reals are cast to double before they are formatted. This will
cause the result to be inf for very large numbers.
Characters and strings formatted with the 's' format character
inside of compound types are surrounded by single and double quotes
and unprintable characters are escaped. To avoid this, a '-'
flag can be specified for the compound specifier
(e.g. "%-(%s%)" instead of "%(%s%)" ).
Structs, unions, classes and interfaces are formatted by calling a
toString method if available.
See module std.format.write for more
details.
Only part of these combinations can be used for reading. See
module std.format.read for more
detailed information.
This table contains descriptions for every possible combination of
type and format character:
<th scope="col" width="20%">Type</th> <th scope="col" width="20%">Format Character</th> Formatted as... <td rowspan="1">null</td> 's' null
|<td rowspan="3">bool</td> 's' |
false or true |
| 'b', 'd', 'o', 'u', 'x', 'X' |
As the integrals 0 or 1 with the same format character.
Please note, that 'o' and 'x' with '#' flag
might produce unexpected results due to special handling of
the value 0. |
| 'r' |
\0 or \1 |
|<td rowspan="4">Integral</td> 's', 'd' |
A signed decimal number. The '#' flag is ignored. |
| 'b', 'o', 'u', 'x', 'X' |
An unsigned binary, decimal, octal or hexadecimal number.
In case of 'o' and 'x', the '#' flag
denotes that the number must be preceded by 0 and 0x, with
the exception of the value 0, where this does not apply. For
'b' and 'u' the '#' flag has no effect. |
| 'e', 'E', 'f', 'F', 'g', 'G', 'a', 'A' |
As a floating point value with the same specifier.
Default precision is large enough to add all digits
of the integral value.
In case of 'a' and 'A', the integral digit can be
any hexadecimal digit.
|
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="5">Floating Point</td> 'e', 'E' |
Scientific notation: Exactly one integral digit followed by a dot
and fractional digits, followed by the exponent.
The exponent is formatted as 'e' followed by
a '+' or '-' sign, followed by at least
two digits.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted. |
| 'f', 'F' |
Natural notation: Integral digits followed by a dot and
fractional digits.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted.
Please note: the difference between 'f' and 'F'
is only visible for NaN and Infinity. |
| 's', 'g', 'G' |
Short notation: If the absolute value is larger than 10 ^^ precision
or smaller than 0.0001, the scientific notation is used.
If not, the natural notation is applied.
In both cases precision denotes the count of all digits, including
the integral digits. Trailing zeros (including a trailing dot) are removed.
If '#' flag is present, trailing zeros are not removed. |
| 'a', 'A' |
Hexadecimal scientific notation: 0x followed by 1
(or 0 in case of value zero or denormalized number)
followed by a dot, fractional digits in hexadecimal
notation and an exponent. The exponent is build by p,
followed by a sign and the exponent in decimal notation.
When there are no fractional digits and the '#' flag
is not present, the dot is omitted. |
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="3">Character</td> 's', 'c' |
As the character.
Inside of a compound indicator 's' is treated differently: The
character is surrounded by single quotes and non printable
characters are escaped. This can be avoided by preceding
the compound indicator with a '-' flag
(e.g. "%-(%s%)"). |
| 'b', 'd', 'o', 'u', 'x', 'X' |
As the integral that represents the character. |
| 'r' |
Characters taken directly from the binary representation. |
|<td rowspan="3">String</td> 's' |
The sequence of characters that form the string.
Inside of a compound indicator the string is surrounded by double quotes
and non printable characters are escaped. This can be avoided
by preceding the compound indicator with a '-' flag
(e.g. "%-(%s%)"). |
| 'r' |
The sequence of characters, each formatted with 'r'. |
| compound |
As an array of characters. |
|<td rowspan="3">Array</td> 's' |
When the elements are characters, the array is formatted as
a string. In all other cases the array is surrounded by square brackets
and the elements are separated by a comma and a space. If the elements
are strings, they are surrounded by double quotes and non
printable characters are escaped. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="2">Associative Array</td> 's' |
As a sequence of the elements in unpredictable order. The output is
surrounded by square brackets. The elements are separated by a
comma and a space. The elements are formatted as key:value. |
| compound |
As a sequence of the elements in unpredictable order. Each element
is formatted according to the specifications given inside of the
compound specifier. The first specifier is used for formatting
the key and the second specifier is used for formatting the value.
The order can be changed with positional arguments. For example
"%(%2$s (%1$s), %)" will write the value, followed by the key in
parenthesis. |
|<td rowspan="2">Enum</td> 's' |
The name of the value. If the name is not available, the base value
is used, preceeded by a cast. |
| All, but 's' |
Enums can be formatted with all format characters that can be used
with the base value. In that case they are formatted like the base value. |
|<td rowspan="3">Input Range</td> 's' |
When the elements of the range are characters, they are written like a string.
In all other cases, the elements are enclosed by square brackets and separated
by a comma and a space. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="1">Struct</td> 's' |
When the struct has neither an applicable toString
nor is an input range, it is formatted as follows:
StructType(field1, field2, ...). |
|<td rowspan="1">Class</td> 's' |
When the class has neither an applicable toString
nor is an input range, it is formatted as the
fully qualified name of the class. |
|<td rowspan="1">Union</td> 's' |
When the union has neither an applicable toString
nor is an input range, it is formatted as its base name. |
|<td rowspan="2">Pointer</td> 's' |
A null pointer is formatted as 'null'. All other pointers are
formatted as hexadecimal numbers with the format character 'X'. |
| 'x', 'X' |
Formatted as a hexadecimal number. |
|<td rowspan="3">SIMD vector</td> 's' |
The array is surrounded by square brackets
and the elements are separated by a comma and a space. |
| 'r' |
The sequence of the elements, each formatted with 'r'. |
| compound |
The sequence of the elements, each formatted according to the specifications
given inside of the compound specifier. |
|<td rowspan="1">Delegate</td> 's', 'r', compound |
As the .stringof of this delegate treated as a string.
Please note: The implementation is currently buggy
and its use is discouraged. |
Source
std/format/package.d
Examples
Simple use:
// Easiest way is to use `%s` everywhere:
assert(format("I got %s %s for %s euros.", 30, "eggs", 5.27) == "I got 30 eggs for 5.27 euros.");
// Other format characters provide more control:
assert(format("I got %b %(%X%) for %f euros.", 30, "eggs", 5.27) == "I got 11110 65676773 for 5.270000 euros.");
Compound specifiers allow formatting arrays and other compound types:
/*
The trailing end of the sub-format string following the specifier for
each item is interpreted as the array delimiter, and is therefore
omitted following the last array item:
*/
assert(format("My items are %(%s %).", [1,2,3]) == "My items are 1 2 3.");
assert(format("My items are %(%s, %).", [1,2,3]) == "My items are 1, 2, 3.");
/*
The "%|" delimiter specifier may be used to indicate where the
delimiter begins, so that the portion of the format string prior to
it will be retained in the last array element:
*/
assert(format("My items are %(-%s-%|, %).", [1,2,3]) == "My items are -1-, -2-, -3-.");
/*
These compound format specifiers may be nested in the case of a
nested array argument:
*/
auto mat = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]];
assert(format("%(%(%d %) - %)", mat), "1 2 3 - 4 5 6 - 7 8 9");
assert(format("[%(%(%d %) - %)]", mat), "[1 2 3 - 4 5 6 - 7 8 9]");
assert(format("[%([%(%d %)]%| - %)]", mat), "[1 2 3] - [4 5 6] - [7 8 9]");
/*
Strings and characters are escaped automatically inside compound
format specifiers. To avoid this behavior, use "%-(" instead of "%(":
*/
assert(format("My friends are %s.", ["John", "Nancy"]) == `My friends are ["John", "Nancy"].`);
assert(format("My friends are %(%s, %).", ["John", "Nancy"]) == `My friends are "John", "Nancy".`);
assert(format("My friends are %-(%s, %).", ["John", "Nancy"]) == `My friends are John, Nancy.`);
Using parameters:
// Flags can be used to influence to outcome:
assert(format("%g != %+#g", 3.14, 3.14) == "3.14 != +3.14000");
// Width and precision help to arrange the formatted result:
assert(format(">%10.2f<", 1234.56789) == "> 1234.57<");
// Numbers can be grouped:
assert(format("%,4d", int.max) == "21,4748,3647");
// It's possible to specify the position of an argument:
assert(format("%3$s %1$s", 3, 17, 5) == "5 3");
Providing parameters as arguments:
// Width as argument
assert(format(">%*s<", 10, "abc") == "> abc<");
// Precision as argument
assert(format(">%.*f<", 5, 123.2) == ">123.20000<");
// Grouping as argument
assert(format("%,*d", 1, int.max) == "2,1,4,7,4,8,3,6,4,7");
// Grouping separator as argument
assert(format("%,3?d", '_', int.max) == "2_147_483_647");
// All at once
assert(format("%*.*,*?d", 20, 15, 6, '/', int.max) == " 000/002147/483647");
format : (alias template) format = std.format.format(Char, Args...)(in Char[] fmt, Args args) if (isSomeChar!Char)Converts its arguments according to a format string into a string.
The second version of format takes the format string as template
argument. In this case, it is checked for consistency at
compile-time and produces slightly faster code, because the length of
the output buffer can be estimated in advance.
Params:
fmt = a $(MREF_ALTTEXT format string, std,format)
args = a variadic list of arguments to be formatted
Char = character type of fmt
Args = a variadic list of types of the arguments
Returns:
The formatted string.
Throws:
A $(LREF FormatException) if formatting did not succeed.
See_Also:
$(LREF sformat) for a variant, that tries to avoid garbage collection.
format;
char[] (local variable) char[] ss;
foreach ((parameter) const(ubyte) xx; (parameter) const(ubyte[]) bb)
(local variable) char[] ss ~= string std.format.format!(char, const(ubyte))(in char[] fmt, const(ubyte) __param_1) pure @safeConverts its arguments according to a format string into a string.
The second version of format takes the format string as template
argument. In this case, it is checked for consistency at
compile-time and produces slightly faster code, because the length of
the output buffer can be estimated in advance.
Examples
assert(format("Here are %d %s.", 3, "apples") == "Here are 3 apples.");
assert("Increase: %7.2f %%".format(17.4285) == "Increase: 17.43 %");
format("%02x", (local variable) const(ubyte) xx);
return (local variable) char[] ss.string object.idup!char(char[] a) pure nothrow @property @safeProvide the .idup array property, which creates an immutable duplicate.
idup;
}
/// Renders a descriptor as text when it plausibly is text (Fedora's `.note.package`).
(alias) object.string = stringstring string autological_elf_note_buildid.asTextIfPrintable(in ubyte[] b) pure @safeRenders a descriptor as text when it plausibly is text (Fedora's .note.package).
asTextIfPrintable(in ubyte[] (parameter) const(ubyte[]) bb) @safe pure
{
foreach ((parameter) const(ubyte) cc; (parameter) const(ubyte[]) bb)
if ((local variable) const(ubyte) cc != 0 && !(cast(char) (local variable) const(ubyte) cc).bool std.ascii.isPrintable(dchar c) pure nothrow @nogc @safeExamples
assert( isPrintable(' ')); // whitespace is printable
assert( isPrintable('1'));
assert( isPrintable('a'));
assert( isPrintable('#'));
assert(!isPrintable('\0')); // control characters are not printable
// N.B.: Printable non-ASCII Unicode characters are not recognized.
assert(!isPrintable('á'));
isPrintable)
return null;
char[] (local variable) char[] ss;
foreach ((parameter) const(ubyte) cc; (parameter) const(ubyte[]) bb)
if ((local variable) const(ubyte) cc != 0)
(local variable) char[] ss ~= cast(char) (local variable) const(ubyte) cc;
return (local variable) char[] ss.string object.idup!char(char[] a) pure nothrow @property @safeProvide the .idup array property, which creates an immutable duplicate.
idup;
}
/// Names the well-known GNU note types.
(alias) object.string = stringstring string autological_elf_note_buildid.typeName(string owner, uint type) pure nothrow @nogc @safeNames the well-known GNU note types.
typeName((alias) object.string = stringstring (parameter) string ownerowner, uint (parameter) uint typetype) @safe pure nothrow @nogc
{
if ((parameter) string ownerowner != "GNU")
return "vendor-defined";
switch ((parameter) uint typetype)
{
case (constant) uint autological_elf_note_buildid.ntGnuAbiTag = 1uThe note types the GNU toolchain defines under the GNU name.
ntGnuAbiTag:
return "NT_GNU_ABI_TAG";
case (constant) uint autological_elf_note_buildid.ntGnuBuildId = 3untGnuBuildId:
return "NT_GNU_BUILD_ID";
case (constant) uint autological_elf_note_buildid.ntGnuPropertyType0 = 5untGnuPropertyType0:
return "NT_GNU_PROPERTY_TYPE_0";
default:
return "GNU (other)";
}
}
/// Decodes the ABI-tag descriptor: OS id plus a minimum kernel version triple.
(alias) object.string = stringstring string autological_elf_note_buildid.abiTag(in ubyte[] desc) pure @safeDecodes the ABI-tag descriptor: OS id plus a minimum kernel version triple.
abiTag(in ubyte[] (parameter) const(ubyte[]) descdesc) @safe pure
{
if ((parameter) const(ubyte[]) descdesc.(field) ulong const(ubyte[]).lengthlength < 16)
return "(malformed)";
static immutable (immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.osos = ["Linux", "GNU/Hurd", "Solaris", "FreeBSD"];
const (local variable) const(uint) idid = uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) descdesc, 0);
const (local variable) const(string) namename = (local variable) const(uint) idid < (immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.osos.(field) ulong immutable(string[]).lengthlength ? (immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.osos[(local variable) const(uint) idid] : "OS " ~ (local variable) const(uint) idid.string std.conv.text!(const(uint))(const(uint) __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text;
return (local variable) const(string) namename ~ " " ~ uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) descdesc, 4).string std.conv.text!uint(uint __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text ~ "." ~ uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) descdesc, 8).string std.conv.text!uint(uint __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text
~ "." ~ uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safeReads a little-endian unsigned integer of T at offset.
le!uint((parameter) const(ubyte[]) descdesc, 12).string std.conv.text!uint(uint __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text ~ " or later";
}
int int D main(string[] args)main((alias) object.string = stringstring[] (parameter) string[] argsargs)
{
// `/proc/self/exe` is the artifact interrogating itself: the kernel's own
// answer to "which file am I running?".
const (local variable) const(string) pathpath = (parameter) string[] argsargs.(field) ulong string[].lengthlength > 1 ? (parameter) string[] argsargs[1] : "/proc/self/exe";
if (!(local variable) const(string) pathpath.bool std.file.exists!string(string name) nothrow @nogc @safeDetermine whether the given file (or directory) exists.
exists)
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln("SKIP: %s does not exist on this host.", (local variable) const(string) pathpath);
return 0;
}
const (local variable) const(ubyte[]) imgimg = cast(ubyte[]) void[] std.file.read!string(string name, ulong upTo = 18446744073709551615LU) @safeRead entire contents of file name and returns it as an untyped
array. If the file size is larger than upTo, only upTo
bytes are read.
Examples
import std.utf : byChar;
scope(exit)
{
assert(exists(deleteme));
remove(deleteme);
}
std.file.write(deleteme, "1234"); // deleteme is the name of a temporary file
assert(read(deleteme, 2) == "12");
assert(read(deleteme.byChar) == "1234");
assert((cast(const(ubyte)[])read(deleteme)).length == 4);
read((local variable) const(string) pathpath);
void std.stdio.writefln!(char, string, ulong)(in char[] fmt, string __param_1, ulong __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln("Reading %s (%s bytes).", (local variable) const(string) pathpath, (local variable) const(ubyte[]) imgimg.(field) ulong const(ubyte[]).lengthlength);
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
const (local variable) const(autological_elf_note_buildid.Note[]) notesnotes = autological_elf_note_buildid.Note[] autological_elf_note_buildid.readNotes(in ubyte[] img) pure @safeWalks every PT_NOTE segment and decodes the notes inside.
Only 64-bit little-endian ELF is handled; that is what the recipe's
platforms "linux" plus a modern toolchain produces, and widening it would add
byte-order plumbing without adding an argument.
readNotes((local variable) const(ubyte[]) imgimg);
if ((local variable) const(autological_elf_note_buildid.Note[]) notesnotes.(field) ulong const(autological_elf_note_buildid.Note[]).lengthlength == 0)
{
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("SKIP: this image carries no PT_NOTE segments (stripped, or linked");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln(" with --build-id=none) — nothing to decode.");
return 0;
}
void std.stdio.writefln!(char, ulong, ulong)(in char[] fmt, ulong __param_1, ulong __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln("%s note(s) across %s PT_NOTE segment(s):", (local variable) const(autological_elf_note_buildid.Note[]) notesnotes.(field) ulong const(autological_elf_note_buildid.Note[]).lengthlength,
(local variable) const(autological_elf_note_buildid.Note[]) notesnotes.autological_elf_note_buildid.main.MapResult!(__lambda_L233_C20, const(Note)[]) autological_elf_note_buildid.main.map!(const(autological_elf_note_buildid.Note)[])(const(autological_elf_note_buildid.Note)[] r) pure nothrow @nogc @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
Examples
import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));
Multiple functions can be passed to map. In that case, the
element type of map is a tuple containing one element for each
function.
auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];
size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
assert(result[0] == sums[i]);
assert(result[1] == products[i]);
++i;
}
You may alias map with some function(s) to a symbol and use
it separately:
import std.algorithm.comparison : equal;
import std.conv : to;
alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
map!(n => n.segment).const(string)[] std.array.array!(autological_elf_note_buildid.main.MapResult!(__lambda_L233_C20, const(Note)[]))(autological_elf_note_buildid.main.MapResult!(__lambda_L233_C20, const(Note)[]) r) pure @safeAllocates an array and initializes it with copies of the elements
of range r.
Narrow strings are handled as follows:
If autodecoding is turned on (default), then they are handled as a separate overload.
If autodecoding is turned off, then this is equivalent to duplicating the array.
array.ulong autological_elf_note_buildid.distinctCount(in string[] xs) pure @safeCounts distinct strings without sorting the caller's data.
distinctCount);
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
foreach ((parameter) const(autological_elf_note_buildid.Note) nn; (local variable) const(autological_elf_note_buildid.Note[]) notesnotes)
{
void std.stdio.writefln!(char, string, const(uint), string, ulong, string)(in char[] fmt, string __param_1, const(uint) __param_2, string __param_3, ulong __param_4, string __param_5) @safeEquivalent to writef(fmt, args, '\n').
writefln(" owner %-12s type 0x%02x %-24s desc %s bytes [%s]",
"'" ~ (local variable) const(autological_elf_note_buildid.Note) nn.(field) string autological_elf_note_buildid.Note.namename ~ "'", (local variable) const(autological_elf_note_buildid.Note) nn.(field) uint autological_elf_note_buildid.Note.typetype, string autological_elf_note_buildid.typeName(string owner, uint type) pure nothrow @nogc @safeNames the well-known GNU note types.
typeName((local variable) const(autological_elf_note_buildid.Note) nn.(field) string autological_elf_note_buildid.Note.namename, (local variable) const(autological_elf_note_buildid.Note) nn.(field) uint autological_elf_note_buildid.Note.typetype), (local variable) const(autological_elf_note_buildid.Note) nn.(field) const(ubyte)[] autological_elf_note_buildid.Note.descdesc.(field) ulong const(ubyte[]).lengthlength, (local variable) const(autological_elf_note_buildid.Note) nn.(field) string autological_elf_note_buildid.Note.segmentsegment);
if ((local variable) const(autological_elf_note_buildid.Note) nn.(field) string autological_elf_note_buildid.Note.namename == "GNU" && (local variable) const(autological_elf_note_buildid.Note) nn.(field) uint autological_elf_note_buildid.Note.typetype == (constant) uint autological_elf_note_buildid.ntGnuBuildId = 3untGnuBuildId)
{
const (local variable) const(string) idid = string autological_elf_note_buildid.hex(in ubyte[] b) pure @safeHex-encodes a descriptor, which is how a build-id is universally written.
hex((local variable) const(autological_elf_note_buildid.Note) nn.(field) const(ubyte)[] autological_elf_note_buildid.Note.descdesc);
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln(" build-id: %s", (local variable) const(string) idid);
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln(" debuginfod key: /buildid/%s/debuginfo", (local variable) const(string) idid);
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln(" -> the artifact names itself; the payload it names lives elsewhere.");
}
else if ((local variable) const(autological_elf_note_buildid.Note) nn.(field) string autological_elf_note_buildid.Note.namename == "GNU" && (local variable) const(autological_elf_note_buildid.Note) nn.(field) uint autological_elf_note_buildid.Note.typetype == (constant) uint autological_elf_note_buildid.ntGnuAbiTag = 1uThe note types the GNU toolchain defines under the GNU name.
ntGnuAbiTag)
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln(" ABI tag: %s", string autological_elf_note_buildid.abiTag(in ubyte[] desc) pure @safeDecodes the ABI-tag descriptor: OS id plus a minimum kernel version triple.
abiTag((local variable) const(autological_elf_note_buildid.Note) nn.(field) const(ubyte)[] autological_elf_note_buildid.Note.descdesc));
}
else if (const (local variable) const(string) tt = string autological_elf_note_buildid.asTextIfPrintable(in ubyte[] b) pure @safeRenders a descriptor as text when it plausibly is text (Fedora's .note.package).
asTextIfPrintable((local variable) const(autological_elf_note_buildid.Note) nn.(field) const(ubyte)[] autological_elf_note_buildid.Note.descdesc))
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln(" text descriptor: %s", (local variable) const(string) tt);
}
}
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("Everything above was found by walking a table and matching a name string.");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("There is no index of notes, no type registry in the file, and no way to");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("ask 'which notes are there?' without parsing all of them. That is what a");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("format without a schema costs, and what a `notes` table would replace.");
return 0;
}
/// Counts distinct strings without sorting the caller's data.
(alias) object.size_t = ulongsize_t ulong autological_elf_note_buildid.distinctCount(in string[] xs) pure @safeCounts distinct strings without sorting the caller's data.
distinctCount(in (alias) object.string = stringstring[] (parameter) const(string[]) xsxs) @safe pure
{
bool[(alias) object.string = stringstring] (local variable) bool[string] seenseen;
foreach ((parameter) const(string) xx; (parameter) const(string[]) xsxs)
bool* core.internal.newaa._d_aaGetY!(string, bool, bool[string], string, bool, const(string))(ref scope bool[string] aa, ref const(string) key, out bool found) pure nothrow @safeLookup key in aa.
Called only from implementation of (aakey) expressions when value is mutable.
seen[bool* core.internal.newaa._d_aaGetY!(string, bool, bool[string], string, bool, const(string))(ref scope bool[string] aa, ref const(string) key, out bool found) pure nothrow @safeLookup key in aa.
Called only from implementation of (aakey) expressions when value is mutable.
x] = true;
return (local variable) bool[string] seenseen.(field) ulong bool[string].lengthlength;
}