void Text::readWordsfromFile(wifstream & file) {
    // Zeile auf dem Mac auskommentieren.
    file.imbue(locale("de_DE.UTF-8"));
    if (file.good()) {
        readWordsFromStream(file);
    }
    else {
        wcout << "Problem mit der Datei" << endl;
    }
}
예제 #2
0
void Utils::openFile(const string& filepath, wifstream& stream, bool verbose)
{
    unsigned char buffer[FILE_TEST_SIZE];
    const unsigned long long fileLength = getFileSize(filepath);
    const size_t bytes = fileLength < FILE_TEST_SIZE ? (size_t)fileLength : FILE_TEST_SIZE;
    ifstream fin(filepath, ifstream::binary);
    fin.read((char*)buffer, bytes);
    fin.close();

    AutoIt::TextEncodingDetect encodingDetector;
    AutoIt::TextEncodingDetect::Encoding encoding = encodingDetector.DetectEncoding(buffer, bytes);
    if (verbose) {
        dumpEncodingType(encoding);
    }
    switch (encoding) {
        // UTF-16
        case AutoIt::TextEncodingDetect::UTF16_LE_BOM:
        case AutoIt::TextEncodingDetect::UTF16_LE_NOBOM:
        case AutoIt::TextEncodingDetect::UTF16_BE_BOM:
        case AutoIt::TextEncodingDetect::UTF16_BE_NOBOM:
        #if defined(_WIN32) || defined(WIN32) // Windows
            stream.open(filepath, ios::binary);
            stream.imbue(locale(fin.getloc(), new codecvt_utf16<wchar_t, 0x10ffff, consume_header>));
            break;
        #else
            throw runtime_error("Converting UTF-16 encoded files is not supported on your platform.");
        #endif

        case AutoIt::TextEncodingDetect::UTF8_BOM:
        case AutoIt::TextEncodingDetect::UTF8_NOBOM:
            stream.open(filepath);
            stream.imbue(locale(fin.getloc(), new codecvt_utf8<wchar_t, 0x10ffff, consume_header>));
            break;

            // ASCII, ANSI, none
        default:
            stream.open(filepath);
            stream.imbue(locale(fin.getloc(), new codecvt<wchar_t, char, mbstate_t>));
            break;
    }
}