bool EncodingTable::load(const std::wstring& fileName, TextFile::Encoding encoding) { unsigned char hexBuffer[MAXHEXLENGTH]; TextFile input; if (input.open(fileName,TextFile::Read,encoding) == false) return false; hexData.clear(); valueData.clear(); entries.clear(); setTerminationEntry((unsigned char*)"\0",1); while (!input.atEnd()) { std::wstring line = input.readLine(); if (line.empty() || line[0] == '*') continue; if (line[0] == '/') { std::wstring hex = line.substr(1); if (hex.empty() || hex.length() > 2*MAXHEXLENGTH) { // error continue; } int length = parseHexString(hex,hexBuffer); if (length == -1) { // error continue; } setTerminationEntry(hexBuffer,length); } else { size_t pos = line.find(L'='); std::wstring hex = line.substr(0,pos); std::wstring value = line.substr(pos+1); if (hex.empty() || value.empty() || hex.length() > 2*MAXHEXLENGTH) { // error continue; } int length = parseHexString(hex,hexBuffer); if (length == -1) { // error continue; } addEntry(hexBuffer,length,value); } } return true; }
void SynonymMap::load(const string& sFileName) { close(); TextFile tf; tf.open(sFileName.c_str(), "r"); char szLine[512]; if(tf.isFileOpen()) { while(!tf.isEof() && tf.readLine(szLine, 512, true) > 0) { StringTokenizer st(szLine, ":", StringTokenizer::TOKEN_TRIM | StringTokenizer::TOKEN_IGNORE_EMPTY ); if(st.getNumTokens() != 2) continue; addSynonyms(st[0].c_str(), st[1].c_str()); } } }
bool GetLine(TextFile& Input, std::wstring& dest) { std::wstring Buffer = Input.readLine(); dest = L""; if (Input.hasError()) Logger::printError(Logger::Warning,Input.getErrorText()); int InputPos = 0; while (InputPos < (int)Buffer.size() && (Buffer[InputPos] == '\t' || Buffer[InputPos] == ' ')) InputPos++; while (InputPos < (int)Buffer.size() && CheckEndLine(Buffer,InputPos) == false) { switch (Buffer[InputPos]) { case ' ': case '\t': while (InputPos < (int)Buffer.size() && (Buffer[InputPos] == '\t' || Buffer[InputPos] == ' ')) InputPos++; if (CheckEndLine(Buffer,InputPos) == true) { return true; } dest += ' '; break; case '"': // string dest += towlower(Buffer[InputPos++]); while (InputPos < (int)Buffer.size() && Buffer[InputPos] != '"') { if (InputPos+1 < (int)Buffer.size() && Buffer[InputPos] == '\\' && Buffer[InputPos+1] == '"') { dest += '\\'; dest += '"'; InputPos += 2; continue; } if (InputPos+1 < (int)Buffer.size() && Buffer[InputPos] == '\\' && Buffer[InputPos+1] == '\\') { dest += '\\'; dest += '\\'; InputPos += 2; continue; } if (Buffer[InputPos] == '\n' || Buffer[InputPos] == 0) { Logger::printError(Logger::Error,L"Unexpected end of line in string constant"); return false; } dest += Buffer[InputPos++]; } if (InputPos == (int)Buffer.size()) { Logger::printError(Logger::Error,L"Unexpected end of line in string constant"); return false; } dest += towlower(Buffer[InputPos++]); break; case '\'': if (Buffer[InputPos+2] == '\'') { dest += Buffer[InputPos++]; dest += Buffer[InputPos++]; dest += Buffer[InputPos++]; } else { Logger::printError(Logger::Error,L"Invalid character constant"); return false; } break; default: dest += towlower(Buffer[InputPos++]); break; } } return true; }