Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
dmd.utils
This module defines some utility functions for DMD.
Authors:
License:
Source utils.d
Documentation https://dlang.org/phobos/dmd_utils.html
- nothrow const(char)*
toWinPath(const(char)*src); - Normalize path by turning forward slashes into backslashesParameters:
const(char)* srcSource path, using unix-style ('/') path separators Returns:A newly-allocated string with '/' turned into backslashes - nothrow bool
readFile(Locloc, const(char)[]filename, ref OutBufferbuf); - Reads a file, terminate the program on errorParameters:
Loc locThe line number information from where the call originates const(char)[] filenamePath to file OutBuffer bufappend contents of file to Returns:true on failure - nothrow bool
writeFile(Locloc, const(char)[]filename, const void[]data); - Writes a file, terminate the program on errorParameters:
Loc locThe line number information from where the call originates const(char)[] filenamePath to file void[] dataFull content of the file to be written Returns:false on error - nothrow bool
ensurePathToNameExists(Locloc, const(char)[]name); - Ensure the root path (the path minus the name) of the provided path exists, and terminate the process if it doesn't.Parameters:
Loc locThe line number information from where the call originates const(char)[] namea path to check (the name is stripped) Returns:false on error - pure nothrow void
escapePath(OutBuffer*buf, const(char)*fname); - Takes a path, and escapes '(', ')' and backslashesParameters:
OutBuffer* bufBuffer to write the escaped path to const(char)* fnamePath to escape - pure nothrow @nogc @safe bool
parseDigits(T)(ref Tval, const(char)[]p, const Tmax= T.max); - Convert string to integer.Parameters:
T Type of integer to parse T valVariable to store the result in const(char)[] pslice to start of string digits T maxmax allowable value (inclusive), defaults to T. maxReturns:false on error, true on successExamples:byte b; ubyte ub; short s; ushort us; int i; uint ui; long l; ulong ul; assert(b.parseDigits("42") && b == 42); assert(ub.parseDigits("42") && ub == 42); assert(s.parseDigits("420") && s == 420); assert(us.parseDigits("42000") && us == 42_000); assert(i.parseDigits("420000") && i == 420_000); assert(ui.parseDigits("420000") && ui == 420_000); assert(l.parseDigits("42000000000") && l == 42_000_000_000); assert(ul.parseDigits("82000000000") && ul == 82_000_000_000); assert(!b.parseDigits(ubyte.max.stringof)); assert(!b.parseDigits("WYSIWYG")); assert(!b.parseDigits("-42")); assert(!b.parseDigits("200")); assert(ub.parseDigits("200") && ub == 200); assert(i.parseDigits(int.max.stringof) && i == int.max); assert(i.parseDigits("420", 500) && i == 420); assert(!i.parseDigits("420", 400));
- nothrow @safe ubyte[]
arrayCastBigEndian(const ubyte[]data, size_tsize); - Cast a ubyte[] to an array of larger integers as if we are on a big endian architectureParameters:
ubyte[] dataarray with big endian data size_t size1 for ubyte[], 2 for ushort[], 4 for uint[], 8 for ulong[] Returns:copy ofdata, with bytes shuffled if compiled for version(LittleEndian)
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:28:05 2025