magic-superposition.dhover×211all
#!/usr/bin/env dub
/+ dub.sdl:
    name "autological_magic_superposition"
    targetPath "build"
    dflags "-preview=in" "-preview=dip1000"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/**
 * "Who decides what the file is?" — answered by running every recognizer at once.
 *
 * Format dispatch is usually described one consumer at a time: the kernel checks
 * `\x7fELF`, the shell checks `#!`, a ZIP reader scans backwards for `PK\x05\x06`.
 * A polyglot exists because those checks are **independent predicates over the
 * same bytes**, and nothing arbitrates between them. This program makes that
 * concrete by implementing a small recognizer set and reporting *every* format
 * that claims a given buffer, rather than the first one — which is what a `file(1)`
 * style tool reports, and why `file(1)` is a poor guide to what will actually run.
 *
 * The recognizers are deliberately written the way real dispatchers write them:
 *
 *   - `ELF`, `PNG`, `PDF`, `MZ`, `#!`  — fixed magic at a fixed offset (the
 *     `binfmt_misc` model: magic + mask + offset; see `binfmt-magic-match.d`).
 *   - `ZIP`                            — signature *scanned for*, from the tail.
 *   - `Mach-O` fat binary              — big-endian magic, so it collides with
 *     nothing little-endian at the same offset.
 *   - `SQLite`/`SELF`                  — header magic at 0 plus an
 *     `application_id` at byte 68 (see `../../self-selfdb/examples/sqlite-header-probe.d`).
 *
 * It then runs them over four buffers, ending with a synthesized Actually
 * Portable Executable prologue: the bytes `MZqFpD='` that are simultaneously a
 * DOS/PE `MZ` signature and the start of a POSIX shell assignment, which is the
 * trick at the heart of Cosmopolitan's `ape/ape.S`.
 *
 * The output table is the point: read down a column and you are reading the set
 * of runtimes that will accept one byte stream.
 *
 * Companions:
 *   docs/research/autological-artifacts/cosmopolitan-ape/index.md
 *   docs/research/autological-artifacts/binfmt-misc.md
 *   docs/research/autological-artifacts/polyglot-craft.md
 *
 * Run with: `dub run --single magic-superposition.d`
 *
 * Portability: pure `std`, no I/O beyond stdout. Runs identically everywhere.
 */
module 
(module) autological_magic_superposition

"Who decides what the file is?" — answered by running every recognizer at once.

Format dispatch is usually described one consumer at a time: the kernel checks \x7fELF, the shell checks #!, a ZIP reader scans backwards for PK\x05\x06. A polyglot exists because those checks are independent predicates over the same bytes, and nothing arbitrates between them. This program makes that concrete by implementing a small recognizer set and reporting every format that claims a given buffer, rather than the first one — which is what a file(1) style tool reports, and why file(1) is a poor guide to what will actually run.

The recognizers are deliberately written the way real dispatchers write them:

  • ELF, PNG, PDF, MZ, #! — fixed magic at a fixed offset (the binfmt_misc model: magic + mask + offset; see binfmt-magic-match.d).

  • ZIP — signature scanned for, from the tail.

  • Mach-O fat binary — big-endian magic, so it collides with nothing little-endian at the same offset.

  • SQLite/SELF — header magic at 0 plus an application_id at byte 68 (see ../../self-selfdb/examples/sqlite-header-probe.d).

It then runs them over four buffers, ending with a synthesized Actually Portable Executable prologue: the bytes MZqFpD=' that are simultaneously a DOS/PE MZ signature and the start of a POSIX shell assignment, which is the trick at the heart of Cosmopolitan's ape/ape.S.

The output table is the point: read down a column and you are reading the set of runtimes that will accept one byte stream.

Companions

docs/research/autological-artifacts/cosmopolitan-ape/index.md docs/research/autological-artifacts/binfmt-misc.md docs/research/autological-artifacts/polyglot-craft.md

Run with: dub run --single magic-superposition.d

Portability

pure std, no I/O beyond stdout. Runs identically everywhere.

autological_magic_superposition
;
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_magic_superposition.canFind = std.algorithm.searching.canFind(alias pred = "a == b")

Convenience function. Like find, but only returns whether or not the search was successful.

For more information about pred see find.

@seeamong for checking a value against multiple arguments.
canFind
,
(alias template) autological_magic_superposition.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_magic_superposition.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_magic_superposition.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
,
(alias template) autological_magic_superposition.join = std.array.join(RoR, R)(RoR ror, R sep) if (isInputRange!RoR && isInputRange!(Unqual!(ElementType!RoR)) && isInputRange!R && (is(immutable(ElementType!(ElementType!RoR)) == immutable(ElementType!R)) || isSomeChar!(ElementType!(ElementType!RoR)) && isSomeChar!(ElementType!R)))

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
;
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_magic_superposition.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.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_magic_superposition.writefln = std.stdio.writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))

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

writefln
,
(alias template) autological_magic_superposition.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
;
import
(package) std
std
.
(module) std.string

String handling functions.

Category Functions
Searching
column
indexOf
indexOfAny
indexOfNeither
lastIndexOf
lastIndexOfAny
lastIndexOfNeither
Comparison
isNumeric
Mutation
capitalize
Pruning and Filling
center
chomp
chompPrefix
chop
detabber
detab
entab
entabber
leftJustify
outdent
rightJustify
strip
stripLeft
stripRight
wrap
Substitution
abbrev
soundex
soundexer
succ
tr
translate
Miscellaneous
assumeUTF
fromStringz
lineSplitter
representation
splitLines
toStringz
Objects of types string, wstring, and dstring are value types
and cannot be mutated element-by-element. For using mutation during building
strings, use char[], wchar[], or dchar[]. The xxxstring
types are preferable because they don't exhibit undesired aliasing, thus
making code more robust.

The following functions are publicly imported:

Module Functions
Publicly imported functions
std.algorithm
cmp, std,algorithm,comparison
count, std,algorithm,searching
endsWith, std,algorithm,searching
startsWith, std,algorithm,searching
std.array
join, std,array
replace, std,array
replaceInPlace, std,array
split, std,array
empty, std,array
std.format
format, std,format
sformat, std,format
std.uni
icmp, std,uni
toLower, std,uni
toLowerInPlace, std,uni
toUpper, std,uni
toUpperInPlace, std,uni
There is a rich set of functions for string handling defined in other modules.
Functions related to Unicode and ASCII are found in std.uni
and std.ascii, respectively. Other functions that have a
wider generality than just strings can be found in std.algorithm
and std.range.

Source

std/string.d

@seestd.algorithm and std.range for generic range algorithms , std.ascii for functions that work with ASCII strings , std.uni for functions that work with unicode strings@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
string
:
(alias template) autological_magic_superposition.representation = std.string.representation(Char)(Char[] s) if (isSomeChar!Char)

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

@params The string to return the representation of.@returnsThe representation of the passed string.
representation
;
/++ One recognizer, in the shape every real dispatcher uses. `offset` + `magic` + `mask` is exactly the `binfmt_misc` registration triple; a `mask` of all-`0xff` bytes means "match literally". `scanned` marks a recognizer whose signature is *searched for* rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible. +/ struct
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
{
(alias) object.string = string
string
(field) string autological_magic_superposition.Recognizer.name
name
;
(alias) object.size_t = ulong
size_t
(field) ulong autological_magic_superposition.Recognizer.offset
offset
;
immutable(ubyte)[]
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magic
magic
;
immutable(ubyte)[]
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.mask
mask
; // empty == literal match
bool
(field) bool autological_magic_superposition.Recognizer.scanned
scanned
; // search the whole buffer instead of testing `offset`
(alias) object.string = string
string
(field) string autological_magic_superposition.Recognizer.dispatcher
dispatcher
; // who acts on this recognition
} /// True when `magic` (under `mask`) matches `buf` at `at`. bool
bool autological_magic_superposition.matchesAt(in ubyte[] buf, ulong at, in ubyte[] magic, in ubyte[] mask) pure nothrow @nogc @safe

True when magic (under mask) matches buf at at.

matchesAt
(in ubyte[]
(parameter) const(ubyte[]) buf
buf
,
(alias) object.size_t = ulong
size_t
(parameter) ulong at
at
, in ubyte[]
(parameter) const(ubyte[]) magic
magic
, in ubyte[]
(parameter) const(ubyte[]) mask
mask
) @safe pure nothrow @nogc
{ if (
(parameter) ulong at
at
+
(parameter) const(ubyte[]) magic
magic
.
(field) ulong const(ubyte[]).length
length
>
(parameter) const(ubyte[]) buf
buf
.
(field) ulong const(ubyte[]).length
length
)
return false; foreach (
(parameter) ulong i
i
,
(parameter) const(ubyte) m
m
;
(parameter) const(ubyte[]) magic
magic
)
{ const
(local variable) const(int) maskByte
maskByte
=
(parameter) const(ubyte[]) mask
mask
.
(field) ulong const(ubyte[]).length
length
?
(parameter) const(ubyte[]) mask
mask
[
(local variable) ulong i
i
] : 0xff;
if ((
(parameter) const(ubyte[]) buf
buf
[
(parameter) ulong at
at
+
(local variable) ulong i
i
] &
(local variable) const(int) maskByte
maskByte
) != (
(local variable) const(ubyte) m
m
&
(local variable) const(int) maskByte
maskByte
))
return false; } return true; } /// True when `r` claims `buf`. bool
bool autological_magic_superposition.claims(in autological_magic_superposition.Recognizer r, in ubyte[] buf) pure nothrow @nogc @safe

True when r claims buf.

claims
(in
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
(parameter) const(autological_magic_superposition.Recognizer) r
r
, in ubyte[]
(parameter) const(ubyte[]) buf
buf
) @safe pure nothrow @nogc
{ if (!
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) bool autological_magic_superposition.Recognizer.scanned
scanned
)
return
bool autological_magic_superposition.matchesAt(in ubyte[] buf, ulong at, in ubyte[] magic, in ubyte[] mask) pure nothrow @nogc @safe

True when magic (under mask) matches buf at at.

matchesAt
(
(parameter) const(ubyte[]) buf
buf
,
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) ulong autological_magic_superposition.Recognizer.offset
offset
,
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magic
magic
,
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.mask
mask
);
// A scanned signature is looked for from the end, because that is where a // footer-anchored format puts it and where a trailing-comment-tolerant // reader must start. if (
(parameter) const(ubyte[]) buf
buf
.
(field) ulong const(ubyte[]).length
length
<
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magic
magic
.
(field) ulong const(immutable(ubyte)[]).length
length
)
return false; for (
(alias) object.ptrdiff_t = long
ptrdiff_t
(local variable) long i
i
= cast(
(alias) object.ptrdiff_t = long
ptrdiff_t
)(
(parameter) const(ubyte[]) buf
buf
.
(field) ulong const(ubyte[]).length
length
-
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magic
magic
.
(field) ulong const(immutable(ubyte)[]).length
length
); i >= 0; i--)
if (
bool autological_magic_superposition.matchesAt(in ubyte[] buf, ulong at, in ubyte[] magic, in ubyte[] mask) pure nothrow @nogc @safe

True when magic (under mask) matches buf at at.

matchesAt
(
(parameter) const(ubyte[]) buf
buf
,
(local variable) long i
i
,
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magic
magic
,
(parameter) const(autological_magic_superposition.Recognizer) r
r
.
(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.mask
mask
))
return true; return false; } immutable
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
[]
(immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizers
recognizers
= [
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("ELF", 0, [0x7f, 'E', 'L', 'F'], null, false, "kernel — fs/binfmt_elf.c"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("PE/MZ", 0, ['M', 'Z'], null, false, "Windows loader / UEFI firmware"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("shell script", 0, ['#', '!'], null, false, "kernel — fs/binfmt_script.c"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("sh (no shebang)", 0, ['M', 'Z', 'q', 'F', 'p', 'D', '=', '\''], null, false,
"POSIX shell — falls back to sh(1) on ENOEXEC"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("Mach-O fat", 0, [0xca, 0xfe, 0xba, 0xbe], null, false, "XNU — fatfile.c"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("PNG", 0, [0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a], null, false, "image consumer"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("PDF", 0, ['%', 'P', 'D', 'F', '-'], null, false, "PDF reader (tolerates a prefix)"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("SQLite 3", 0, "SQLite format 3\0".
immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safe

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

Examples

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);
@params The string to return the representation of.@returnsThe representation of the passed string.
representation
, null, false, "SQLite library"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("SELF (SQLite app id)", 68, [0x53, 0x45, 0x4c, 0x46], null, false,
"kernel — binfmt_misc, magic at offset 68"),
(struct) autological_magic_superposition.Recognizer

One recognizer, in the shape every real dispatcher uses.

offset + magic + mask is exactly the binfmt_misc registration triple; a mask of all-0xff bytes means "match literally". scanned marks a recognizer whose signature is searched for rather than found at a fixed offset — the structural property that separates ZIP from ELF, and the one that makes suffix-parasitism possible.

Recognizer
("ZIP", 0, [0x50, 0x4b, 0x05, 0x06], null, true, "ZIP reader — backwards EOCD scan"),
]; /// A named buffer to run the whole recognizer set against. struct
(struct) autological_magic_superposition.Specimen

A named buffer to run the whole recognizer set against.

Specimen
{
(alias) object.string = string
string
(field) string autological_magic_superposition.Specimen.label
label
;
immutable(ubyte)[]
(field) immutable(ubyte)[] autological_magic_superposition.Specimen.bytes
bytes
;
(alias) object.string = string
string
(field) string autological_magic_superposition.Specimen.note
note
;
} /++ The APE prologue, abbreviated. Cosmopolitan's real `ape/ape.S` opens with `MZqFpD='` followed by a shell program. To DOS/PE that is the `MZ` signature and a `e_cblp`/`e_cp` field pair; to a POSIX shell that received `ENOEXEC` from `execve` it is the start of a variable assignment, and the shell re-runs the file as a script. Two loaders, one prefix, no shared bytes wasted. +/ immutable(ubyte)[]
immutable(ubyte)[] autological_magic_superposition.apePrologue() pure @safe

The APE prologue, abbreviated.

Cosmopolitan's real ape/ape.S opens with MZqFpD=' followed by a shell program. To DOS/PE that is the MZ signature and a e_cblp/e_cp field pair; to a POSIX shell that received ENOEXEC from execve it is the start of a variable assignment, and the shell re-runs the file as a script. Two loaders, one prefix, no shared bytes wasted.

apePrologue
() @safe pure
{ return ("MZqFpD='\n" ~ "if [ x\"$1\" = x--assimilate ]; then\n" ~ " exec \"$0.ape\" \"$@\"\n" ~ "fi\n" ~ "'\n").
immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safe

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

Examples

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);
@params The string to return the representation of.@returnsThe representation of the passed string.
representation
~
// ...and, much later in the same file, a ZIP central directory + EOCD.
immutable(ubyte)[] autological_magic_superposition.emptyEocd() pure nothrow @safe

A well-formed, entry-less End Of Central Directory record.

emptyEocd
;
} /// A well-formed, entry-less End Of Central Directory record. private immutable(ubyte)[]
immutable(ubyte)[] autological_magic_superposition.emptyEocd() pure nothrow @safe

A well-formed, entry-less End Of Central Directory record.

emptyEocd
() @safe pure nothrow
{ immutable(ubyte)[]
(local variable) immutable(ubyte)[] eocd
eocd
= [0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; return
(local variable) immutable(ubyte)[] eocd
eocd
;
} int
int D main()
main
()
{ const
(local variable) const(autological_magic_superposition.Specimen[]) specimens
specimens
= [
(struct) autological_magic_superposition.Specimen

A named buffer to run the whole recognizer set against.

Specimen
("plain ELF",
immutable(ubyte)[] autological_magic_superposition.elfHeader() pure nothrow @safe

The first eight bytes of any 64-bit little-endian ELF image.

elfHeader
,
"one claim — the ordinary case"),
(struct) autological_magic_superposition.Specimen

A named buffer to run the whole recognizer set against.

Specimen
("shell script", "#!/bin/sh\necho hi\n".
immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safe

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

Examples

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);
@params The string to return the representation of.@returnsThe representation of the passed string.
representation
,
"one claim — dispatched by fs/binfmt_script.c"),
(struct) autological_magic_superposition.Specimen

A named buffer to run the whole recognizer set against.

Specimen
("SELF database",
immutable(ubyte)[] autological_magic_superposition.selfHeader() pure @safe

A minimal SQLite header carrying SELF in the application_id field.

selfHeader
(),
"two claims — a SQLite file that binfmt_misc also recognizes"),
(struct) autological_magic_superposition.Specimen

A named buffer to run the whole recognizer set against.

Specimen
("APE prologue",
immutable(ubyte)[] autological_magic_superposition.apePrologue() pure @safe

The APE prologue, abbreviated.

Cosmopolitan's real ape/ape.S opens with MZqFpD=' followed by a shell program. To DOS/PE that is the MZ signature and a e_cblp/e_cp field pair; to a POSIX shell that received ENOEXEC from execve it is the start of a variable assignment, and the shell re-runs the file as a script. Two loaders, one prefix, no shared bytes wasted.

apePrologue
(),
"three claims — the superposition, deliberately constructed"), ];
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
("Every recognizer, run against every specimen. A column with more than");
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
("one mark is a byte stream in superposition.");
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
;
// Header row.
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safe

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

writefln
("%-24s | %s", "recognizer",
(local variable) const(autological_magic_superposition.Specimen[]) specimens
specimens
.
autological_magic_superposition.main.MapResult!(__lambda_L175_C24, const(Specimen)[]) autological_magic_superposition.main.map!(const(autological_magic_superposition.Specimen)[])(const(autological_magic_superposition.Specimen)[] 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
!(s => format4(s.label)).
string std.array.join!(autological_magic_superposition.main.MapResult!(__lambda_L175_C24, const(Specimen)[]), string)(autological_magic_superposition.main.MapResult!(__lambda_L175_C24, const(Specimen)[]) ror, string sep) pure @safe

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
(" "));
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safe

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

writefln
("%-24s-+-%s", "------------------------",
(local variable) const(autological_magic_superposition.Specimen[]) specimens
specimens
.
autological_magic_superposition.main.MapResult!(__lambda_L177_C24, const(Specimen)[]) autological_magic_superposition.main.map!(const(autological_magic_superposition.Specimen)[])(const(autological_magic_superposition.Specimen)[] 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
!(_ => "----------------").
string std.array.join!(autological_magic_superposition.main.MapResult!(__lambda_L177_C24, const(Specimen)[]), string)(autological_magic_superposition.main.MapResult!(__lambda_L177_C24, const(Specimen)[]) ror, string sep) pure nothrow @safe

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
("-"));
foreach (
(parameter) immutable(autological_magic_superposition.Recognizer) r
r
;
(immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizers
recognizers
)
{ const
(local variable) const(string) marks
marks
=
(local variable) const(autological_magic_superposition.Specimen[]) specimens
specimens
.
autological_magic_superposition.main.MapResult!(__lambda_L182_C19, const(Specimen)[]) autological_magic_superposition.main.map!(const(autological_magic_superposition.Specimen)[])(const(autological_magic_superposition.Specimen)[] 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
!(s => format4(claims(r, s.bytes) ? " ✓" : " "))
.
string std.array.join!(autological_magic_superposition.main.MapResult!(__lambda_L182_C19, const(Specimen)[]), string)(autological_magic_superposition.main.MapResult!(__lambda_L182_C19, const(Specimen)[]) ror, string sep) pure @safe

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
(" ");
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safe

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

writefln
("%-24s | %s",
(local variable) immutable(autological_magic_superposition.Recognizer) r
r
.
(field) string autological_magic_superposition.Recognizer.name
name
,
(local variable) const(string) marks
marks
);
}
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_magic_superposition.Specimen) s
s
;
(local variable) const(autological_magic_superposition.Specimen[]) specimens
specimens
)
{ const
(local variable) const(immutable(string)[]) hits
hits
=
(immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizers
recognizers
.
autological_magic_superposition.main.FilterResult!(__lambda_L190_C42, immutable(Recognizer)[]) autological_magic_superposition.main.filter!(immutable(autological_magic_superposition.Recognizer)[])(immutable(autological_magic_superposition.Recognizer)[] range) pure nothrow @nogc @safe

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).

Examples

import std.algorithm.comparison : equal;
import std.math.operations : isClose;
import std.range;

int[] arr = [ 1, 2, 3, 4, 5 ];

// Filter below 3
auto small = filter!(a => a < 3)(arr);
assert(equal(small, [ 1, 2 ]));

// Filter again, but with Uniform Function Call Syntax (UFCS)
auto sum = arr.filter!(a => a < 3);
assert(equal(sum, [ 1, 2 ]));

// In combination with chain() to span multiple ranges
int[] a = [ 3, -2, 400 ];
int[] b = [ 100, -101, 102 ];
auto r = chain(a, b).filter!(a => a > 0);
assert(equal(r, [ 3, 400, 100, 102 ]));

// Mixing convertible types is fair game, too
double[] c = [ 2.5, 3.0 ];
auto r1 = chain(c, a, b).filter!(a => cast(int) a != a);
assert(isClose(r1, [ 2.5 ]));
@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@paramrange An input range of elements@returnsA range containing only elements x in range for which predicate(x) returns true.
filter
!(r => claims(r, s.bytes)).
autological_magic_superposition.main.MapResult!(__lambda_L190_C72, FilterResult!(__lambda_L190_C42, immutable(Recognizer)[])) autological_magic_superposition.main.map!(autological_magic_superposition.main.FilterResult!(__lambda_L190_C42, immutable(Recognizer)[]))(autological_magic_superposition.main.FilterResult!(__lambda_L190_C42, immutable(Recognizer)[]) 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
!(r => r.name).
immutable(string)[] std.array.array!(autological_magic_superposition.main.MapResult!(__lambda_L190_C72, FilterResult!(__lambda_L190_C42, immutable(Recognizer)[])))(autological_magic_superposition.main.MapResult!(__lambda_L190_C72, FilterResult!(__lambda_L190_C42, immutable(Recognizer)[])) r) pure nothrow @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
;
void std.stdio.writefln!(char, string, ulong, string)(in char[] fmt, string __param_1, ulong __param_2, string __param_3) @safe

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

writefln
("%s: %s claim(s) — %s",
(local variable) const(autological_magic_superposition.Specimen) s
s
.
(field) string autological_magic_superposition.Specimen.label
label
,
(local variable) const(immutable(string)[]) hits
hits
.
(field) ulong const(immutable(string)[]).length
length
,
(local variable) const(immutable(string)[]) hits
hits
.
string std.array.join!(immutable(string)[], string)(immutable(string)[] ror, string sep) pure nothrow @safe

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

@paramror An input range of input ranges@paramsep An input range, or a single element, to join the ranges on@returnsAn array of elements@seeFor a lazy version, see joiner
join
(", "));
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safe

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

writefln
(" %s",
(local variable) const(autological_magic_superposition.Specimen) s
s
.
(field) string autological_magic_superposition.Specimen.note
note
);
}
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
("Dispatchers, by who is holding the bytes:");
foreach (
(local variable) immutable(autological_magic_superposition.Recognizer) r
r
;
(immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizers
recognizers
.
autological_magic_superposition.main.FilterResult!(__lambda_L197_C37, immutable(Recognizer)[]) autological_magic_superposition.main.filter!(immutable(autological_magic_superposition.Recognizer)[])(immutable(autological_magic_superposition.Recognizer)[] range) pure nothrow @nogc @safe

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).

Examples

import std.algorithm.comparison : equal;
import std.math.operations : isClose;
import std.range;

int[] arr = [ 1, 2, 3, 4, 5 ];

// Filter below 3
auto small = filter!(a => a < 3)(arr);
assert(equal(small, [ 1, 2 ]));

// Filter again, but with Uniform Function Call Syntax (UFCS)
auto sum = arr.filter!(a => a < 3);
assert(equal(sum, [ 1, 2 ]));

// In combination with chain() to span multiple ranges
int[] a = [ 3, -2, 400 ];
int[] b = [ 100, -101, 102 ];
auto r = chain(a, b).filter!(a => a > 0);
assert(equal(r, [ 3, 400, 100, 102 ]));

// Mixing convertible types is fair game, too
double[] c = [ 2.5, 3.0 ];
auto r1 = chain(c, a, b).filter!(a => cast(int) a != a);
assert(isClose(r1, [ 2.5 ]));
@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@paramrange An input range of elements@returnsA range containing only elements x in range for which predicate(x) returns true.
filter
!(r => claims(r, apePrologue())))
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safe

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

writefln
(" %-24s -> %s",
(local variable) immutable(autological_magic_superposition.Recognizer) r
r
.
(field) string autological_magic_superposition.Recognizer.name
name
,
(local variable) immutable(autological_magic_superposition.Recognizer) r
r
.
(field) string autological_magic_superposition.Recognizer.dispatcher
dispatcher
);
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
("Note the shape of the disagreement: the fixed-offset recognizers all");
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
("read byte 0, and the scanned one reads the tail. A format that anchors");
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
("its index at neither end has nothing left to share.");
return 0; } /// The first eight bytes of any 64-bit little-endian ELF image. immutable(ubyte)[]
immutable(ubyte)[] autological_magic_superposition.elfHeader() pure nothrow @safe

The first eight bytes of any 64-bit little-endian ELF image.

elfHeader
() @safe pure nothrow
{ immutable(ubyte)[]
(local variable) immutable(ubyte)[] e
e
= [0x7f, 'E', 'L', 'F', 2, 1, 1, 0];
return
(local variable) immutable(ubyte)[] e
e
;
} /// A minimal SQLite header carrying `SELF` in the `application_id` field. immutable(ubyte)[]
immutable(ubyte)[] autological_magic_superposition.selfHeader() pure @safe

A minimal SQLite header carrying SELF in the application_id field.

selfHeader
() @safe pure
{ auto
(local variable) ubyte[] h
h
= new ubyte[100];
(local variable) ubyte[] h
h
[0 .. 16] = "SQLite format 3\0".
immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safe

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

Examples

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);
@params The string to return the representation of.@returnsThe representation of the passed string.
representation
;
(local variable) ubyte[] h
h
[16] = 0x10;
(local variable) ubyte[] h
h
[17] = 0x00; // page size 4096, big-endian
(local variable) ubyte[] h
h
[68 .. 72] = "SELF".
immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safe

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

Examples

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);
@params The string to return the representation of.@returnsThe representation of the passed string.
representation
; // application_id
return
(local variable) ubyte[] h
h
.
immutable(ubyte)[] object.idup!ubyte(ubyte[] a) pure nothrow @property @safe

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

idup
;
} /// Pads a cell to a fixed width so the table columns line up.
(alias) object.string = string
string
string autological_magic_superposition.format4(string s) pure @safe

Pads a cell to a fixed width so the table columns line up.

format4
(
(alias) object.string = string
string
(parameter) string s
s
) @safe pure
{ 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) replicate = std.array.replicate(S)(S s, size_t n) if (isDynamicArray!S)

Params: s = an $(REF_ALTTEXT input range, isInputRange, std,range,primitives) or a dynamic array n = number of times to repeat s

Returns: An array that consists of s repeated n times. This function allocates, fills, and returns a new array.

See_Also: For a lazy version, refer to $(REF repeat, std,range).

replicate
;
import
(package) std
std
.
(module) std.utf

Encode and decode UTF-8, UTF-16 and UTF-32 strings.

UTF character support is restricted to '\u0000' &lt;= character &lt;= '\U0010FFFF'.

Category Functions
Decode decode decodeFront
Lazy decode byCodeUnit byChar byWchar byDchar byUTF
Encode encode toUTF8 toUTF16 toUTF32 toUTFz toUTF16z
Length codeLength count stride strideBack
Index toUCSindex toUTFindex
Validation isValidDchar isValidCodepoint validate
Miscellaneous replacementDchar UseReplacementDchar UTFException

Source

std/utf.d

utf
:
(alias template) count = std.utf.count(C)(const(C)[] str) if (isSomeChar!C)

Returns the total number of code points encoded in str.

    Supercedes: This function supercedes $(LREF toUCSindex).

    Standards: Unicode 5.0, ASCII, ISO-8859-1, WINDOWS-1252

    Throws:
        `UTFException` if `str` is not well-formed.
count
;
enum
(constant) int autological_magic_superposition.format4.width = 16
width
= 16;
const
(local variable) const(ulong) len
len
=
(parameter) string s
s
.
ulong std.utf.count!char(const(char)[] str) pure nothrow @nogc @safe

Returns the total number of code points encoded in str.

Supercedes

This function supercedes toUCSindex.

Examples

assert(count("") == 0);
assert(count("a") == 1);
assert(count("abc") == 3);
assert(count("\u20AC100") == 4);
@standardsUnicode 5.0, ASCII, ISO-8859-1, WINDOWS-1252@throwsUTFException if str is not well-formed.
count
;
return
(local variable) const(ulong) len
len
>=
(constant) int autological_magic_superposition.format4.width = 16
width
?
(parameter) string s
s
:
(parameter) string s
s
~ " ".
string std.array.replicate!string(string s, ulong n) pure nothrow @safe
@params an input range or a dynamic array@paramn number of times to repeat s@returnsAn array that consists of s repeated n times. This function allocates, fills, and returns a new array.@seeFor a lazy version, refer to repeat.
replicate
(
(constant) int autological_magic_superposition.format4.width = 16
width
-
(local variable) const(ulong) len
len
);
}