Function isTextualData

Check if data seems to be textual. Can be used to choose whether to use text/plain or application/octet-stream as fallback.

bool isTextualData (
  scope const(void)[] data
) pure nothrow @trusted;

Returns

True if data seems to be textual, false otherwise.

Note

Empty data is not considered to be textual.

Example

assert(isTextualData("English"));
assert(isTextualData("日本語"));
assert(isTextualData("Русский язык"));
assert(isTextualData("English and кириллица"));
assert(isTextualData("Copyright ©"));
assert(isTextualData("0A a!\n\r\t~(){}.?"));
assert(isTextualData("Hello \U0001F603"));

assert(isTextualData("日本語"[0..$-1]));
assert(isTextualData("Русский язык"[0..$-1]));
assert(isTextualData("Hello \U0001F603"[0..$-1]));
assert(isTextualData("text \u00A2"[0..$-1]));

assert(!isTextualData("text\U000F0000text"));//private use

assert(!isTextualData(""));
assert(!isTextualData("abc\x01"));
assert(!isTextualData("\xFF\xFE"));
assert(!isTextualData("\xd0\x54"));
assert(!isTextualData("\x10"));