bool cUnixFSServices::GetExecutableFilename(TSTRING& strFullPath, const TSTRING& strFilename) const
{
    bool fGotName = false;

    if (strFilename.empty())
        return false;

    // if there is a slash in the filename, it's absolute or relative to cwd
    if (TSTRING::npos != strFilename.find(_T('/')))
    {
        // if absolute path
        if (strFilename[0] == _T('/'))
        {
            strFullPath = strFilename;
            fGotName    = true;
        }
        else // is relative path; find path from cwd
        {
            fGotName = FullPath(strFullPath, strFilename);
        }
    }
    else // it's just a filename: should be found in path
    {
        fGotName = util_PathFind(strFullPath, strFilename);

        TSTRING strFP;
        if (fGotName && FullPath(strFP, strFullPath))
            strFullPath = strFP;
    }

    return (fGotName);
}
Example #2
0
	TSTRING Replace( const TSTRING& orignStr, const TSTRING& oldStr, const vector<TSTRING>&vc )
	{
		size_t pos = 0; 
		TSTRING tempStr = orignStr; 
		TSTRING::size_type newStrLen; 
		TSTRING::size_type oldStrLen = oldStr.length();
		int i=0;

		while(true) 
		{ 
			pos = tempStr.find(oldStr, pos); 
			if (pos == TSTRING::npos) break; 
			TSTRING s=vc.at(i);
			s = _T("\'")+s +_T("\'");
			newStrLen= s.length(); 

			tempStr.replace(pos, oldStrLen, s);         
			pos += newStrLen;
			i++;

		} 

		return tempStr; 

	}
bool cEncoder::AllIdentifiersUnique() const
{
    TSTRING chars;
    for( sack_type::const_iterator atE = m_encodings.begin(); atE != m_encodings.end(); atE++ )
    {
        TCHAR chID = (*atE)->Identifier();
        if( chars.find( chID ) == TSTRING::npos )
            chars += chID;
        else
            return false;
    }
    return true;
}
////////////////////////////////////////////////////////////////////////////////////
// Function name    : util_GetNextPathElement
// Description      :
//      starting from the left side of the path string, returns the index'th path element
//      returns true if the element exists, false if there aren't <index + 1> many elements
//
//      index is ZERO BASED
//
//      2rd element of   ABC/DEF/GH -> GH
//      1st element of //ABC/DEF/GH -> DEF
//
// Return type      : bool : got path element? ( i.e. was there index path elements? )
// Argument         : const TSTRING& strPathC
// Argument         : TSTRING& strElem
// Argument         : int index
/////////////////////////////////////////////////////////////////////////////////
bool util_GetNextPathElement(const TSTRING& strPathC, TSTRING& strElem, int index)
{

    // don't do anything if root or empty
    if (strPathC.empty() || iFSServices::GetInstance()->IsRoot(strPathC))
        return false;

    TSTRING strPath = strPathC; // writable local version

    bool               fMoreSeps = true;
    TSTRING::size_type nextSep, nextNonSep;
    nextSep = nextNonSep = (TSTRING::size_type)-1;
    for (int i = 0; i <= index && fMoreSeps; i++)
    {
        // go past leading separators
        nextNonSep = strPath.find_first_not_of(TW_SLASH, nextSep + 1);

        if (nextNonSep != TSTRING::npos)
        {
            // find index'th slash (start of index'th element)
            nextSep = strPath.find(TW_SLASH, nextNonSep);

            // if we're at the end and we haven't found the index'th element
            // left, then tell the caller that there aren't that many elemnts
            if (nextSep == TSTRING::npos && i < index)
                fMoreSeps = false;
        }
        else
            fMoreSeps = false;
    }

    // get the element and remove it from the path
    if (fMoreSeps)
        strElem = strPath.substr(nextNonSep, nextSep - nextNonSep);

    return (fMoreSeps);
}