dmd.common.outbuffer
An expandable buffer in which you can write text or binary data.
License
Source: root/outbuffer.d
Documentation: https://dlang.org/phobos/dmd_root_outbuffer.html
-
Declaration
struct
OutBuffer
;
is a write-only output stream of untyped data. It is backed up by a contiguous array or a memory-mapped file.OutBuffer
-
Declaration
bool
doindent
;Whether to indent
-
Declaration
bool
spaces
;Whether to indent by 4
spaces
or by tabs; -
Declaration
int
level
;Current indent
level
-
Declaration
nothrow @safe this(size_t
initialSize
);Construct given size.
-
Declaration
nothrow @trusted this(const(char)*
filename
);Construct from
filename
. Will map the file into memory (or create it anew if necessary) and start writing at the beginning of it.Parameters
const(char)*
filename
zero-terminated name of file to map into memory
-
Declaration
pure nothrow @trusted void
dtor
();Frees resources associated.
-
Declaration
nothrow @system ubyte*
buf
();For porting with ease from dmd.backend.outbuf.Outbuffer
-
Declaration
nothrow @system ubyte**
bufptr
();For porting with ease from dmd.backend.outbuf.Outbuffer
-
Declaration
pure nothrow @nogc @trusted char*
extractData
();Transfer ownership of the allocated data to the caller.
Return Value
pointer to the allocated data
-
Declaration
pure nothrow @trusted void
destroy
();Releases all resources associated with
this
and resets it as an empty memory buffer. The config variablesnotlinehead
,doindent
etc. are not changed. -
Declaration
pure nothrow @trusted void
reserve
(size_tnbytes
);Reserves
bytes of additional memory (or file space) in advance. The resulting capacity is at least the previous length plusnbytes
.nbytes
Parameters
size_t
nbytes
the number of additional bytes to
reserve
-
Declaration
pure nothrow @nogc @safe void
setsize
(size_tsize
);Shrink the
size
of the data to
.size
Parameters
size_t
size
new
size
of data, must be <=.length
-
Declaration
nothrow @trusted void
write16n
(intv
);Writes a 16 bit value, no reserve check.
-
Declaration
nothrow void
write16
(intv
);Writes a 16 bit value.
-
Declaration
nothrow @trusted void
write32
(intv
);Writes a 32 bit int.
-
Declaration
nothrow @trusted void
write64
(longv
);Writes a 64 bit int.
-
Declaration
pure nothrow @system void
writestring
(const(char)*s
);
pure nothrow @safe voidwritestring
(scope const(char)[]s
);
pure nothrow @safe voidwritestring
(scope strings
);NOT zero-terminated
-
Declaration
pure nothrow @safe void
writestringln
(const(char)[]s
);NOT zero-terminated, followed by newline
-
Declaration
pure nothrow @system void
writeStringz
(const(char)*s
);
pure nothrow @safe voidwriteStringz
(const(char)[]s
);
pure nothrow @safe voidwriteStringz
(strings
);Write string to buffer, ensure it is zero terminated
-
Declaration
pure nothrow @safe void
writenl
();strip trailing tabs or spaces, write newline
-
Declaration
nothrow @trusted void
writeByten
(intb
);Writes an 8 bit byte, no reserve check.
-
Declaration
pure nothrow @safe char[]
allocate
(size_tnbytes
);Allocate space, but leave it uninitialized.
Parameters
size_t
nbytes
amount to
allocate
Return Value
slice of the allocated space to be filled in
-
Declaration
pure nothrow @safe void
print
(ulongu
);Convert
to a string and append it to the buffer.u
Parameters
ulong
u
integral value to append
-
Declaration
pure nothrow @system size_t
bracket
(size_ti
, const(char)*left
, size_tj
, const(char)*right
);Insert
left
ati
, andright
atj
. Return index just pastright
. -
Declaration
pure nothrow @system size_t
insert
(size_toffset
, const(void)*p
, size_tnbytes
);Return Value
offset
+nbytes
-
Declaration
const pure nothrow @nogc @safe const(char)[]
opSlice
();Return Value
a non-owning const slice of the buffer contents
-
Declaration
pure nothrow char[]
extractSlice
(boolnullTerminate
= false);Extract the data as a slice and take ownership of it.
Discussion
When
true
is passed as an argument, this function behaves likedmd.utils.toDString(thisbuffer.extractChars())
.Parameters
bool
nullTerminate
When
true
, the data will benull
terminated. This is useful to call C functions or store the result inStrings
. Defaults tofalse
. -
Declaration
nothrow @system bool
moveToFile
(const char*filename
);Destructively saves the contents of
this
to
. As an optimization, if the file already has identical contents with the buffer, no copying is done. This is because on SSD drives reading is often much faster than writing and because there's a high likelihood an identical file is written during the build process.filename
Parameters
char*
filename
the name of the file to receive the contents
Return Value
true
iff the operation succeeded.
-