示例#1
0
bool LexicsCutter::_ReadLetterAnalogs(const std::string& fileName)
{
    char szLine[1024];

    FILE* file = fopen(fileName.c_str(), "rb");
    if (!file)
        return false;

    while (!feof(file))
    {
        szLine[0] = 0x0;
        fgets(szLine, 1020, file);

        std::string line;
        if (!_ProcessLine(szLine, line))
            continue;

        std::string ch;
        unsigned int pos = 0;
        if (ReadUTF8(line, ch, pos))
        {
            // Create analogs vector
            std::string analog;
            LC_AnalogVector av;
            while (ReadUTF8(line, analog, pos))
                av.push_back(analog);

            // Store vector in hash map
            _analogMap[ch] = av;
        }
    }
    fclose(file);
    return true;
}
示例#2
0
bool LexicsCutter::Read_Letter_Analogs(std::string& FileName)
{
    FILE *ma_file;
    char line[1024];
    unsigned int pos;
    std::string line_s;
    std::string lchar;
    std::string lanalog;

    ma_file = fopen(FileName.c_str(), "rb");

    while (!feof(ma_file))
    {
        line[0] = 0x0;
        fgets(line, 1020, ma_file);

        // check for UTF8 prefix and comments
        if (strlen(line) >= 3)
        {
            if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF')
            {
                strncpy(&line[0], &line[3], strlen(line) - 3);
            }
        }

        if (strlen(line) >= 2)
        {
            if (line[0] == '/' && line[1] == '/') continue;
        }

        // check for empty string
        line_s = line;
        line_s = trim(line_s, "\x0A\x0D\x20");
        if (line_s == "") continue;

        // process line without CR/LF
        line_s = line;
        line_s = trim(line_s, "\x0A\x0D");

        pos = 0;
        if (ReadUTF8(line_s, lchar, pos))
        {
            // create analogs vector
            LC_AnalogVector av;
            while (ReadUTF8(line_s, lanalog, pos))
            {
                av.push_back(lanalog);
            }

            // store vector in hash map
            AnalogMap[lchar] = av;
        }
    }

    fclose(ma_file);

    return true;
}