elf-note-buildid.dhover×333all
#!/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_buildid

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.

autological_elf_note_buildid
;
import
(package) std
std
.
(module) std.algorithm

This 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

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
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).

@parampredicate Function to apply to each element of range@returnsAn input range that contains the filtered elements. If range is at least a forward range, the return value of filter will also be a forward range.@seeFilter (higher-order function), filterBidirectional
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.

@paramfun one or more transformation functions@seeMap (higher-order function)
map
;
import
(package) std
std
.
(module) std.array

Functions 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

@copyrightCopyright Andrei Alexandrescu 2008- and Jonathan M Davis 2011-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu and Jonathan M Davis
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.

@paramr range (or aggregate with opApply function) whose elements are copied into the allocated array@returnsallocated and initialized array
array
;
import
(package) std
std
.
(module) std.ascii

Functions 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

ASCII Table, Wikipedia

Source

std/ascii.d

ascii
:
(alias) autological_elf_note_buildid.isPrintable = bool std.ascii.isPrintable(dchar c) pure nothrow @nogc @safe
@paramc The character to test.@returnsWhether or not c is a printable character - including the space character.
isPrintable
;
import
(package) std
std
.
(module) std.conv

A 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

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
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) std
std
.
(module) std.file

Utilities 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

@copyrightCopyright The D Language Foundation 2007 - 2011.@seeThe official tutorial for an introduction to working with files in D, module std.stdio for opening files and manipulating them via handles, and module std.path for manipulating path strings.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis
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.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input 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.

@paramname string or range of characters representing the file name@paramupTo if present, the maximum number of bytes to read@returnsUntyped array of bytes read.@throwsFileException on error.@seereadText for reading and validating a text file.
read
;
import
(package) std
std
.
(module) std.stdio
Category 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:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
/// `p_type` values this program cares about. enum uint
(constant) uint autological_elf_note_buildid.ptNote = 4u

p_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 = 1u

The note types the GNU toolchain defines under the GNU name.

ntGnuAbiTag
= 1;
enum uint
(constant) uint autological_elf_note_buildid.ntGnuBuildId = 3u
ntGnuBuildId
= 3;
enum uint
(constant) uint autological_elf_note_buildid.ntGnuPropertyType0 = 5u
ntGnuPropertyType0
= 5;
/// One decoded ELF note. struct
(struct) autological_elf_note_buildid.Note

One decoded ELF note.

Note
{
(alias) object.string = string
string
(field) string autological_elf_note_buildid.Note.name
name
;
uint
(field) uint autological_elf_note_buildid.Note.type
type
;
const(ubyte)[]
(field) const(ubyte)[] autological_elf_note_buildid.Note.desc
desc
;
(alias) object.string = string
string
(field) string autological_elf_note_buildid.Note.segment
segment
; // which PT_NOTE it came from, for reporting
} /// Reads a little-endian unsigned integer of `T` at `offset`.
(alias) T = ulong
T
ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
(T)(in ubyte[]
(parameter) const(ubyte[]) b
b
,
(alias) object.size_t = ulong
size_t
(parameter) ulong offset
offset
) @safe pure nothrow @nogc
in (
(parameter) ulong offset
offset
+
(ulong) ulong
T
.
(constant) ulong ulong.sizeof = 8LU
sizeof
<=
(parameter) const(ubyte[]) b
b
.
(field) ulong const(ubyte[]).length
length
, "read past end of image")
{
(alias) T = ulong
T
(local variable) ulong v
v
;
foreach (
(local variable) ulong i
i
; 0 ..
(ulong) ulong
T
.
(constant) ulong ulong.sizeof = 8LU
sizeof
)
(local variable) ulong v
v
|=
(ulong) ulong
T
(
(parameter) const(ubyte[]) b
b
[
(parameter) ulong offset
offset
+
(local variable) ulong i
i
]) << (8 *
(local variable) ulong i
i
);
return
(local variable) ulong v
v
;
} /// Rounds `n` up to the next multiple of 4, as the note format requires.
(alias) object.size_t = ulong
size_t
ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safe

Rounds n up to the next multiple of 4, as the note format requires.

align4
(
(alias) object.size_t = ulong
size_t
(parameter) ulong n
n
) @safe pure nothrow @nogc => (
(parameter) ulong n
n
+ 3) & ~
(ulong) ulong
size_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.Note

One decoded ELF note.

Note
[]
autological_elf_note_buildid.Note[] autological_elf_note_buildid.readNotes(in ubyte[] img) pure @safe

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.

readNotes
(in ubyte[]
(parameter) const(ubyte[]) img
img
) @safe pure
{ if (
(parameter) const(ubyte[]) img
img
.
(field) ulong const(ubyte[]).length
length
< 64 ||
(parameter) const(ubyte[]) img
img
[0 .. 4] != [0x7f, 'E', 'L', 'F'])
throw new
(class) object.Exception

The 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[]) img
img
[4] != 2 ||
(parameter) const(ubyte[]) img
img
[5] != 1)
throw new
(class) object.Exception

The 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) phoff
phoff
=
ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!ulong(
(parameter) const(ubyte[]) img
img
, 0x20);
const
(local variable) const(ushort) phentsize
phentsize
=
ushort autological_elf_note_buildid.le!ushort(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!ushort(
(parameter) const(ubyte[]) img
img
, 0x36);
const
(local variable) const(ushort) phnum
phnum
=
ushort autological_elf_note_buildid.le!ushort(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!ushort(
(parameter) const(ubyte[]) img
img
, 0x38);
(struct) autological_elf_note_buildid.Note

One decoded ELF note.

Note
[]
(local variable) autological_elf_note_buildid.Note[] notes
notes
;
foreach (
(local variable) int i
i
; 0 ..
(local variable) const(ushort) phnum
phnum
)
{ const
(local variable) const(ulong) ph
ph
= cast(
(alias) object.size_t = ulong
size_t
)(
(local variable) const(ulong) phoff
phoff
+
(local variable) int i
i
*
(local variable) const(ushort) phentsize
phentsize
);
if (
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) img
img
,
(local variable) const(ulong) ph
ph
) !=
(constant) uint autological_elf_note_buildid.ptNote = 4u

p_type values this program cares about.

ptNote
)
continue; const
(local variable) const(ulong) offset
offset
= cast(
(alias) object.size_t = ulong
size_t
)
ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!ulong(
(parameter) const(ubyte[]) img
img
,
(local variable) const(ulong) ph
ph
+ 0x08);
const
(local variable) const(ulong) filesz
filesz
= cast(
(alias) object.size_t = ulong
size_t
)
ulong autological_elf_note_buildid.le!ulong(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!ulong(
(parameter) const(ubyte[]) img
img
,
(local variable) const(ulong) ph
ph
+ 0x20);
const
(local variable) const(string) label
label
= "PT_NOTE[" ~
(local variable) int i
i
.
string std.conv.text!int(int __param_0) pure nothrow @safe

Convenience 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 @safe

Lowercase hex, for offsets in labels.

offsetHex
(
(local variable) const(ulong) offset
offset
);
(alias) object.size_t = ulong
size_t
(local variable) ulong cursor
cursor
=
(local variable) const(ulong) offset
offset
;
const
(local variable) const(ulong) end
end
=
(local variable) const(ulong) offset
offset
+
(local variable) const(ulong) filesz
filesz
;
while (
(local variable) ulong cursor
cursor
+ 12 <=
(local variable) const(ulong) end
end
)
{ const
(local variable) const(uint) namesz
namesz
=
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) img
img
,
(local variable) ulong cursor
cursor
);
const
(local variable) const(uint) descsz
descsz
=
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) img
img
,
(local variable) ulong cursor
cursor
+ 4);
const
(local variable) const(uint) type
type
=
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) img
img
,
(local variable) ulong cursor
cursor
+ 8);
const
(local variable) const(ulong) nameAt
nameAt
=
(local variable) ulong cursor
cursor
+ 12;
const
(local variable) const(ulong) descAt
descAt
=
(local variable) const(ulong) nameAt
nameAt
+
ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safe

Rounds n up to the next multiple of 4, as the note format requires.

align4
(
(local variable) const(uint) namesz
namesz
);
if (
(local variable) const(ulong) descAt
descAt
+
(local variable) const(uint) descsz
descsz
>
(local variable) const(ulong) end
end
)
break; // `n_namesz` counts the terminating NUL; drop it for display. const
(local variable) const(ubyte[]) nameBytes
nameBytes
=
(parameter) const(ubyte[]) img
img
[
(local variable) const(ulong) nameAt
nameAt
..
(local variable) const(ulong) nameAt
nameAt
+ (
(local variable) const(uint) namesz
namesz
?
(local variable) const(uint) namesz
namesz
- 1 : 0)];
(local variable) autological_elf_note_buildid.Note[] notes
notes
~=
(struct) autological_elf_note_buildid.Note

One decoded ELF note.

Note
(cast(
(alias) object.string = string
string
)
(local variable) const(ubyte[]) nameBytes
nameBytes
.
immutable(ubyte)[] object.idup!(const(ubyte))(const(ubyte)[] a) pure nothrow @property @safe

Provide the .idup array property, which creates an immutable duplicate.

idup
,
(local variable) const(uint) type
type
,
(parameter) const(ubyte[]) img
img
[
(local variable) const(ulong) descAt
descAt
..
(local variable) const(ulong) descAt
descAt
+
(local variable) const(uint) descsz
descsz
].
immutable(ubyte)[] object.idup!(const(ubyte))(const(ubyte)[] a) pure nothrow @property @safe

Provide the .idup array property, which creates an immutable duplicate.

idup
,
(local variable) const(string) label
label
);
(local variable) ulong cursor
cursor
=
(local variable) const(ulong) descAt
descAt
+
ulong autological_elf_note_buildid.align4(ulong n) pure nothrow @nogc @safe

Rounds n up to the next multiple of 4, as the note format requires.

align4
(
(local variable) const(uint) descsz
descsz
);
} } return
(local variable) autological_elf_note_buildid.Note[] notes
notes
;
} /// Lowercase hex, for offsets in labels.
(alias) object.string = string
string
string autological_elf_note_buildid.offsetHex(ulong v) pure @safe

Lowercase hex, for offsets in labels.

offsetHex
(
(alias) object.size_t = ulong
size_t
(parameter) ulong v
v
) @safe pure
{ import
(package) std
std
.
(module) std.format

This 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*: **'-'**|**'+'**|**'&nbsp;'**|**'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. | | '+'&nbsp;/&nbsp;*'&nbsp;'* | 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");
@copyrightCopyright The D Language Foundation 2000-2021.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, and Kenji Hara
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 @safe

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.

Examples

assert(format("Here are %d %s.", 3, "apples") == "Here are 3 apples.");

assert("Increase: %7.2f %%".format(17.4285) == "Increase:   17.43 %");
@paramfmt a format string@paramargs a variadic list of arguments to be formatted@paramChar character type of fmt@paramArgs a variadic list of types of the arguments@returnsThe formatted string.@throwsA FormatException if formatting did not succeed.@seesformat for a variant, that tries to avoid garbage collection.
format
("%x",
(parameter) ulong v
v
);
} /// Hex-encodes a descriptor, which is how a build-id is universally written.
(alias) object.string = string
string
string autological_elf_note_buildid.hex(in ubyte[] b) pure @safe

Hex-encodes a descriptor, which is how a build-id is universally written.

hex
(in ubyte[]
(parameter) const(ubyte[]) b
b
) @safe pure
{ import
(package) std
std
.
(module) std.format

This 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*: **'-'**|**'+'**|**'&nbsp;'**|**'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. | | '+'&nbsp;/&nbsp;*'&nbsp;'* | 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");
@copyrightCopyright The D Language Foundation 2000-2021.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, and Kenji Hara
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[] s
s
;
foreach (
(parameter) const(ubyte) x
x
;
(parameter) const(ubyte[]) b
b
)
(local variable) char[] s
s
~=
string std.format.format!(char, const(ubyte))(in char[] fmt, const(ubyte) __param_1) pure @safe

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.

Examples

assert(format("Here are %d %s.", 3, "apples") == "Here are 3 apples.");

assert("Increase: %7.2f %%".format(17.4285) == "Increase:   17.43 %");
@paramfmt a format string@paramargs a variadic list of arguments to be formatted@paramChar character type of fmt@paramArgs a variadic list of types of the arguments@returnsThe formatted string.@throwsA FormatException if formatting did not succeed.@seesformat for a variant, that tries to avoid garbage collection.
format
("%02x",
(local variable) const(ubyte) x
x
);
return
(local variable) char[] s
s
.
string object.idup!char(char[] a) pure nothrow @property @safe

Provide 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 = string
string
string autological_elf_note_buildid.asTextIfPrintable(in ubyte[] b) pure @safe

Renders a descriptor as text when it plausibly is text (Fedora's .note.package).

asTextIfPrintable
(in ubyte[]
(parameter) const(ubyte[]) b
b
) @safe pure
{ foreach (
(parameter) const(ubyte) c
c
;
(parameter) const(ubyte[]) b
b
)
if (
(local variable) const(ubyte) c
c
!= 0 && !(cast(char)
(local variable) const(ubyte) c
c
).
bool std.ascii.isPrintable(dchar c) pure nothrow @nogc @safe

Examples

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('á'));
@paramc The character to test.@returnsWhether or not c is a printable character - including the space character.
isPrintable
)
return null; char[]
(local variable) char[] s
s
;
foreach (
(parameter) const(ubyte) c
c
;
(parameter) const(ubyte[]) b
b
)
if (
(local variable) const(ubyte) c
c
!= 0)
(local variable) char[] s
s
~= cast(char)
(local variable) const(ubyte) c
c
;
return
(local variable) char[] s
s
.
string object.idup!char(char[] a) pure nothrow @property @safe

Provide the .idup array property, which creates an immutable duplicate.

idup
;
} /// Names the well-known GNU note types.
(alias) object.string = string
string
string autological_elf_note_buildid.typeName(string owner, uint type) pure nothrow @nogc @safe

Names the well-known GNU note types.

typeName
(
(alias) object.string = string
string
(parameter) string owner
owner
, uint
(parameter) uint type
type
) @safe pure nothrow @nogc
{ if (
(parameter) string owner
owner
!= "GNU")
return "vendor-defined"; switch (
(parameter) uint type
type
)
{ case
(constant) uint autological_elf_note_buildid.ntGnuAbiTag = 1u

The note types the GNU toolchain defines under the GNU name.

ntGnuAbiTag
:
return "NT_GNU_ABI_TAG"; case
(constant) uint autological_elf_note_buildid.ntGnuBuildId = 3u
ntGnuBuildId
:
return "NT_GNU_BUILD_ID"; case
(constant) uint autological_elf_note_buildid.ntGnuPropertyType0 = 5u
ntGnuPropertyType0
:
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 = string
string
string autological_elf_note_buildid.abiTag(in ubyte[] desc) pure @safe

Decodes the ABI-tag descriptor: OS id plus a minimum kernel version triple.

abiTag
(in ubyte[]
(parameter) const(ubyte[]) desc
desc
) @safe pure
{ if (
(parameter) const(ubyte[]) desc
desc
.
(field) ulong const(ubyte[]).length
length
< 16)
return "(malformed)"; static immutable
(immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.os
os
= ["Linux", "GNU/Hurd", "Solaris", "FreeBSD"];
const
(local variable) const(uint) id
id
=
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) desc
desc
, 0);
const
(local variable) const(string) name
name
=
(local variable) const(uint) id
id
<
(immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.os
os
.
(field) ulong immutable(string[]).length
length
?
(immutable global) immutable(string[]) autological_elf_note_buildid.abiTag.os
os
[
(local variable) const(uint) id
id
] : "OS " ~
(local variable) const(uint) id
id
.
string std.conv.text!(const(uint))(const(uint) __param_0) pure nothrow @safe

Convenience functions for converting one or more arguments of any type into text (the three character widths).

text
;
return
(local variable) const(string) name
name
~ " " ~
uint autological_elf_note_buildid.le!uint(in ubyte[] b, ulong offset) pure nothrow @nogc @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) desc
desc
, 4).
string std.conv.text!uint(uint __param_0) pure nothrow @safe

Convenience 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 @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) desc
desc
, 8).
string std.conv.text!uint(uint __param_0) pure nothrow @safe

Convenience 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 @safe

Reads a little-endian unsigned integer of T at offset.

le
!uint(
(parameter) const(ubyte[]) desc
desc
, 12).
string std.conv.text!uint(uint __param_0) pure nothrow @safe

Convenience 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 = string
string
[]
(parameter) string[] args
args
)
{ // `/proc/self/exe` is the artifact interrogating itself: the kernel's own // answer to "which file am I running?". const
(local variable) const(string) path
path
=
(parameter) string[] args
args
.
(field) ulong string[].length
length
> 1 ?
(parameter) string[] args
args
[1] : "/proc/self/exe";
if (!
(local variable) const(string) path
path
.
bool std.file.exists!string(string name) nothrow @nogc @safe

Determine whether the given file (or directory) exists.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input exists
exists
)
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("SKIP: %s does not exist on this host.",
(local variable) const(string) path
path
);
return 0; } const
(local variable) const(ubyte[]) img
img
= cast(ubyte[])
void[] std.file.read!string(string name, ulong upTo = 18446744073709551615LU) @safe

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.

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);
@paramname string or range of characters representing the file name@paramupTo if present, the maximum number of bytes to read@returnsUntyped array of bytes read.@throwsFileException on error.@seereadText for reading and validating a text file.
read
(
(local variable) const(string) path
path
);
void std.stdio.writefln!(char, string, ulong)(in char[] fmt, string __param_1, ulong __param_2) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("Reading %s (%s bytes).",
(local variable) const(string) path
path
,
(local variable) const(ubyte[]) img
img
.
(field) ulong const(ubyte[]).length
length
);
void std.stdio.writeln!()() @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
const
(local variable) const(autological_elf_note_buildid.Note[]) notes
notes
=
autological_elf_note_buildid.Note[] autological_elf_note_buildid.readNotes(in ubyte[] img) pure @safe

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.

readNotes
(
(local variable) const(ubyte[]) img
img
);
if (
(local variable) const(autological_elf_note_buildid.Note[]) notes
notes
.
(field) ulong const(autological_elf_note_buildid.Note[]).length
length
== 0)
{
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("SKIP: this image carries no PT_NOTE segments (stripped, or linked");
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
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) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("%s note(s) across %s PT_NOTE segment(s):",
(local variable) const(autological_elf_note_buildid.Note[]) notes
notes
.
(field) ulong const(autological_elf_note_buildid.Note[]).length
length
,
(local variable) const(autological_elf_note_buildid.Note[]) notes
notes
.
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 @safe

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.

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" ]));
@paramfun one or more transformation functions@seeMap (higher-order function)@paramr an input range@returnsA range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
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 @safe

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.

@paramr range (or aggregate with opApply function) whose elements are copied into the allocated array@returnsallocated and initialized array
array
.
ulong autological_elf_note_buildid.distinctCount(in string[] xs) pure @safe

Counts distinct strings without sorting the caller's data.

distinctCount
);
void std.stdio.writeln!()() @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
foreach (
(parameter) const(autological_elf_note_buildid.Note) n
n
;
(local variable) const(autological_elf_note_buildid.Note[]) notes
notes
)
{
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) @safe

Equivalent to writef(fmt, args, '\n').

writefln
(" owner %-12s type 0x%02x %-24s desc %s bytes [%s]",
"'" ~
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) string autological_elf_note_buildid.Note.name
name
~ "'",
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) uint autological_elf_note_buildid.Note.type
type
,
string autological_elf_note_buildid.typeName(string owner, uint type) pure nothrow @nogc @safe

Names the well-known GNU note types.

typeName
(
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) string autological_elf_note_buildid.Note.name
name
,
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) uint autological_elf_note_buildid.Note.type
type
),
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) const(ubyte)[] autological_elf_note_buildid.Note.desc
desc
.
(field) ulong const(ubyte[]).length
length
,
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) string autological_elf_note_buildid.Note.segment
segment
);
if (
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) string autological_elf_note_buildid.Note.name
name
== "GNU" &&
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) uint autological_elf_note_buildid.Note.type
type
==
(constant) uint autological_elf_note_buildid.ntGnuBuildId = 3u
ntGnuBuildId
)
{ const
(local variable) const(string) id
id
=
string autological_elf_note_buildid.hex(in ubyte[] b) pure @safe

Hex-encodes a descriptor, which is how a build-id is universally written.

hex
(
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) const(ubyte)[] autological_elf_note_buildid.Note.desc
desc
);
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
(" build-id: %s",
(local variable) const(string) id
id
);
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
(" debuginfod key: /buildid/%s/debuginfo",
(local variable) const(string) id
id
);
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
(" -> the artifact names itself; the payload it names lives elsewhere.");
} else if (
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) string autological_elf_note_buildid.Note.name
name
== "GNU" &&
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) uint autological_elf_note_buildid.Note.type
type
==
(constant) uint autological_elf_note_buildid.ntGnuAbiTag = 1u

The note types the GNU toolchain defines under the GNU name.

ntGnuAbiTag
)
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
(" ABI tag: %s",
string autological_elf_note_buildid.abiTag(in ubyte[] desc) pure @safe

Decodes the ABI-tag descriptor: OS id plus a minimum kernel version triple.

abiTag
(
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) const(ubyte)[] autological_elf_note_buildid.Note.desc
desc
));
} else if (const
(local variable) const(string) t
t
=
string autological_elf_note_buildid.asTextIfPrintable(in ubyte[] b) pure @safe

Renders a descriptor as text when it plausibly is text (Fedora's .note.package).

asTextIfPrintable
(
(local variable) const(autological_elf_note_buildid.Note) n
n
.
(field) const(ubyte)[] autological_elf_note_buildid.Note.desc
desc
))
{
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
(" text descriptor: %s",
(local variable) const(string) t
t
);
} }
void std.stdio.writeln!()() @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("Everything above was found by walking a table and matching a name string.");
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
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) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("ask 'which notes are there?' without parsing all of them. That is what a");
void std.stdio.writeln!string(string __param_0) @safe

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);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
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 = ulong
size_t
ulong autological_elf_note_buildid.distinctCount(in string[] xs) pure @safe

Counts distinct strings without sorting the caller's data.

distinctCount
(in
(alias) object.string = string
string
[]
(parameter) const(string[]) xs
xs
) @safe pure
{ bool[
(alias) object.string = string
string
]
(local variable) bool[string] seen
seen
;
foreach (
(parameter) const(string) x
x
;
(parameter) const(string[]) xs
xs
)
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 @safe

Lookup key in aa. Called only from implementation of (aakey) expressions when value is mutable.

@paramaa associative array@paramkey reference to the key value@paramfound returns whether the key was found or a new entry was added@returnsif key was in the aa, a mutable pointer to the existing value. If key was not in the aa, a mutable pointer to newly inserted value which is set to zero
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 @safe

Lookup key in aa. Called only from implementation of (aakey) expressions when value is mutable.

@paramaa associative array@paramkey reference to the key value@paramfound returns whether the key was found or a new entry was added@returnsif key was in the aa, a mutable pointer to the existing value. If key was not in the aa, a mutable pointer to newly inserted value which is set to zero
x
] = true;
return
(local variable) bool[string] seen
seen
.
(field) ulong bool[string].length
length
;
}