当前位置: 首页>>代码示例>>C++>>正文


C++ TSTRING::substr方法代码示例

本文整理汇总了C++中TSTRING::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ TSTRING::substr方法的具体用法?C++ TSTRING::substr怎么用?C++ TSTRING::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TSTRING的用法示例。


在下文中一共展示了TSTRING::substr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DisplayStringToFCOName

///////////////////////////////////////////////////////////////////////////////
// DisplayStringToFCOName
///////////////////////////////////////////////////////////////////////////////
bool cFSNameTranslator::DisplayStringToFCOName( const TSTRING& strC, cFCOName& name ) const
{ 
    TSTRING str = strC;    
    const TCHAR dq = _T('\"');

    // do a little error checking.  must have at least '""'
    if( str.size() < 1 )
        return false;
    if( dq != str[0] )
        return false;
    if( dq != str[str.size() - 1] )
        return false;

    // get rid of beginning and trailing quote
	str = str.substr( 1, str.size() - 2 );

    //
    // undo funky wide char encoding
    //
    cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP );
    if( ! e.Decode( str ) )
        return false;

    // give to cFCOName
    name = str;

    return true;
}
开发者ID:jiangzhw,项目名称:tripwire-open-source,代码行数:31,代码来源:fsnametranslator.cpp

示例2: util_RemoveLastPathElement

//////////////////////////////////////////////////////////////////////////////////
// Function name    : util_RemoveLastPathElement
// Description      :
//      effectively pops off a path element from the end, except for the root dir, where it does nothing
//      it removes any slashes before and after the element
//      ///root//foo/    -> leaves "///root" ("foo"  is strElem)
//      ///root          -> leaves ""        ("root" is strElem)
//      //               -> leaves ""        (""     is strElem)
//
// Return type      : void
// Argument         :  TSTRING& strPath
// Argument         : TSTRING& strElem
/////////////////////////////////////////////////////////////////////////////////
void util_RemoveLastPathElement(TSTRING& strPath, TSTRING& strElem)
{

    // remove all trailing separators
    util_RemoveTrailingSeps(strPath);

    // find the last separator
    TSTRING::size_type lastSep = strPath.rfind(TW_SLASH);

    // if separator was found, take all chars after it
    if (lastSep != TSTRING::npos)
    {
        strElem = strPath.substr(lastSep + 1);
        strPath.resize(lastSep + 1);
    }
    else // no seps in name, take whole string
    {
        // last element
        strElem = strPath;
        strPath.erase();
    }

    // remove all trailing separators
    util_RemoveTrailingSeps(strPath);
}
开发者ID:Tripwire,项目名称:tripwire-open-source,代码行数:38,代码来源:unixfsservices.cpp

示例3: util_GetNextPathElement

////////////////////////////////////////////////////////////////////////////////////
// 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);
}
开发者ID:Tripwire,项目名称:tripwire-open-source,代码行数:53,代码来源:unixfsservices.cpp

示例4: DoVarSubstitution

bool cGenreParseInfo::DoVarSubstitution( TSTRING &rval ) //throw( eParserHelper )
{
    cDebug d("cConfigFile::DoVarSubst()");
    d.TraceDebug("ORIG: %s\n", rval.c_str());

    // walk through string
    //      look for $(
    //          find matching )
    //          pick out subset
    //          look up in symbol table
    //          substitute subset
    //      continue iterating

    // step through string
    // iterate to (slen-1), because we are looking for a two-character sentinel "$("
    bool fEscaping = false;
    for (TSTRING::size_type i = 0; i < rval.size(); i++) 
    {
        TCHAR c = rval[i];

        // is it the "$(" sentinel? (an escaped '$' is not a variable)
        if (c == '$' && ! fEscaping ) 
        {
            c = rval[i+1];
            if (c == '(') 
            {
                // ooh, wow!  it's a variable!  find the end
                bool found = false;
                TSTRING::size_type j;

                for (j = i+1; j < rval.size(); j++) 
                {
                    if (rval[j] == ')') 
                    {
                        found = true;
                        break;
                    }
                }

                // did we find it?
                if (!found) 
                {
                    // TODO: throw error
                    return false;
                }

                // otherwise, cut out the variable name
                TSTRING::size_type begin = i + 2;
                TSTRING::size_type size = j - i - 2;
                TSTRING varname;
                varname = rval.substr(begin, size);

                d.TraceDebug("symbol = %s\n", varname.c_str());

                // look up in symbol table
                TSTRING varvalue;
                if ( ! LookupVariable( varname, varvalue ) ) 
                    throw eParserUseUndefVar( varname );

                // replace varname with varvalue
                rval.replace(begin-2, size+3, varvalue);

                d.TraceDebug("POST: %s\n", rval.c_str());

                // no no no
                // we should exit function, and get called again


                // update counters
                //      we should bump the cursor over by the length of the 
                //          varvalue (minus one, to compensate for post-increment of index)
                i += varvalue.size() - 1;
                goto nextchar;
            }
        }
        else if (c == '\\')
        {
            fEscaping = ! fEscaping;
        }
        else
        {
            fEscaping = false;
        }
nextchar:
        ;
    }



    d.TraceDebug("DONE: %s\n", rval.c_str());

    // switch around
    return true;
}
开发者ID:brc0x1,项目名称:tripwire-open-source,代码行数:94,代码来源:genreparseinfo.cpp

示例5: splitFullPath

	HRESULT SLog::splitFullPath(TSTRING szFullPath)
	{
		HRESULT retValue = S_OK;

		TSTRING szSlash = TSTRING(_T("/\\"));
		TSTRING szDot = TSTRING(_T("."));
		int iLastSlash, iLastDot;
		bool bBadPath = false;

		// Quick sanity check...
		if (szFullPath.empty())
		{
			retValue = ERROR_BAD_ARGUMENTS;
			goto EXIT;
		}

		// First, make sure we actually have strings...
		if (NULL == m_szLogFilePath)
			m_szLogFilePath = new TSTRING();

		if (NULL == m_szLogFileName)
			m_szLogFileName = new TSTRING();

		if (NULL == m_szLogFileExt)
			m_szLogFileExt = new TSTRING();

		// Make sure they're clear (remember, we may not have created them)
		m_szLogFilePath->clear();
		m_szLogFileName->clear();
		m_szLogFileExt->clear();

		// To peel apart the string, we need to find the last slash character
		iLastSlash = szFullPath.find_last_of(szSlash.c_str(), TNPOS);

		// Now, this could go either way; either we have no slash, in which case
		// this DOESN'T have a path, or we do and there's a path...
		if (iLastSlash == TNPOS)
		{
			// We didn't get a path...
			bBadPath = true;
		}
		else
		{
			// Get the path, if there is one...
			m_szLogFilePath->append(szFullPath.substr(0, (iLastSlash + 1)));

			// Does that path actually exist?
			WIN32_FILE_ATTRIBUTE_DATA dirData;
			if (!GetFileAttributesEx(m_szLogFilePath->c_str(),
				GetFileExInfoStandard,
				&dirData))
			{
				// We hit an error!
				DWORD dw;
				dw = GetLastError();
				retValue = HRESULT_FROM_WIN32(dw);
				bBadPath = true;
			}
			else if ((dirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
			{
				// The path isn't to a directory!
				retValue = ERROR_BAD_PATHNAME;
				bBadPath = true;
			}
		}

		if (bBadPath)
		{
			// We either got no path or a bad path, so let's
			// set it to the Current Directory...
			// First, get the size of buffer we're going to need
			int iDirSize = GetCurrentDirectory(0, NULL);

			// Next, declare the buffer and use it to get the current directory
			m_szLogFilePath->clear();
			TCHAR* szDirBuffer = new TCHAR[iDirSize];
			GetCurrentDirectory(iDirSize, szDirBuffer);
			m_szLogFilePath->append(szDirBuffer);
			m_szLogFilePath->append(_T("\\"));		// Have to add the trailing slash
		}

		// To peel apart the extension, we need to find the last dot character
		iLastDot = szFullPath.find_last_of(szDot.c_str(), TNPOS);

		// We may or may not have a dot; no dot, no extension
		if (iLastDot == TNPOS)
		{
			iLastDot = szFullPath.length();
			m_szLogFileExt->append(DEFAULT_EXT);
		}
		else
		{
			m_szLogFileExt->append(szFullPath.substr(iLastDot));
		}

		// With all that out of the way, we can get our file name
		m_szLogFileName->append(szFullPath.substr((iLastSlash + 1), ( iLastDot - iLastSlash - 1 )));

	EXIT:
		return retValue;
//.........这里部分代码省略.........
开发者ID:KennGuilstorf,项目名称:SPerfTest,代码行数:101,代码来源:SLog.cpp


注:本文中的TSTRING::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。