| 1 |
immutable(T)[] assumeUnique(T)(ref T[] array) pure nothrow |
| 2 |
{ |
| 3 |
auto result = cast(immutable(T)[]) array; |
| 4 |
array = null; |
| 5 |
return result; |
| 6 |
} |
| 7 |
|
| 8 |
pure nothrow |
| 9 |
private string escapeShellArguments() |
| 10 |
{ |
| 11 |
char[] buf; |
| 12 |
|
| 13 |
@safe nothrow |
| 14 |
char[] allocator(size_t size) |
| 15 |
{ |
| 16 |
return buf = new char[size]; |
| 17 |
} |
| 18 |
|
| 19 |
escapeShellArgument!allocator("foo"); |
| 20 |
return assumeUnique(buf); |
| 21 |
} |
| 22 |
|
| 23 |
@safe nothrow |
| 24 |
auto escapeShellArgument(alias allocator)(in char[] arg) |
| 25 |
{ |
| 26 |
auto buf = allocator(4); |
| 27 |
buf[0] = 'f'; |
| 28 |
buf[1] = 'o'; |
| 29 |
buf[2] = 'o'; |
| 30 |
buf[3] = '\0'; |
| 31 |
} |
| 32 |
|
| 33 |
void main() |
| 34 |
{ |
| 35 |
string res = escapeShellArguments(); |
| 36 |
if (res != "foo\0") assert(0); |
| 37 |
} |