mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +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
116 lines
3.2 KiB
C++
116 lines
3.2 KiB
C++
#include "vfs_types.h"
|
|
#include "vfs_debug.h"
|
|
|
|
#include <vector>
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
namespace vfs
|
|
{
|
|
const vfs::size_t npos = vfs::size_t(-1);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
template<>
|
|
std::string vfs::trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
|
{
|
|
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
|
{
|
|
return "";
|
|
}
|
|
::size_t iStart,iEnd;
|
|
iStart = sStr.find_first_not_of(" \t\r\n",(::size_t)iMinPos);
|
|
iEnd = sStr.find_last_not_of(" \t\r\n",(::size_t)iMaxPos);
|
|
if( (iStart != std::string::npos) && (iEnd != std::string::npos) )
|
|
{
|
|
return sStr.substr(iStart,iEnd-iStart+1);
|
|
}
|
|
return "";
|
|
}
|
|
template<>
|
|
std::wstring vfs::trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
|
{
|
|
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
|
{
|
|
return L"";
|
|
}
|
|
::size_t iStart,iEnd;
|
|
iStart = sStr.find_first_not_of(L" \t\r\n",(::size_t)iMinPos);
|
|
iEnd = sStr.find_last_not_of(L" \t\r\n",(::size_t)iMaxPos);
|
|
if( (iStart != std::wstring::npos) && (iEnd != std::wstring::npos) )
|
|
{
|
|
return sStr.substr(iStart,iEnd-iStart+1);
|
|
}
|
|
return L"";
|
|
}
|
|
template<>
|
|
utf8string vfs::trimString<utf8string>(utf8string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
|
{
|
|
return vfs::trimString(sStr.c_wcs(), iMinPos, iMaxPos);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
template<>
|
|
BuildString& BuildString::add<utf8string>(utf8string const& value)
|
|
{
|
|
this->add(value.c_str());
|
|
return *this;
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|
|
/**
|
|
* try to recursively match the pattern
|
|
*/
|
|
bool matchPattern(utf8string const& sPattern, utf8string const& sStr)
|
|
{
|
|
return matchPattern(sPattern,sStr.c_wcs());
|
|
}
|
|
|
|
bool matchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
|
{
|
|
utf8string::str_t const& pat = sPattern.c_wcs();
|
|
|
|
utf8string::size_t star = pat.find_first_of(vfs::Const::STAR());
|
|
if(star == utf8string::str_t::npos)
|
|
{
|
|
return StrCmp::Equal( pat, sStr );
|
|
}
|
|
else if(star == 0)
|
|
{
|
|
if(pat.length() == 1)
|
|
{
|
|
// there is only the '*' -> matches all strings
|
|
return true;
|
|
}
|
|
utf8string::char_t atpos1 = pat.at(1);
|
|
utf8string::size_t match = utf8string::size_t(-1);
|
|
do
|
|
{
|
|
match = sStr.find_first_of(atpos1,match+1);
|
|
if(match == utf8string::str_t::npos)
|
|
{
|
|
return false;
|
|
}
|
|
} while(!matchPattern( pat.substr(1,pat.length()-1), sStr.substr(match,sStr.length()-match) ));
|
|
return true;
|
|
}
|
|
else // if(star > 0)
|
|
{
|
|
// check if characters before * match
|
|
if(!StrCmp::Equal(pat.substr(0,star), sStr.substr(0,star)) )
|
|
{
|
|
return false;
|
|
}
|
|
return matchPattern( pat.substr(star,pat.length()-star), sStr.substr(star,sStr.length()-star) );
|
|
}
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|