Assertion from fileNeedsCppSyntaxHighlighting


#1

When clicking a text file that's navigatable in the project, the Introjucer assumes it's a libc++ header with no extension.

Sadly, text files can contain UTF8 data, which asserts in the String class when opened by the function fileNeedsCppSyntaxHighlighting.

In other words, this is what you have:

bool fileNeedsCppSyntaxHighlighting (const File& file)
{
    if (file.hasFileExtension (sourceOrHeaderFileExtensions))
        return true;

    // This is a bit of a bodge to deal with libc++ headers with no extension..
    char fileStart[64] = { 0 };
    FileInputStream fin (file);
    fin.read (fileStart, sizeof (fileStart) - 4);

    return String (fileStart).trimStart().startsWith ("// -*- C++ -*-");
}

This is what I think you should have:


bool fileNeedsCppSyntaxHighlighting (const File& file)
{
    if (file.hasFileExtension (sourceOrHeaderFileExtensions))
        return true;

    if (file.hasFileExtension ("txt"))
        return false;

    // This is a bit of a bodge to deal with libc++ headers with no extension..
    char fileStart[64] = { 0 };
    FileInputStream fin (file);
    fin.read (fileStart, sizeof (fileStart) - 4);

    return String (fileStart).trimStart().startsWith ("// -*- C++ -*-");
}

#2

Sadly, text files can contain UTF8 data, which asserts in the String class

In this case, perhaps it should check for the presence of non-ASCII characters rather than the file extension .txt?


#3

Yeah, I'll change it to this:

    return CharPointer_UTF8::isValidString (fileStart, sizeof (fileStart))
             && String (fileStart).trimStart().startsWith ("// -*- C++ -*-");