dmd.utils
This module defines some utility functions for DMD.
License
Source: utils.d
Documentation: https://dlang.org/phobos/dmd_utils.html
-
Declaration
nothrow const(char)*toWinPath(const(char)*src);Normalize path by turning forward slashes into backslashes
Parameters
const(char)*srcSource path, using unix-style ('/') path separators
Return Value
A newly-allocated string with '/' turned into backslashes
-
Declaration
nothrow BufferreadFile(Locloc, const(char)*filename);
nothrow BufferreadFile(Locloc, const(char)[]filename);Reads a file, terminate the program on error
Parameters
LoclocThe line number information from where the call originates
const(char)*filenamePath to file
-
Declaration
nothrow voidwriteFile(Locloc, const(char)[]filename, const void[]data);Writes a file, terminate the program on error
Parameters
LoclocThe line number information from where the call originates
const(char)[]filenamePath to file
void[]dataFull content of the file to be written
-
Declaration
nothrow voidensurePathToNameExists(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
LoclocThe line number information from where the call originates
const(char)[]namea path to check (the
nameis stripped) -
Declaration
nothrow voidescapePath(OutBuffer*buf, const(char)*fname);Takes a path, and escapes '(', ')' and backslashes
Parameters
OutBuffer*bufBuffer to write the escaped path to
const(char)*fnamePath to escape
-
Declaration
nothrow voidwriteEscapedMakePath(ref OutBufferbuf, const(char)*fname);Takes a path, and make it compatible with GNU Makefile format.
Discussion
GNU make uses a weird quoting scheme for white space. A space or tab preceded by 2N+1 backslashes represents N backslashes followed by space; a space or tab preceded by 2N backslashes represents N backslashes at the end of a file name; and backslashes in other contexts should not be doubled.
Parameters
OutBufferbufBuffer to write the escaped path to
const(char)*fnamePath to escape
Examples
version (Windows) { enum input = `C:\My Project\file#4$.ext`; enum expected = `C:\My\ Project\file\#4$$.ext`; } else { enum input = `/foo\bar/weird$.:name#\ with spaces.ext`; enum expected = `/foo\bar/weird$$.\:name\#\\\ with\ spaces.ext`; } OutBuffer buf; buf.writeEscapedMakePath(input); assert(buf[] == expected);
-
Declaration
pure nothrow @nogc @safe boolparseDigits(T)(ref Tval, const(char)[]p, const Tmax= T.max);Convert string to integer.
Parameters
TType of integer to parse
TvalVariable to store the result in
const(char)[]pslice to start of string digits
Tmaxmaxallowable value (inclusive), defaults toT.maxReturn Value
falseon error,trueon 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));