FileFlags.parse

Parses an fopen-style mode string such as "r+". All possible mode strings include:

Mode StringMeaning
"wb"Write truncated
"wb+"Read/write truncated
"w+b"Read/write truncated
"wbx"Write new
"wb+x"Read/write new
"w+bx"Read/write new
"rb"Read existing"
"rb+"Read/write existing"
"r+b"Read/write existing"
"ab"Append new"
"ab+"Append/read new"
"a+b"Append/read new"

The _mode strings accepted here differ from those accepted by fopen. Here, file streams are never opened in text _mode -- only binary mode. Text handling functionality is built on top of low-level file streams. It does not make sense to distinguish between text and binary modes here. fopen opens all files in text _mode by default and the flag 'b' must be specified in order to open in binary _mode. Thus, an exception is thrown here if 'b' is omitted in the specified mode string.

Note: It is not advisable to use fopen-style _mode strings. It is better to use one of the predefined file flag configurations such as FileFlags.readExisting for greater readability and intent of meaning.

struct FileFlags
static pure
parse
(
string mode
)

Examples

static assert(FileFlags("wb")   == FileFlags.writeEmpty);
static assert(FileFlags("wb+")  == FileFlags.readWriteEmpty);
static assert(FileFlags("w+b")  == FileFlags.readWriteEmpty);
static assert(FileFlags("wbx")  == FileFlags.writeNew);
static assert(FileFlags("wb+x") == FileFlags.readWriteNew);
static assert(FileFlags("w+bx") == FileFlags.readWriteNew);
static assert(FileFlags("rb")   == FileFlags.readExisting);
static assert(FileFlags("rb+")  == FileFlags.readWriteExisting);
static assert(FileFlags("r+b")  == FileFlags.readWriteExisting);
static assert(FileFlags("ab")   == FileFlags(Mode.openOrCreate | Mode.append, Access.write));
static assert(FileFlags("ab+")  == FileFlags(Mode.openOrCreate | Mode.append, Access.readWrite));
static assert(FileFlags("a+b")  == FileFlags(Mode.openOrCreate | Mode.append, Access.readWrite));

Meta