"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/dmd/utils.d" between
dmd-2.095.0.tar.gz and dmd-2.095.1.tar.gz

About: DMD (Digital Mars D) is the D reference compiler. D is an object-oriented, imperative, multi-paradigm system programming language.

utils.d  (dmd-2.095.0):utils.d  (dmd-2.095.1)
skipping to change at line 47 skipping to change at line 47
while (*p != '\0') while (*p != '\0')
{ {
if (*p == '/') if (*p == '/')
*p = '\\'; *p = '\\';
p++; p++;
} }
return result; return result;
} }
/** /**
* Normalize path by turning backslashes into forward slashes
*
* Params:
* src = Source path, using window-style ('\') or mixed path separators
*
* Returns:
* A newly-allocated string with '\' turned into '/'
*/
@trusted nothrow const(char)* toPosixPath(const(char)* src)
{
if (src is null)
return null;
char* result = strdup(src);
char* p = result;
while (*p != '\0')
{
if (*p == '\\')
*p = '/';
p++;
}
return result;
}
/**
* ditto
*/
@safe pure nothrow const(char)[] toPosixPath(const(char)[] src)
{
if (!src)
return null;
char[] result = src.dup;
foreach (ref c; result)
{
if (c == '\\')
c = '/';
}
return result;
}
///
@safe nothrow unittest
{
const(char)[] nullStr;
const(char)* nullStrP;
assert(toPosixPath(nullStrP) == null);
assert(toPosixPath(nullStr) == null);
@trusted nothrow void assertion(const(char)[] s1, const(char)[] s2)
{
assert(toPosixPath(s1) == s2);
assert(strcmp(toPosixPath(s1.ptr), s2.ptr) == 0);
}
const posixAbsPath = `/some/path`;
const posixRelPath = `some/path`;
const windowsAbsPath = `C:\some\path`;
const windowsAbsMixedPath = `C:\some/path`;
const windowsAbsPosixPath = `C:/some/path`;
const windowsRelPath = `some\path`;
assertion(posixAbsPath, posixAbsPath);
assertion(posixRelPath, posixRelPath);
assertion(windowsAbsPath, windowsAbsPosixPath);
assertion(windowsAbsMixedPath, windowsAbsPosixPath);
assertion(windowsAbsPosixPath, windowsAbsPosixPath);
assertion(windowsRelPath, posixRelPath);
}
/**
* Reads a file, terminate the program on error * Reads a file, terminate the program on error
* *
* Params: * Params:
* loc = The line number information from where the call originates * loc = The line number information from where the call originates
* filename = Path to file * filename = Path to file
*/ */
FileBuffer readFile(Loc loc, const(char)* filename) FileBuffer readFile(Loc loc, const(char)* filename)
{ {
return readFile(loc, filename.toDString()); return readFile(loc, filename.toDString());
} }
skipping to change at line 210 skipping to change at line 139
goto default; goto default;
default: default:
buf.writeByte(*fname); buf.writeByte(*fname);
break; break;
} }
fname++; fname++;
} }
} }
/** /**
* Takes a path, and make it compatible with GNU Makefile format.
*
* 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.
*
* Params:
* buf = Buffer to write the escaped path to
* fname = Path to escape
*/
void writeEscapedMakePath(ref OutBuffer buf, const(char)* fname)
{
uint slashes;
while (*fname)
{
switch (*fname)
{
case '\\':
slashes++;
break;
case '$':
buf.writeByte('$');
goto default;
case ' ':
case '\t':
while (slashes--)
buf.writeByte('\\');
goto case;
case '#':
buf.writeByte('\\');
goto default;
case ':':
// ':' not escaped on Windows because it can
// create problems with absolute paths (e.g. C:\Project)
version (Windows) {}
else
{
buf.writeByte('\\');
}
goto default;
default:
slashes = 0;
break;
}
buf.writeByte(*fname);
fname++;
}
}
///
unittest
{
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);
}
/**
* Convert string to integer. * Convert string to integer.
* *
* Params: * Params:
* T = Type of integer to parse * T = Type of integer to parse
* val = Variable to store the result in * val = Variable to store the result in
* p = slice to start of string digits * p = slice to start of string digits
* max = max allowable value (inclusive), defaults to `T.max` * max = max allowable value (inclusive), defaults to `T.max`
* *
* Returns: * Returns:
* `false` on error, `true` on success * `false` on error, `true` on success
 End of changes. 2 change blocks. 
71 lines changed or deleted 74 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)