Пример #1
0
CTokenizer::CTokenizer(const tstring& p_Str, const tstring& p_Delimiters)
{
	const tstring::size_type len = p_Str.length();
	tstring::size_type i = 0;

	while(i < len)
	{
		// eat leading whitespace
		i = p_Str.find_first_not_of(p_Delimiters, i);
		if(i == tstring::npos)
			return;   // nothing left but white space

		// find the end of the token
		tstring::size_type j = p_Str.find_first_of(p_Delimiters, i);

		// push token
		if(j == tstring::npos) 
		{
			m_Tokens.push_back(p_Str.substr(i));
			return;
		} else
			m_Tokens.push_back(p_Str.substr(i, j - i));

		// set up for next loop
		i = j + 1;
	}
}
Пример #2
0
BOOL CRegistryTool::RegPathToHkeyAndSubKey(tstring regPath,HKEY *hKey,tstring *strSubKey)
{
	int iPos;
	tstring strRootKey;
	BOOL bResult = FALSE;

	if(regPath.size()==0)
		return FALSE;

	iPos = regPath.find("\\");

	if(iPos == tstring::npos)
		return FALSE;

	strRootKey = regPath.substr(0,iPos);
	if(strRootKey.size()==0)
		return FALSE;

	if(StringToRootKey(strRootKey,hKey))
		bResult = TRUE;

	*strSubKey = regPath.substr(iPos+1,regPath.size()-iPos-1);
	

	return bResult;
}
Пример #3
0
	Filepath::Filepath(const tstring & full_path)
		: m_Path(EMPTY_STRING)
		, m_File(EMPTY_STRING)
	{
		int32 dotCounter(0);
		for(uint32 i = 0; i < full_path.size(); ++i)
		{
			if(full_path[i] == _T('.'))
			{
				++dotCounter;
			}
		}
		if(dotCounter > 1)
		{
			Logger::GetInstance()->Log(LogLevel::Error, 
				_T("Please don't use . in your filename (except for the file extension)"));
		}

		auto index = full_path.find_last_of('/');
		if(index == tstring::npos)
		{
			index = full_path.find_last_of('\\');
		}
		if(index != tstring::npos)
		{
			index += 1;
			m_Path = full_path.substr(0,index);
			m_File = full_path.substr(index, full_path.length() - index);
		}
		else
		{
			m_File = full_path;
		}
	}
Пример #4
0
CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam)
    : CRegBaseCommon<tstring> (key, force, base, sam)
{
    tstring::size_type pos = key.find_last_of(_T('\\'));
    m_path = key.substr(0, pos);
    m_key = key.substr(pos + 1);
}
Пример #5
0
RegWrap::RegWrap( const tstring& sKey, REGSAM samDesired ) :
    hkSession( 0 )
{
    // Parse the key

    unsigned long iFirstSlash = sKey.find_first_of( _T("\\") );

    if ( iFirstSlash == tstring::npos )
        return;

    tstring sRootKey = sKey.substr( 0, iFirstSlash );
    tstring sSubKey = sKey.substr( iFirstSlash+1 );

    // Get the root key by its name

    HKEY hRootKey = (HKEY)-1;

    for ( unsigned long i = 0; rkam[i].szName != 0; ++i )
        if ( sRootKey == rkam[i].szName )
            hRootKey = rkam[i].hRootKey;

    if ( hRootKey == (HKEY)-1 )
        return;

    Init( hRootKey, sSubKey, samDesired );
}
Пример #6
0
bool CDDELink::ParseLink(const tstring& link, tstring& service, tstring& topic, tstring& item)
{
	size_t serviceBegin = 0;
	size_t serviceEnd = link.find_first_of('|', serviceBegin);

	if ( (serviceEnd == tstring::npos) || (serviceEnd == serviceBegin) )
		return false;

	size_t topicBegin = serviceEnd + 1;
	size_t topicEnd = link.find_first_of('!', topicBegin);

	if ( (topicEnd == tstring::npos) || (topicEnd == topicBegin) )
		return false;

	size_t itemBegin = topicEnd + 1;
	size_t itemEnd = link.length();

	if (itemEnd == itemBegin)
		return false;

	service = link.substr(serviceBegin, serviceEnd - serviceBegin);
	topic   = link.substr(topicBegin,   topicEnd   - topicBegin);
	item    = link.substr(itemBegin,    itemEnd    - itemBegin);

	ASSERT(service.length() != 0);
	ASSERT(topic.length() != 0);
	ASSERT(item.length() != 0);

	return true;
}
Пример #7
0
	D3DXVECTOR2 ConvertTString(const tstring & value)
	{
        D3DXVECTOR2 vec;
        int index = value.find(';',0);
		vec.x = ConvertTString<float>(value.substr(0, index));
		vec.y = ConvertTString<float>(value.substr(++index,value.size()-index));
        return vec;
	}
Пример #8
0
	uvec2 string_cast<uvec2, tstring>
		(const tstring & value)
	{
		uvec2 vec;
		int32 index = value.find(';', 0);
		vec.x = string_cast<uint32>(value.substr(0, index));
		vec.y = string_cast<uint32>(value.substr(++index, value.size() - index));
		return vec;
	}
Пример #9
0
	pos string_cast<pos, tstring>
		(const tstring & value)
	{
		pos pos;
		int32 index = value.find(';', 0);
		pos.x = string_cast<float32>(value.substr(0, index));
		int32 index2 = value.find(';', ++index);
		pos.y = string_cast<float32>(value.substr(index, index2 - index));
		pos.l = lay(string_cast<int32>(value.substr(++index2, value.size() - index2)));
		return pos;
	}
Пример #10
0
bool isPathValid(const tstring &sPath) noexcept {
	if (sPath.empty())
		return false;

	if ((sPath.substr(1, 2) == _T(":\\")) || (sPath.substr(0, 2) == _T("\\\\"))) {
		if (GetFileAttributes(sPath.c_str()) & FILE_ATTRIBUTE_DIRECTORY)
			return true;
	}

	return false;
}
Пример #11
0
	uvec3 string_cast<uvec3, tstring>
		(const tstring & value)
	{
		uvec3 vec;
		int32 index = value.find(';', 0);
		vec.x = string_cast<uint32>(value.substr(0, index));
		int32 index2 = value.find(';', ++index);
		vec.y = string_cast<uint32>(value.substr(index, index2 - index));
		vec.z = string_cast<uint32>(value.substr(++index2, value.size() - index2));
		return vec;
	}
Пример #12
0
void PopupManager::ShowMC(const tstring& msg, HWND owner){
	int pos1 = msg.find_first_of(_T("<"));
	int pos2 = msg.find_first_of(_T(">"));
	
	//something wrong with the string, return
	if(pos1 == tstring::npos || pos2 == tstring::npos)
		return;

	ShowMC(msg.substr(pos1+1, pos2-pos1-1), msg.substr(pos2+1), owner);
	
}
Пример #13
0
ChatCommandContext::ChatCommandContext(const tstring& s) {
  dcassert(isCommand(s));
  const string::size_type i = s.find(' ');
  if (i != string::npos) {
    param = s.substr(i + 1);
    command = s.substr(1, i - 1);
  } 
  else {
    command = s.substr(1);
  }
}
Пример #14
0
tstring GetFilePath(tstring FileName){
	tstring::size_type n = FileName.find_last_of(_T('\\'));
	if(n != tstring::npos){
		return FileName.substr(0,n);
	}
	n = FileName.find_last_of(_T('/'));
	if(n == tstring::npos){
		return FileName;
	}
	return FileName.substr(0,n);
};
Пример #15
0
	D3DXQUATERNION ConvertTString(const tstring & value)
	{
		D3DXQUATERNION vec;
		int index = value.find(';', 0);
		vec.x = ConvertTString<float>(value.substr(0, index));
		int index2 = value.find(';', ++index);
		vec.y = ConvertTString<float>(value.substr(index, index2 - index));
		index = value.find(';', ++index2);
		vec.z = ConvertTString<float>(value.substr(index2, index - index2));
		vec.w = ConvertTString<float>(value.substr(++index, value.size() - index));
        return vec;
	}
Пример #16
0
tstring GetFileNoPathName(tstring s)
{
	tstring::size_type n = s.find_last_of(_T('\\'));
	if(n != tstring::npos){
		return s.substr(n+1);
	}
	n = s.find_last_of(_T('/'));
	if(n == tstring::npos){
		return s;
	}
	return s.substr(n);
}
Пример #17
0
	dquat string_cast<dquat, tstring>
		(const tstring & value)
	{
		dquat quat;
		int32 index = value.find(';', 0);
		quat.x = string_cast<float64>(value.substr(0, index));
		int32 index2 = value.find(';', ++index);
		quat.y = string_cast<float64>(value.substr(index, index2 - index));
		index = value.find(';', ++index2);
		quat.z = string_cast<float64>(value.substr(index2, index - index2));
		quat.w = string_cast<float64>(value.substr(++index, value.size() - index));
		return quat;
	}
Пример #18
0
static bool matches(tstring const& mask, tstring const& str)
{
    if( mask == str )
        return true;
    if( mask.size() > 0 && mask[mask.size()-1] == '*') {
        size_t const_part_len = mask.size()-1;
        
        if( str.size() >= const_part_len &&
            str.substr(0,const_part_len) == mask.substr(0, const_part_len) )
            return true;
    }
    return false;
}
Пример #19
0
	ivec4 string_cast<ivec4, tstring>
		(const tstring & value)
	{
		ivec4 vec;
		int32 index = value.find(';', 0);
		vec.x = string_cast<int32>(value.substr(0, index));
		int32 index2 = value.find(';', ++index);
		vec.y = string_cast<int32>(value.substr(index, index2 - index));
		index = value.find(';', ++index2);
		vec.z = string_cast<int32>(value.substr(index2, index - index2));
		vec.w = string_cast<int32>(value.substr(++index, value.size() - index));
		return vec;
	}
Пример #20
0
void ShellCache::CPathFilter::AddEntries(const tstring& s, bool include)
{
	size_t pos = 0, pos_ant = 0;
	pos = s.find(L'\n', pos_ant);
	while (pos != tstring::npos)
	{
		AddEntry(s.substr(pos_ant, pos - pos_ant), include);
		pos_ant = pos + 1;
		pos = s.find(L'\n', pos_ant);
	}

	if (!s.empty())
		AddEntry(s.substr(pos_ant, s.size() - 1), include);
}
Пример #21
0
tstring GetObjectType(tstring s)
{
	tstring Result;
	tstring::size_type n = s.find('.');
	if(n == tstring::npos)return Result; 
    n++;

	tstring::size_type n1 =s.find(' ',n);
	if(n1==tstring::npos)n1 = s.size();
    tstring ext = s.substr(n,n1-n);

	if(_tcsncmp(ext.c_str(),_T("ROOM"),4)==0)return _T("ROOM");
	else if(_tcsncmp(ext.c_str(),_T("PEOPLE"),6))return _T("PEOPLE");
	else if(_tcsncmp(ext.c_str(),_T("CONTAINER"),9))return _T("CONTAINER");	
	else {
		SHFILEINFO    sfi;	
		::SHGetFileInfo(
			(LPCTSTR)s.c_str(), 
			FILE_ATTRIBUTE_NORMAL,
			&sfi, 
			sizeof(SHFILEINFO), 
     		SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES);
     
		Result = sfi.szTypeName;
		return Result;
	}
};
Пример #22
0
static tstring remove_duplicate_initial_slashes(tstring s)
{
    while( s.size() > 1 && s[0] == '/' && s[1] == '/' ) {
        s = s.substr(1);
    }
    return s;
}
Пример #23
0
OptionParameter OptionPriceBoard::GetOptionParameterByOptionCode(const tstring& optionCode){
	OptionParameter param;

	tstring optionTypeNum = optionCode.substr(0,1);

	int index = -1;
	if(optionTypeNum.compare(_T("2"))==0){
		index = this->callOptions.FineOptionInfoByOptionCode(optionCode);
		if(index>=0){
			OptionInfo& optionInfo = this->callOptions.GetAt(index);
			param.SetOptionCode(optionInfo.GetOption().GetOptionCode());
			param.SetOptionType(CALL_OPTION);
			param.SetStrikePrice(optionInfo.GetStrikePrice());
			param.SetPremium(optionInfo.GetOption().GetOptionValue().GetValue());
			param.SetPremiumMarket(optionInfo.GetMarketPrice());
		}
	}
	else if(optionTypeNum.compare(_T("3"))==0){
		index = this->putOptions.FineOptionInfoByOptionCode(optionCode);
		if(index>=0){
			OptionInfo& optionInfo = this->putOptions.GetAt(index);
			param.SetOptionCode(optionInfo.GetOption().GetOptionCode());
			param.SetOptionType(PUT_OPTION);
			param.SetStrikePrice(optionInfo.GetStrikePrice());
			param.SetPremium(optionInfo.GetOption().GetOptionValue().GetValue());
			param.SetPremiumMarket(optionInfo.GetMarketPrice());
		}
	}

	return param;
}
Пример #24
0
bool Control::TrimString(tstring& str, int width)
{
  wxClientDC dc (m_Window);

  int x, y;
  wxString wxStr (str.c_str());
  dc.GetTextExtent(wxStr, &x, &y, NULL, NULL, &m_Window->GetFont());

  if (x <= width)
  {
    return false;
  }

  size_t count = str.size();
  for ( size_t i = count; i>0; i-- )
  {
    wxStr = (str.substr(0, i-1) + TXT( "..." ) ).c_str();

    dc.GetTextExtent(wxStr, &x, &y, NULL, NULL, &m_Window->GetFont());

    if (x < width)
    {
      str = wxStr.c_str();
      return true;
    }
  }

  str = TXT( "..." );
  return true;
}
Пример #25
0
    bool CreateDirectory(const tstring& path)
    {
        size_t  pos   = 0;
        int     index = 0;
        tstring subPath;

        while((pos = path.find_first_of(_T("\\/"), pos)) != tstring::npos)
        {
            index++;
            pos++;
            if (index == 1)
            {
                continue;
            }
            subPath = path.substr(0, pos - 1);
            if (!DirectoryExists(subPath))
            {
                if (::CreateDirectory(subPath.c_str(), NULL) == FALSE)
                {
                    return false;
                }
            }
        }
        if (!DirectoryExists(path))
        {
            return ::CreateDirectory(path.c_str(), NULL) != FALSE;
        }
        return true;
    }
void VariableHandler::replaceVariables(tstring &source)
{
	tstring::size_type startPos, endPos;
	startPos = 0;
	endPos = tstring::npos;

	do 
	{
		startPos = source.find(_T('$'), startPos);
		if (startPos != tstring::npos)
		{
			endPos = source.find(_T('$'), startPos + 1);
			if (endPos == tstring::npos)
				break;
		}

		if (endPos != tstring::npos)
		{
			tstring varValue = (*_variables)[source.substr(startPos + 1, endPos - startPos - 1)];
			source.replace(startPos, endPos - startPos + 1, varValue);
			startPos = startPos + varValue.size();
			endPos = tstring::npos;
		}


	} while(startPos != tstring::npos);

	

}
Пример #27
0
void Tokenize( const tstring& str, std::vector< T >& tokens, const tstring& delimiters )
{
    // Skip delimiters at beginning.
    tstring::size_type lastPos = str.find_first_not_of( delimiters, 0 );
    // Find first "non-delimiter".
    tstring::size_type pos     = str.find_first_of( delimiters, lastPos );

    I temp;
    while ( tstring::npos != pos || tstring::npos != lastPos )
    {
        // Found a token, convert it to the proper type for our vector
        tstringstream stream (str.substr( lastPos, pos - lastPos ));
        stream >> temp; // NOTE: Stream operator stops at spaces!
        if ( !stream.fail() )
        {
            // Add the token to the vector
            tokens.push_back( (T)temp );
        }
        else
        {
            HELIUM_BREAK();
        }
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of( delimiters, pos );
        // Find next "non-delimiter"
        pos = str.find_first_of( delimiters, lastPos );
    }
}
Пример #28
0
bool
WaypointReaderZander::parseString(const TCHAR* src, tstring& dest, unsigned len)
{
    if (src[0] == 0)
        return true;

    dest.assign(src);

    // Cut the string after the first space, tab or null character
    size_t found = dest.find_first_of(_T("\t\0"));
    if (found != tstring::npos)
        dest = dest.substr(0, found);

    dest = dest.substr(0, len);
    trim_inplace(dest);
    return true;
}
Пример #29
0
void GetHashInfo(tstring id, std::vector<std::wstring> & info) {
	while(id.size() > 0)
	{
		size_t pos = id.find(L'-');
		
		tstring substr =
			id.substr(0, pos == tstring::npos ? id.length() : pos);
		info.push_back(substr);
		
		if(pos == tstring::npos) id = L"";
		else
		{
			++pos;
			id = id.substr(pos, id.length() - pos);
		}
	}
}
Пример #30
0
void PopupManager::ShowPm(const tstring& nick, const tstring& msg, HWND owner){
	int pos = msg.find_first_of(_T(">"))+1;
	if(pos == tstring::npos )
		pos = 0;

	tstring s = TSTRING(POPUP_NEW_PM) + _T(" ") + nick + _T(" ") + TSTRING(POPUP_MSG) + msg.substr(pos);
	Show(s, owner);
}