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:
Denis Shelomovskij 2012-09-11 20:31:05 +04:00
parent e281d8deaa
commit 13a87ff8ca

View file

@ -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');
}