mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
Improve std.stdio.File.{writef,writefln}
* don't throw AssertError in writef * make these functions consistent with std.format.formattedWrite
This commit is contained in:
parent
e281d8deaa
commit
13a87ff8ca
1 changed files with 4 additions and 16 deletions
20
std/stdio.d
20
std/stdio.d
|
@ -720,33 +720,21 @@ arguments in text format to the file, followed by a newline. */
|
|||
write(args, '\n');
|
||||
}
|
||||
|
||||
private enum errorMessage =
|
||||
"You must pass a formatting string as the first"
|
||||
" argument to writef or writefln. If no formatting is needed,"
|
||||
" you may want to use write or writeln.";
|
||||
|
||||
/**
|
||||
If the file is not opened, throws an exception. Otherwise, writes its
|
||||
arguments in text format to the file, according to the format in the
|
||||
first argument. */
|
||||
void writef(S...)(S args) // if (isSomeString!(S[0]))
|
||||
void writef(Char, A...)(in Char[] fmt, A args)
|
||||
{
|
||||
assert(_p);
|
||||
assert(_p.handle);
|
||||
static assert(S.length>0, errorMessage);
|
||||
static assert(isSomeString!(S[0]) && !is(S[0] == enum), errorMessage);
|
||||
auto w = lockingTextWriter;
|
||||
std.format.formattedWrite(w, args);
|
||||
std.format.formattedWrite(lockingTextWriter, fmt, args);
|
||||
}
|
||||
|
||||
/**
|
||||
Same as writef, plus adds a newline. */
|
||||
void writefln(S...)(S args)
|
||||
void writefln(Char, A...)(in Char[] fmt, A args)
|
||||
{
|
||||
static assert(S.length>0, errorMessage);
|
||||
static assert(isSomeString!(S[0]) && !is(S[0] == enum), errorMessage);
|
||||
auto w = lockingTextWriter;
|
||||
std.format.formattedWrite(w, args);
|
||||
std.format.formattedWrite(w, fmt, args);
|
||||
w.put('\n');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue