mirror of
https://github.com/1dot13/source.git
synced 2026-09-02 14:36:06 +02:00
**********************************************************
** Big Maps Projects code (incl. Multiplayer v1.5 ** ********************************************************** - Merged Big Maps Project code from BMP+MP trunk (Revision: 3340) o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - Before THIS merge, I made a branch of the existing 1.13 source o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src - Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago - I will add VS 2010 projects and solution file in the next few days git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+59
-36
@@ -1,9 +1,10 @@
|
||||
#include "Log.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
const char CLog::endl[] = "\r\n";
|
||||
const char CLog::ENDL[] = "\r\n";
|
||||
#else
|
||||
const char CLog::endl[] = "\n";
|
||||
const char CLog::ENDL[] = "\n";
|
||||
#endif
|
||||
|
||||
std::list<CLog*>& CLog::_logs()
|
||||
@@ -12,12 +13,12 @@ std::list<CLog*>& CLog::_logs()
|
||||
return logs;
|
||||
}
|
||||
|
||||
CLog* CLog::Create(vfs::Path fileName, bool append, EFlushMode flushMode)
|
||||
CLog* CLog::create(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
{
|
||||
_logs().push_back(new CLog(fileName, append, flushMode));
|
||||
return _logs().back();
|
||||
}
|
||||
void CLog::FlushFinally()
|
||||
void CLog::flushFinally()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
@@ -27,18 +28,30 @@ void CLog::FlushFinally()
|
||||
_logs().clear();
|
||||
}
|
||||
|
||||
void CLog::FlushAll()
|
||||
void CLog::flushAll()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
{
|
||||
(*it)->Flush();
|
||||
(*it)->flush();
|
||||
(*it)->_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
utf8string CLog::_shared_id_str;
|
||||
|
||||
CLog::CLog(vfs::Path fileName, bool append, EFlushMode flushMode)
|
||||
utf8string const& CLog::getSharedString()
|
||||
{
|
||||
return _shared_id_str;
|
||||
}
|
||||
|
||||
void CLog::setSharedString(utf8string const& str)
|
||||
{
|
||||
_shared_id_str = str;
|
||||
}
|
||||
|
||||
|
||||
CLog::CLog(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
: _filename(fileName), _file(NULL), _own_file(false),
|
||||
_first_write(true), _flush_mode(flushMode), _append(append),
|
||||
_buffer_size(0), _buffer_test_size(512)
|
||||
@@ -55,35 +68,35 @@ CLog::~CLog()
|
||||
|
||||
CLog& CLog::operator<<(unsigned int const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned short const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned char const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(int const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(short const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(char const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(float const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(double const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
|
||||
CLog& CLog::operator<<(const char* t)
|
||||
@@ -125,20 +138,20 @@ CLog& CLog::operator<<(utf8string const& t)
|
||||
return *this;
|
||||
}
|
||||
|
||||
CLog& CLog::Endl()
|
||||
CLog& CLog::endl()
|
||||
{
|
||||
_buffer << CLog::endl;
|
||||
_buffer_size += sizeof(CLog::endl)-1;
|
||||
_buffer << CLog::ENDL;
|
||||
_buffer_size += sizeof(CLog::ENDL)-1;
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CLog::SetAppend(bool append)
|
||||
void CLog::setAppend(bool append)
|
||||
{
|
||||
_append = append;
|
||||
}
|
||||
|
||||
void CLog::SetBufferSize(vfs::UInt32 bufferSize)
|
||||
void CLog::setBufferSize(vfs::UInt32 bufferSize)
|
||||
{
|
||||
_buffer_test_size = bufferSize;
|
||||
}
|
||||
@@ -149,14 +162,14 @@ void CLog::_test_flush(bool force)
|
||||
(_flush_mode == FLUSH_BUFFER && _buffer_size > _buffer_test_size) ||
|
||||
(/*_flush_mode == FLUSH_ON_DELETE &&*/ force == true) )
|
||||
{
|
||||
Flush();
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
#include <ctime>
|
||||
void CLog::Flush()
|
||||
void CLog::flush()
|
||||
{
|
||||
vfs::UInt32 buflen = _buffer.str().length();
|
||||
::size_t buflen = _buffer.str().length();
|
||||
if(buflen == 0)
|
||||
{
|
||||
return;
|
||||
@@ -172,21 +185,26 @@ void CLog::Flush()
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
// write file anyway
|
||||
_file = vfs::tWriteableFile::Cast(new vfs::CFile(_filename));
|
||||
_file->OpenWrite(true,!_append);
|
||||
_own_file = true;
|
||||
try
|
||||
{
|
||||
logException(ex);
|
||||
// write file anyway
|
||||
_file = vfs::tWritableFile::cast(new vfs::CFile(_filename));
|
||||
_file->openWrite(true,!_append);
|
||||
_own_file = true;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vfs::COpenWriteFile wfile(_file);
|
||||
if(_append)
|
||||
{
|
||||
wfile.file().SetWriteLocation(0,vfs::IBaseFile::SD_END);
|
||||
wfile.file().setWritePosition(0,vfs::IBaseFile::SD_END);
|
||||
}
|
||||
|
||||
vfs::UInt32 io;
|
||||
if(_first_write)
|
||||
{
|
||||
time_t rawtime;
|
||||
@@ -194,21 +212,26 @@ void CLog::Flush()
|
||||
std::string datetime(ctime(&rawtime));
|
||||
std::string s_out;
|
||||
|
||||
vfs::UInt32 wloc = wfile.file().GetWriteLocation();
|
||||
vfs::size_t wloc = wfile.file().getWritePosition();
|
||||
if(wloc > 0)
|
||||
{
|
||||
s_out = CLog::endl;
|
||||
s_out = CLog::ENDL;
|
||||
}
|
||||
s_out += " *** ";
|
||||
s_out += datetime.substr(0,datetime.length()-1);
|
||||
s_out += " *** ";
|
||||
s_out += CLog::endl;
|
||||
s_out += CLog::endl;
|
||||
wfile.file().Write(s_out.c_str(), s_out.length(), io);
|
||||
s_out += CLog::ENDL;
|
||||
s_out += "[ ";
|
||||
s_out += _shared_id_str.utf8();
|
||||
s_out += " ]";
|
||||
s_out += CLog::ENDL;
|
||||
s_out += CLog::ENDL;
|
||||
|
||||
wfile.file().write(s_out.c_str(), s_out.length());
|
||||
_first_write = false;
|
||||
}
|
||||
|
||||
wfile.file().Write(_buffer.str().c_str(), buflen, io);
|
||||
wfile.file().write(_buffer.str().c_str(), buflen);
|
||||
_buffer.str("");
|
||||
_buffer.clear();
|
||||
_buffer_size = 0;
|
||||
|
||||
+18
-15
@@ -7,8 +7,7 @@
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
//class CMemoryFile;
|
||||
class CLog
|
||||
class VFS_API CLog
|
||||
{
|
||||
public:
|
||||
enum EFlushMode
|
||||
@@ -19,12 +18,15 @@ public:
|
||||
};
|
||||
public:
|
||||
|
||||
CLog(vfs::Path fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
CLog(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
~CLog();
|
||||
|
||||
static CLog* Create(vfs::Path fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
static void FlushAll();
|
||||
static void FlushFinally();
|
||||
static CLog* create(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
static void flushAll();
|
||||
static void flushFinally();
|
||||
|
||||
static utf8string const& getSharedString();
|
||||
static void setSharedString(utf8string const& str);
|
||||
|
||||
CLog& operator<<(unsigned int const& t);
|
||||
CLog& operator<<(unsigned short const& t);
|
||||
@@ -41,35 +43,36 @@ public:
|
||||
CLog& operator<<(std::wstring const& t);
|
||||
CLog& operator<<(utf8string const& t);
|
||||
|
||||
CLog& Endl();
|
||||
static const char endl[];
|
||||
CLog& endl();
|
||||
static const char ENDL[];
|
||||
|
||||
void SetAppend(bool append = true);
|
||||
void SetBufferSize(vfs::UInt32 bufferSize);
|
||||
void setAppend(bool append = true);
|
||||
void setBufferSize(vfs::UInt32 bufferSize);
|
||||
|
||||
void Flush();
|
||||
void flush();
|
||||
private:
|
||||
void _test_flush(bool force=false);
|
||||
|
||||
template<typename T_>
|
||||
CLog& PushNumber(T_ const& t)
|
||||
CLog& pushNumber(T_ const& t)
|
||||
{
|
||||
_buffer << ToString<char>(t);
|
||||
_buffer << toString<char>(t);
|
||||
_buffer_size += sizeof(T_);
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
vfs::Path _filename;
|
||||
vfs::tWriteableFile* _file;
|
||||
vfs::tWritableFile* _file;
|
||||
bool _own_file;
|
||||
bool _first_write;
|
||||
EFlushMode _flush_mode;
|
||||
bool _append;
|
||||
vfs::UInt32 _buffer_size, _buffer_test_size;
|
||||
::size_t _buffer_size, _buffer_test_size;
|
||||
std::stringstream _buffer;
|
||||
private:
|
||||
static std::list<CLog*>& _logs();
|
||||
static utf8string _shared_id_str;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+94
-70
@@ -4,6 +4,8 @@
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
@@ -11,41 +13,63 @@ CReadLine::CReadLine(vfs::tReadableFile& rFile)
|
||||
: _file(rFile), _buffer_pos(0), _eof(false)
|
||||
{
|
||||
memset(_buffer,0,sizeof(_buffer));
|
||||
FillBuffer();
|
||||
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
_bytes_left = rfile.file().getSize();
|
||||
fillBuffer();
|
||||
vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
if(memcmp(utf8bom, &_buffer[0],3) == 0)
|
||||
{
|
||||
_buffer_pos += 3;
|
||||
}
|
||||
rfile.release();
|
||||
};
|
||||
|
||||
bool CReadLine::FillBuffer()
|
||||
CReadLine::~CReadLine()
|
||||
{
|
||||
if(!_eof)
|
||||
if(_file.isOpenRead())
|
||||
{
|
||||
// reading can be done byte-wise or line-wise.
|
||||
// we have no control over this here, so we have to account for both cases.
|
||||
|
||||
vfs::UInt32 read = 0;
|
||||
// fill the buffer from the start, BUFFER_SIZE charactes at max (_buffer has BUFFER_SIZE+1 elements)
|
||||
_eof = !_file.Read(&_buffer[0],BUFFER_SIZE,read);
|
||||
// if read() fails, it means that we are at the end of the file,
|
||||
// but we probably have read a couple of valid bytes, so we need to do one last 'correct' run
|
||||
|
||||
// bite-wise read files usually terminate a line with \n (or \r\n on WIN32)
|
||||
// line-wise read files just returns 0-terminated string
|
||||
|
||||
// always terminate the string with 0
|
||||
_buffer[read] = 0;
|
||||
|
||||
_buffer_pos = 0;
|
||||
_buffer_last = read;
|
||||
return true;
|
||||
_file.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CReadLine::FromBuffer(std::string& line)
|
||||
bool CReadLine::fillBuffer()
|
||||
{
|
||||
if(_eof)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::size_t bytesRead = BUFFER_SIZE < _bytes_left ? BUFFER_SIZE : _bytes_left;
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
|
||||
// fill the buffer from the start, BUFFER_SIZE charactes at max (_buffer has BUFFER_SIZE+1 elements)
|
||||
THROWIFFALSE(bytesRead == _file.read(&_buffer[0], bytesRead), L"");
|
||||
rfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
|
||||
_bytes_left -= bytesRead;
|
||||
_eof = (_bytes_left == 0);
|
||||
|
||||
|
||||
// bite-wise read files usually terminate a line with \n (or \r\n on WIN32)
|
||||
// line-wise read files just returns 0-terminated string
|
||||
|
||||
// always terminate the string with 0
|
||||
_buffer[bytesRead] = 0;
|
||||
|
||||
_buffer_pos = 0;
|
||||
_buffer_last = bytesRead;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CReadLine::fromBuffer(std::string& line)
|
||||
{
|
||||
bool done = false;
|
||||
while(!done)
|
||||
@@ -54,7 +78,7 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
{
|
||||
// start where we left last time
|
||||
vfs::Byte *temp = &_buffer[_buffer_pos];
|
||||
vfs::UInt32 start_pos = _buffer_pos;
|
||||
vfs::size_t start_pos = _buffer_pos;
|
||||
// go until we hit 0. since our buffer is always 0 terminated, the second test should be redundant.
|
||||
while(*temp && (_buffer_pos < _buffer_last))
|
||||
{
|
||||
@@ -87,7 +111,7 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else if(*temp == '\n' || *temp == 0)
|
||||
@@ -99,47 +123,47 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CReadLine::GetLine(std::string& line)
|
||||
bool CReadLine::getLine(std::string& line)
|
||||
{
|
||||
line.clear();
|
||||
return FromBuffer(line);
|
||||
return fromBuffer(line);
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
CSplitStringList::CSplitStringList(utf8string const& sList)
|
||||
: m_sList(sList), iCurrent(0),iNext(0)
|
||||
: m_list(sList), current(0), next(0)
|
||||
{};
|
||||
|
||||
CSplitStringList::~CSplitStringList()
|
||||
{};
|
||||
|
||||
bool CSplitStringList::NextListEntry(utf8string &sEntry)
|
||||
bool CSplitStringList::nextListEntry(utf8string &sEntry)
|
||||
{
|
||||
if(iNext >= 0)
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
iNext = m_sList.c_wcs().find_first_of(L",",iCurrent+1);
|
||||
if(iNext > iCurrent)
|
||||
next = m_list.c_wcs().find_first_of(L",", current+1);
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
sEntry.r_wcs().assign(vfs::TrimString(m_sList,iCurrent,iNext-1).c_wcs());
|
||||
iCurrent = iNext+1;
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,next-1).c_wcs());
|
||||
current = next+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// last or only entry
|
||||
sEntry.r_wcs().assign(vfs::TrimString(m_sList,iCurrent,m_sList.length()).c_wcs());
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,m_list.length()).c_wcs());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -154,20 +178,20 @@ CTransferRules::CTransferRules()
|
||||
{};
|
||||
|
||||
|
||||
bool CTransferRules::InitFromTxtFile(vfs::Path const& sPath)
|
||||
bool CTransferRules::initFromTxtFile(vfs::Path const& sPath)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(GetVFS()->FileExists(sPath))
|
||||
if(getVFS()->fileExists(sPath))
|
||||
{
|
||||
return InitFromTxtFile(GetVFS()->GetRFile(sPath));
|
||||
return initFromTxtFile(getVFS()->getReadFile(sPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CTextFile(sPath);
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sPath);
|
||||
if(pFile)
|
||||
{
|
||||
bool success = InitFromTxtFile(vfs::tReadableFile::Cast(pFile));
|
||||
bool success = initFromTxtFile(vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
return success;
|
||||
}
|
||||
@@ -175,22 +199,22 @@ bool CTransferRules::InitFromTxtFile(vfs::Path const& sPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
bool CTransferRules::initFromTxtFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(pFile && pFile->OpenRead())
|
||||
if(pFile && pFile->openRead())
|
||||
{
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
std::string sBuffer;
|
||||
vfs::UInt32 line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.GetLine(sBuffer))
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
@@ -200,7 +224,7 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
// comment -> do nothing
|
||||
break;
|
||||
default:
|
||||
int iEnd = sBuffer.find_first_of(" \t", iStart);
|
||||
::size_t iEnd = sBuffer.find_first_of(" \t", iStart);
|
||||
if(iEnd != std::string::npos)
|
||||
{
|
||||
SRule rule;
|
||||
@@ -218,18 +242,18 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
std::wstring trybuffer = L"Invalid UTF-8 character in string";
|
||||
IGNOREEXCEPTION( trybuffer = utf8string(sBuffer).c_wcs() ); /* just make sure we don't break off when string conversion fails */
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown action in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Unknown action in file \"" << pFile->getPath().c_wcs()
|
||||
<< L", line " << line_counter << " : " << utf8string(sBuffer).c_wcs();
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
try
|
||||
{
|
||||
rule.pattern = vfs::Path(vfs::TrimString(sBuffer, iEnd, sBuffer.length()));
|
||||
rule.pattern = vfs::Path(vfs::trimString(sBuffer, iEnd, sBuffer.length()));
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not convert string, invalid utf8 encoding in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Could not convert string, invalid utf8 encoding in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
@@ -244,22 +268,22 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CTransferRules::SetDefaultAction(CTransferRules::EAction act)
|
||||
void CTransferRules::setDefaultAction(CTransferRules::EAction act)
|
||||
{
|
||||
m_eDefaultAction = act;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::GetDefaultAction()
|
||||
CTransferRules::EAction CTransferRules::getDefaultAction()
|
||||
{
|
||||
return m_eDefaultAction;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::ApplyRule(utf8string const& sStr)
|
||||
CTransferRules::EAction CTransferRules::applyRule(utf8string const& sStr)
|
||||
{
|
||||
tPatternList::iterator sit = m_listRules.begin();
|
||||
for(; sit != m_listRules.end(); ++sit)
|
||||
{
|
||||
if(MatchPattern(sit->pattern(), sStr))
|
||||
if(matchPattern(sit->pattern(), sStr))
|
||||
{
|
||||
return sit->action;
|
||||
}
|
||||
@@ -275,7 +299,7 @@ CTransferRules::EAction CTransferRules::ApplyRule(utf8string const& sStr)
|
||||
typedef vfs::UInt16 UINT16;
|
||||
extern UINT16 gsKeyTranslationTable[1024];
|
||||
|
||||
CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, size_t startPos)
|
||||
CodePageReader::EMode CodePageReader::extractMode(std::string const &readStr, size_t startPos)
|
||||
{
|
||||
vfs::Int32 iEqual = readStr.find_first_of("=",startPos);
|
||||
if(iEqual < 0)
|
||||
@@ -283,14 +307,14 @@ CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, si
|
||||
return Error;
|
||||
}
|
||||
// extract keyword
|
||||
std::string key = vfs::TrimString(readStr,0,iEqual-1);
|
||||
std::string key = vfs::trimString(readStr,0,iEqual-1);
|
||||
if(!StrCmp::Equal(key, "mode"))
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
// extract mode
|
||||
EMode mode = Error;
|
||||
std::string sMode = vfs::TrimString(readStr,iEqual+1,readStr.size());
|
||||
std::string sMode = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
if(StrCmp::Equal(sMode, "normal"))
|
||||
{
|
||||
mode = Normal;
|
||||
@@ -310,7 +334,7 @@ CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, si
|
||||
return mode;
|
||||
}
|
||||
|
||||
bool CodePageReader::ExtractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s)
|
||||
bool CodePageReader::extractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s)
|
||||
{
|
||||
vfs::Int32 iEqual = str.find_first_of("=",iStart);
|
||||
if(iEqual < 0)
|
||||
@@ -341,9 +365,9 @@ bool CodePageReader::ExtractCode(std::string const& str, int iStart, vfs::UInt32
|
||||
return true;
|
||||
}
|
||||
|
||||
void CodePageReader::ReadCodePage(vfs::Path const& codepagefile)
|
||||
void CodePageReader::readCodePage(vfs::Path const& codepagefile)
|
||||
{
|
||||
if(!GetVFS()->FileExists(codepagefile))
|
||||
if(!GetVFS()->fileExists(codepagefile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -416,7 +440,7 @@ namespace charSet
|
||||
static std::map<ECharSet,std::set<wchar_t> > _sets;
|
||||
};
|
||||
|
||||
inline bool TestSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
inline bool testSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
{
|
||||
if(char_set & es)
|
||||
{
|
||||
@@ -426,20 +450,20 @@ inline bool TestSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool charSet::IsFromSet(char wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(char wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::isFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::isFromSet(int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::IsFromSet(int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::IsFromSet(unsigned int wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(unsigned int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
|
||||
bool charSet::IsFromSet(wchar_t wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(wchar_t wc, unsigned int char_set)
|
||||
{
|
||||
bool inSet = false;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPACE, wc)) return true;
|
||||
@@ -452,7 +476,7 @@ bool charSet::IsFromSet(wchar_t wc, unsigned int char_set)
|
||||
return false;
|
||||
}
|
||||
|
||||
void charSet::AddToCharSet(ECharSet eset, std::wstring cset)
|
||||
void charSet::addToCharSet(ECharSet eset, std::wstring cset)
|
||||
{
|
||||
std::set<wchar_t>& wcset = charSet::_sets[eset];
|
||||
for(unsigned int i = 0; i < cset.length(); ++i)
|
||||
@@ -461,7 +485,7 @@ void charSet::AddToCharSet(ECharSet eset, std::wstring cset)
|
||||
}
|
||||
}
|
||||
|
||||
void charSet::InitializeCharSets()
|
||||
void charSet::initializeCharSets()
|
||||
{
|
||||
charSet::AddToCharSet(charSet::CS_SPACE, L" ");
|
||||
charSet::AddToCharSet(charSet::CS_ALPHA_LC, L"abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
+20
-14
@@ -8,22 +8,26 @@
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
const vfs::UInt32 BUFFER_SIZE = 1024;
|
||||
const vfs::size_t BUFFER_SIZE = 1024;
|
||||
|
||||
class CReadLine
|
||||
{
|
||||
public:
|
||||
CReadLine(vfs::tReadableFile& rFile);
|
||||
~CReadLine();
|
||||
|
||||
bool FillBuffer();
|
||||
bool FromBuffer(std::string& line);
|
||||
bool GetLine(std::string& line);
|
||||
bool fillBuffer();
|
||||
bool fromBuffer(std::string& line);
|
||||
bool getLine(std::string& line);
|
||||
private:
|
||||
vfs::Byte _buffer[BUFFER_SIZE+1];
|
||||
vfs::tReadableFile& _file;
|
||||
vfs::UInt32 _buffer_pos;
|
||||
vfs::UInt32 _buffer_last;
|
||||
vfs::size_t _bytes_left;
|
||||
vfs::size_t _buffer_pos;
|
||||
vfs::size_t _buffer_last;
|
||||
bool _eof;
|
||||
|
||||
void operator=(CReadLine const& rl);
|
||||
};
|
||||
|
||||
/**************************************************************/
|
||||
@@ -35,10 +39,12 @@ public:
|
||||
CSplitStringList(utf8string const& sList);
|
||||
~CSplitStringList();
|
||||
|
||||
bool NextListEntry(utf8string &sEntry);
|
||||
bool nextListEntry(utf8string &sEntry);
|
||||
private:
|
||||
const utf8string m_sList;
|
||||
int iCurrent,iNext;
|
||||
const utf8string m_list;
|
||||
utf8string::size_t current,next;
|
||||
|
||||
void operator=(CSplitStringList const& strlist);
|
||||
};
|
||||
|
||||
|
||||
@@ -56,13 +62,13 @@ public:
|
||||
public:
|
||||
CTransferRules();
|
||||
|
||||
bool InitFromTxtFile(vfs::Path const& sPath);
|
||||
bool InitFromTxtFile(vfs::tReadableFile* pFile);
|
||||
bool initFromTxtFile(vfs::Path const& sPath);
|
||||
bool initFromTxtFile(vfs::tReadableFile* pFile);
|
||||
|
||||
void SetDefaultAction(EAction act);
|
||||
EAction GetDefaultAction();
|
||||
void setDefaultAction(EAction act);
|
||||
EAction getDefaultAction();
|
||||
|
||||
EAction ApplyRule(utf8string const& sStr);
|
||||
EAction applyRule(utf8string const& sStr);
|
||||
private:
|
||||
struct SRule
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#include "Tools.h"
|
||||
|
||||
template<>
|
||||
utf8string ToStringList<utf8string>(std::list<utf8string> const& rValList)
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
std::list<utf8string>::const_iterator cit = rValList.begin();
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
#include <list>
|
||||
|
||||
template<typename CharType, typename ValueType>
|
||||
std::basic_string<CharType> ToString(ValueType const& rVal)
|
||||
std::basic_string<CharType> toString(ValueType const& rVal)
|
||||
{
|
||||
std::basic_stringstream<CharType> tss;
|
||||
if( !(tss << rVal))
|
||||
@@ -16,7 +16,7 @@ std::basic_string<CharType> ToString(ValueType const& rVal)
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
bool ConvertTo(utf8string const& sStr, T_ &rVal)
|
||||
bool convertTo(utf8string const& sStr, T_ &rVal)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
ss.str(sStr.c_wcs());
|
||||
@@ -28,7 +28,7 @@ bool ConvertTo(utf8string const& sStr, T_ &rVal)
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
utf8string ToStringList(std::list<T_> const& rValList)
|
||||
utf8string toStringList(std::list<T_> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
typename std::list<T_>::const_iterator cit = rValList.begin();
|
||||
@@ -49,6 +49,6 @@ utf8string ToStringList(std::list<T_> const& rValList)
|
||||
}
|
||||
|
||||
template<>
|
||||
utf8string ToStringList<utf8string>(std::list<utf8string> const& rValList);
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList);
|
||||
|
||||
#endif // _TOOLS_H_
|
||||
|
||||
Reference in New Issue
Block a user