#!/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) stdstd.(module) std.algorithmThis package implements generic algorithms oriented towards the processing of
sequences. Sequences processed by these functions define range-based
interfaces. See also Reference on ranges and
tutorial on ranges.
Algorithms are categorized into the following submodules:
Submodule Functions
| Searching |
all
any
balancedParens
boyerMooreFinder
canFind
commonPrefix
count
countUntil
endsWith
find
findAdjacent
findAmong
findSkip
findSplit
findSplitAfter
findSplitBefore
minCount
maxCount
minElement
maxElement
minIndex
maxIndex
minPos
maxPos
skipOver
startsWith
until
|
| Comparison |
among
castSwitch
clamp
cmp
either
equal
isPermutation
isSameLength
levenshteinDistance
levenshteinDistanceAndPath
max
min
mismatch
predSwitch
|
| Iteration |
cache
cacheBidirectional
chunkBy
cumulativeFold
each
filter
filterBidirectional
fold
group
joiner
map
mean
permutations
reduce
splitWhen
splitter
substitute
sum
uniq
|
| Sorting |
completeSort
isPartitioned
isSorted
isStrictlyMonotonic
ordered
strictlyOrdered
makeIndex
merge
multiSort
nextEvenPermutation
nextPermutation
nthPermutation
partialSort
partition
partition3
schwartzSort
sort
topN
topNCopy
topNIndex
|
| Set operations (setops) |
cartesianProduct
largestPartialIntersection
largestPartialIntersectionWeighted
multiwayMerge
multiwayUnion
setDifference
setIntersection
setSymmetricDifference
|
| Mutation |
bringToFront
copy
fill
initializeAll
move
moveAll
moveSome
moveEmplace
moveEmplaceAll
moveEmplaceSome
remove
reverse
strip
stripLeft
stripRight
swap
swapRanges
uninitializedFill
|
Many functions in this package are parameterized with a predicate.
The predicate may be any suitable callable type
(a function, a delegate, a functor, or a lambda), or a
compile-time string. The string may consist of any legal D
expression that uses the symbol a (for unary functions) or the
symbols a and b (for binary functions). These names will NOT
interfere with other homonym symbols in user code because they are
evaluated in a different context. The default for all binary
comparison predicates is "a == b" for unordered operations and
"a < b" for ordered operations.
Example
int[] a = ...;
static bool greater(int a, int b)
{
return a > b;
}
sort!greater(a); // predicate as alias
sort!((a, b) => a > b)(a); // predicate as a lambda.
sort!"a > b"(a); // predicate as string
// (no ambiguity with array name)
sort(a); // no predicate, "a < b" is implicit
Source
std/algorithm/package.d
algorithm : (alias template) autological_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.
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).
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.
map;
import (package) stdstd.(module) std.arrayFunctions and types that manipulate built-in arrays and associative arrays.
This module provides all kinds of functions to create, manipulate or convert arrays:
Function Name Description
| array |
Returns a copy of the input in a newly allocated dynamic array.
|
| appender |
Returns a new Appender or RefAppender initialized with a given array.
|
| assocArray |
Returns a newly allocated associative array from a range/ranges of keys and values.
|
| byPair |
Construct a range iterating over an associative array by key/value tuples.
|
| insertInPlace |
Inserts into an existing array at a given position.
|
| join |
Concatenates a range of ranges into one array.
|
| minimallyInitializedArray |
Returns a new array of type T.
|
| replace |
Returns a new array with all occurrences of a certain subrange replaced.
|
| replaceFirst |
Returns a new array with the first occurrence of a certain subrange replaced.
|
| replaceInPlace |
Replaces all occurrences of a certain subrange and puts the result into a given array.
|
| replaceInto |
Replaces all occurrences of a certain subrange and puts the result into an output range.
|
| replaceLast |
Returns a new array with the last occurrence of a certain subrange replaced.
|
| replaceSlice |
Returns a new array with a given slice replaced.
|
| replicate |
Creates a new array out of several copies of an input array or range.
|
| sameHead |
Checks if the initial segments of two arrays refer to the same
place in memory.
|
| sameTail |
Checks if the final segments of two arrays refer to the same place
in memory.
|
| split |
Eagerly split a range or string into an array.
|
| staticArray |
Creates a new static array from given data.
|
| uninitializedArray |
Returns a new array of type T without initializing its elements.
|
Source
std/array.d
array : (alias template) autological_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.
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.
join;
import (package) stdstd.(module) std.convA one-stop shop for converting values from one type to another.
Category Functions Generic asOriginalType castFrom parse to toChars bitCast Strings text wtext dtext writeText writeWText writeDText hexString Numeric octal roundTo signed unsigned Exceptions ConvException ConvOverflowException
Source
std/conv.d
conv : (alias template) autological_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) stdstd.(module) std.stdioCategory Symbols File handles _popen File isFileHandle openNetwork stderr stdin stdout Reading chunks lines readf readfln readln Writing toFile write writef writefln writeln Misc KeepTerminator LockType StdioException
Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio
is publically imported when importing std.stdio.
There are three layers of I/O:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
stdio : (alias template) autological_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);
}
}
writeln;
import (package) stdstd.(module) std.stringString 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
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.
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.RecognizerOne 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 = stringstring (field) string autological_magic_superposition.Recognizer.namename;
(alias) object.size_t = ulongsize_t (field) ulong autological_magic_superposition.Recognizer.offsetoffset;
immutable(ubyte)[] (field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magicmagic;
immutable(ubyte)[] (field) immutable(ubyte)[] autological_magic_superposition.Recognizer.maskmask; // empty == literal match
bool (field) bool autological_magic_superposition.Recognizer.scannedscanned; // search the whole buffer instead of testing `offset`
(alias) object.string = stringstring (field) string autological_magic_superposition.Recognizer.dispatcherdispatcher; // 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 @safeTrue when magic (under mask) matches buf at at.
matchesAt(in ubyte[] (parameter) const(ubyte[]) bufbuf, (alias) object.size_t = ulongsize_t (parameter) ulong atat, in ubyte[] (parameter) const(ubyte[]) magicmagic, in ubyte[] (parameter) const(ubyte[]) maskmask) @safe pure nothrow @nogc
{
if ((parameter) ulong atat + (parameter) const(ubyte[]) magicmagic.(field) ulong const(ubyte[]).lengthlength > (parameter) const(ubyte[]) bufbuf.(field) ulong const(ubyte[]).lengthlength)
return false;
foreach ((parameter) ulong ii, (parameter) const(ubyte) mm; (parameter) const(ubyte[]) magicmagic)
{
const (local variable) const(int) maskBytemaskByte = (parameter) const(ubyte[]) maskmask.(field) ulong const(ubyte[]).lengthlength ? (parameter) const(ubyte[]) maskmask[(local variable) ulong ii] : 0xff;
if (((parameter) const(ubyte[]) bufbuf[(parameter) ulong atat + (local variable) ulong ii] & (local variable) const(int) maskBytemaskByte) != ((local variable) const(ubyte) mm & (local variable) const(int) maskBytemaskByte))
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 @safeTrue when r claims buf.
claims(in (struct) autological_magic_superposition.RecognizerOne 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) rr, in ubyte[] (parameter) const(ubyte[]) bufbuf) @safe pure nothrow @nogc
{
if (!(parameter) const(autological_magic_superposition.Recognizer) rr.(field) bool autological_magic_superposition.Recognizer.scannedscanned)
return bool autological_magic_superposition.matchesAt(in ubyte[] buf, ulong at, in ubyte[] magic, in ubyte[] mask) pure nothrow @nogc @safeTrue when magic (under mask) matches buf at at.
matchesAt((parameter) const(ubyte[]) bufbuf, (parameter) const(autological_magic_superposition.Recognizer) rr.(field) ulong autological_magic_superposition.Recognizer.offsetoffset, (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magicmagic, (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.maskmask);
// 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[]) bufbuf.(field) ulong const(ubyte[]).lengthlength < (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magicmagic.(field) ulong const(immutable(ubyte)[]).lengthlength)
return false;
for ((alias) object.ptrdiff_t = longptrdiff_t (local variable) long ii = cast((alias) object.ptrdiff_t = longptrdiff_t)((parameter) const(ubyte[]) bufbuf.(field) ulong const(ubyte[]).lengthlength - (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magicmagic.(field) ulong const(immutable(ubyte)[]).lengthlength); i >= 0; i--)
if (bool autological_magic_superposition.matchesAt(in ubyte[] buf, ulong at, in ubyte[] magic, in ubyte[] mask) pure nothrow @nogc @safeTrue when magic (under mask) matches buf at at.
matchesAt((parameter) const(ubyte[]) bufbuf, (local variable) long ii, (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.magicmagic, (parameter) const(autological_magic_superposition.Recognizer) rr.(field) immutable(ubyte)[] autological_magic_superposition.Recognizer.maskmask))
return true;
return false;
}
immutable (struct) autological_magic_superposition.RecognizerOne 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.recognizersrecognizers = [
(struct) autological_magic_superposition.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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.RecognizerOne 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 @safeReturns 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]);
representation, null, false, "SQLite library"),
(struct) autological_magic_superposition.RecognizerOne 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.RecognizerOne 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.SpecimenA named buffer to run the whole recognizer set against.
Specimen
{
(alias) object.string = stringstring (field) string autological_magic_superposition.Specimen.labellabel;
immutable(ubyte)[] (field) immutable(ubyte)[] autological_magic_superposition.Specimen.bytesbytes;
(alias) object.string = stringstring (field) string autological_magic_superposition.Specimen.notenote;
}
/++
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 @safeThe 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 @safeReturns 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]);
representation ~
// ...and, much later in the same file, a ZIP central directory + EOCD.
immutable(ubyte)[] autological_magic_superposition.emptyEocd() pure nothrow @safeA 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 @safeA well-formed, entry-less End Of Central Directory record.
emptyEocd() @safe pure nothrow
{
immutable(ubyte)[] (local variable) immutable(ubyte)[] eocdeocd = [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)[] eocdeocd;
}
int int D main()main()
{
const (local variable) const(autological_magic_superposition.Specimen[]) specimensspecimens = [
(struct) autological_magic_superposition.SpecimenA named buffer to run the whole recognizer set against.
Specimen("plain ELF", immutable(ubyte)[] autological_magic_superposition.elfHeader() pure nothrow @safeThe first eight bytes of any 64-bit little-endian ELF image.
elfHeader,
"one claim — the ordinary case"),
(struct) autological_magic_superposition.SpecimenA 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 @safeReturns 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]);
representation,
"one claim — dispatched by fs/binfmt_script.c"),
(struct) autological_magic_superposition.SpecimenA named buffer to run the whole recognizer set against.
Specimen("SELF database", immutable(ubyte)[] autological_magic_superposition.selfHeader() pure @safeA 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.SpecimenA named buffer to run the whole recognizer set against.
Specimen("APE prologue", immutable(ubyte)[] autological_magic_superposition.apePrologue() pure @safeThe 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) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("Every recognizer, run against every specimen. A column with more than");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("one mark is a byte stream in superposition.");
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
// Header row.
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln("%-24s | %s", "recognizer",
(local variable) const(autological_magic_superposition.Specimen[]) specimensspecimens.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 @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
Examples
import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));
Multiple functions can be passed to map. In that case, the
element type of map is a tuple containing one element for each
function.
auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];
size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
assert(result[0] == sums[i]);
assert(result[1] == products[i]);
++i;
}
You may alias map with some function(s) to a symbol and use
it separately:
import std.algorithm.comparison : equal;
import std.conv : to;
alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
map!(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 @safeEagerly concatenates all of the ranges in ror together (with the GC)
into one array using sep as the separator if present.
join(" "));
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln("%-24s-+-%s", "------------------------",
(local variable) const(autological_magic_superposition.Specimen[]) specimensspecimens.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 @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
Examples
import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));
Multiple functions can be passed to map. In that case, the
element type of map is a tuple containing one element for each
function.
auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];
size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
assert(result[0] == sums[i]);
assert(result[1] == products[i]);
++i;
}
You may alias map with some function(s) to a symbol and use
it separately:
import std.algorithm.comparison : equal;
import std.conv : to;
alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
map!(_ => "----------------").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 @safeEagerly concatenates all of the ranges in ror together (with the GC)
into one array using sep as the separator if present.
join("-"));
foreach ((parameter) immutable(autological_magic_superposition.Recognizer) rr; (immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizersrecognizers)
{
const (local variable) const(string) marksmarks = (local variable) const(autological_magic_superposition.Specimen[]) specimensspecimens
.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 @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
Examples
import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));
Multiple functions can be passed to map. In that case, the
element type of map is a tuple containing one element for each
function.
auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];
size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
assert(result[0] == sums[i]);
assert(result[1] == products[i]);
++i;
}
You may alias map with some function(s) to a symbol and use
it separately:
import std.algorithm.comparison : equal;
import std.conv : to;
alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
map!(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 @safeEagerly concatenates all of the ranges in ror together (with the GC)
into one array using sep as the separator if present.
join(" ");
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln("%-24s | %s", (local variable) immutable(autological_magic_superposition.Recognizer) rr.(field) string autological_magic_superposition.Recognizer.namename, (local variable) const(string) marksmarks);
}
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
foreach ((parameter) const(autological_magic_superposition.Specimen) ss; (local variable) const(autological_magic_superposition.Specimen[]) specimensspecimens)
{
const (local variable) const(immutable(string)[]) hitshits = (immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizersrecognizers.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 @safefilter`!(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 ]));
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 @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(range)
returns a range of which elements are obtained by applying fun(a)
left to right for all elements a in range. The original ranges are
not changed. Evaluation is done lazily.
Examples
import std.algorithm.comparison : equal;
import std.range : chain, only;
auto squares =
chain(only(1, 2, 3, 4), only(5, 6)).map!(a => a * a);
assert(equal(squares, only(1, 4, 9, 16, 25, 36)));
Multiple functions can be passed to map. In that case, the
element type of map is a tuple containing one element for each
function.
auto sums = [2, 4, 6, 8];
auto products = [1, 4, 9, 16];
size_t i = 0;
foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a"))
{
assert(result[0] == sums[i]);
assert(result[1] == products[i]);
++i;
}
You may alias map with some function(s) to a symbol and use
it separately:
import std.algorithm.comparison : equal;
import std.conv : to;
alias stringize = map!(to!string);
assert(equal(stringize([ 1, 2, 3, 4 ]), [ "1", "2", "3", "4" ]));
map!(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 @safeAllocates an array and initializes it with copies of the elements
of range r.
Narrow strings are handled as follows:
If autodecoding is turned on (default), then they are handled as a separate overload.
If autodecoding is turned off, then this is equivalent to duplicating the array.
array;
void std.stdio.writefln!(char, string, ulong, string)(in char[] fmt, string __param_1, ulong __param_2, string __param_3) @safeEquivalent to writef(fmt, args, '\n').
writefln("%s: %s claim(s) — %s", (local variable) const(autological_magic_superposition.Specimen) ss.(field) string autological_magic_superposition.Specimen.labellabel, (local variable) const(immutable(string)[]) hitshits.(field) ulong const(immutable(string)[]).lengthlength, (local variable) const(immutable(string)[]) hitshits.string std.array.join!(immutable(string)[], string)(immutable(string)[] ror, string sep) pure nothrow @safeEagerly concatenates all of the ranges in ror together (with the GC)
into one array using sep as the separator if present.
join(", "));
void std.stdio.writefln!(char, string)(in char[] fmt, string __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln(" %s", (local variable) const(autological_magic_superposition.Specimen) ss.(field) string autological_magic_superposition.Specimen.notenote);
}
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("Dispatchers, by who is holding the bytes:");
foreach ((local variable) immutable(autological_magic_superposition.Recognizer) rr; (immutable global) immutable(autological_magic_superposition.Recognizer[]) autological_magic_superposition.recognizersrecognizers.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 @safefilter`!(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 ]));
filter!(r => claims(r, apePrologue())))
void std.stdio.writefln!(char, string, string)(in char[] fmt, string __param_1, string __param_2) @safeEquivalent to writef(fmt, args, '\n').
writefln(" %-24s -> %s", (local variable) immutable(autological_magic_superposition.Recognizer) rr.(field) string autological_magic_superposition.Recognizer.namename, (local variable) immutable(autological_magic_superposition.Recognizer) rr.(field) string autological_magic_superposition.Recognizer.dispatcherdispatcher);
void std.stdio.writeln!()() @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln;
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("Note the shape of the disagreement: the fixed-offset recognizers all");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("read byte 0, and the scanned one reads the tail. A format that anchors");
void std.stdio.writeln!string(string __param_0) @safeEquivalent to write(args, '\n'). Calling writeln without
arguments is valid and just prints a newline to the standard
output.
Example
Reads stdin and writes it to stdout with an argument
counter.
import std.stdio;
void main()
{
string line;
for (size_t count = 0; (line = readln) !is null; count++)
{
writeln("Input ", count, ": ", line);
}
}
writeln("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 @safeThe first eight bytes of any 64-bit little-endian ELF image.
elfHeader() @safe pure nothrow
{
immutable(ubyte)[] (local variable) immutable(ubyte)[] ee = [0x7f, 'E', 'L', 'F', 2, 1, 1, 0];
return (local variable) immutable(ubyte)[] ee;
}
/// A minimal SQLite header carrying `SELF` in the `application_id` field.
immutable(ubyte)[] immutable(ubyte)[] autological_magic_superposition.selfHeader() pure @safeA minimal SQLite header carrying SELF in the application_id field.
selfHeader() @safe pure
{
auto (local variable) ubyte[] hh = new ubyte[100];
(local variable) ubyte[] hh[0 .. 16] = "SQLite format 3\0".immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safeReturns 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]);
representation;
(local variable) ubyte[] hh[16] = 0x10;
(local variable) ubyte[] hh[17] = 0x00; // page size 4096, big-endian
(local variable) ubyte[] hh[68 .. 72] = "SELF".immutable(ubyte)[] std.string.representation!(immutable(char))(string s) pure nothrow @nogc @safeReturns 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]);
representation; // application_id
return (local variable) ubyte[] hh.immutable(ubyte)[] object.idup!ubyte(ubyte[] a) pure nothrow @property @safeProvide 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 = stringstring string autological_magic_superposition.format4(string s) pure @safePads a cell to a fixed width so the table columns line up.
format4((alias) object.string = stringstring (parameter) string ss) @safe pure
{
import (package) stdstd.(module) std.arrayFunctions and types that manipulate built-in arrays and associative arrays.
This module provides all kinds of functions to create, manipulate or convert arrays:
Function Name Description
| array |
Returns a copy of the input in a newly allocated dynamic array.
|
| appender |
Returns a new Appender or RefAppender initialized with a given array.
|
| assocArray |
Returns a newly allocated associative array from a range/ranges of keys and values.
|
| byPair |
Construct a range iterating over an associative array by key/value tuples.
|
| insertInPlace |
Inserts into an existing array at a given position.
|
| join |
Concatenates a range of ranges into one array.
|
| minimallyInitializedArray |
Returns a new array of type T.
|
| replace |
Returns a new array with all occurrences of a certain subrange replaced.
|
| replaceFirst |
Returns a new array with the first occurrence of a certain subrange replaced.
|
| replaceInPlace |
Replaces all occurrences of a certain subrange and puts the result into a given array.
|
| replaceInto |
Replaces all occurrences of a certain subrange and puts the result into an output range.
|
| replaceLast |
Returns a new array with the last occurrence of a certain subrange replaced.
|
| replaceSlice |
Returns a new array with a given slice replaced.
|
| replicate |
Creates a new array out of several copies of an input array or range.
|
| sameHead |
Checks if the initial segments of two arrays refer to the same
place in memory.
|
| sameTail |
Checks if the final segments of two arrays refer to the same place
in memory.
|
| split |
Eagerly split a range or string into an array.
|
| staticArray |
Creates a new static array from given data.
|
| uninitializedArray |
Returns a new array of type T without initializing its elements.
|
Source
std/array.d
array : (alias template) 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) stdstd.(module) std.utfEncode and decode UTF-8, UTF-16 and UTF-32 strings.
UTF character support is restricted to
'\u0000' <= character <= '\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 = 16width = 16;
const (local variable) const(ulong) lenlen = (parameter) string ss.ulong std.utf.count!char(const(char)[] str) pure nothrow @nogc @safeReturns 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);
count;
return (local variable) const(ulong) lenlen >= (constant) int autological_magic_superposition.format4.width = 16width ? (parameter) string ss : (parameter) string ss ~ " ".string std.array.replicate!string(string s, ulong n) pure nothrow @safereplicate((constant) int autological_magic_superposition.format4.width = 16width - (local variable) const(ulong) lenlen);
}