cppstring GTextUtils::ExtractBaseName(const cppstring & sFullName, int * p_nOutNumberSuffix)
{
	// ExtractBaseName expects a string in the form of [base sequenece][space character][digits]
	// The base sequence is returned as a cppstring.
	// The digits, if present, are converted to an integer value and stored
	// on exit in the p_nOutNumberSuffix parameter if it is non-NULL.
	
	cppstring sBase;
	cppstring sNum;
	
	unsigned int nLastSpacePos = sFullName.find_last_of(' ');
	if (nLastSpacePos != cppstring::npos)
	{
		unsigned int ix;
		for (ix = 0; ix < nLastSpacePos; ix++)
			sBase += sFullName[ix];
		
		for (ix = nLastSpacePos + 1; ix < sFullName.length(); ix++)
			sNum += sFullName[ix];
		
		bool bGotNum = (sNum.length() > 0 && IsStringLong(sNum));
		if (!bGotNum)
			sBase = sFullName;
			
		if (p_nOutNumberSuffix != NULL)
		{
			if (bGotNum)
				*p_nOutNumberSuffix = (int) GTextUtils::CPPStringToLong(sNum);
			else
				*p_nOutNumberSuffix = 0;
		}
	}
	else
	{
		sBase = sFullName;
		if (p_nOutNumberSuffix != NULL)
			*p_nOutNumberSuffix = 0;
	}
	return sBase;
}
Пример #2
0
int GPortRef::DecodeFromString(const cppstring & sInString)
{
    int nResult = kResponse_Error;

    cppstring::size_type nSearchStartPos = 0;
    cppstring::size_type nCurrentPos = 0;
    cppstring::size_type nNextPos = 0;
    cppstring::size_type nTestPos = 0;

    // ensure that we have a GPortRef tag...
    nSearchStartPos = sInString.find(k_sPortRefCode, 0);
    if (nSearchStartPos != cppstring::npos)
        nSearchStartPos += k_sPortRefCode.length();
    if (nSearchStartPos >= sInString.length())
        nSearchStartPos = cppstring::npos;

    if (nSearchStartPos != cppstring::npos)
        nTestPos = sInString.find_last_of('>');

    if (nTestPos != cppstring::npos)
    {
        cppstring sSubStr;

        // decode port-type
        nCurrentPos = sInString.find(k_sPortTypeCode, nSearchStartPos);
        nCurrentPos += k_sPortTypeCode.length();
        if (nCurrentPos < sInString.length())
            nCurrentPos = sInString.find('\"', nCurrentPos);
        else
            nCurrentPos = cppstring::npos;

        if (nCurrentPos != cppstring::npos)
            nNextPos = nCurrentPos + 1;
        if (nNextPos != cppstring::npos)
            nNextPos = sInString.find('\"', nNextPos);
        if (	nCurrentPos != cppstring::npos &&
                nNextPos != cppstring::npos &&
                nCurrentPos < nNextPos)
            sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1));
        if (sSubStr.length() > 0)
            m_ePortType = (EPortType) GTextUtils::CPPStringToLong(sSubStr.c_str());
        sSubStr = GSTD_S("");

        // decode location
        nCurrentPos = sInString.find(k_sLocationCode, nSearchStartPos);
        nCurrentPos += k_sLocationCode.length();
        if (nCurrentPos < sInString.length())
            nCurrentPos = sInString.find('\"', nCurrentPos);
        else
            nCurrentPos = cppstring::npos;

        if (nCurrentPos != cppstring::npos)
            nNextPos = nCurrentPos + 1;
        if (nNextPos != cppstring::npos)
            nNextPos = sInString.find('\"', nNextPos);
        if (	nCurrentPos != cppstring::npos &&
                nNextPos != cppstring::npos &&
                nCurrentPos < nNextPos)
            sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1));
        if (sSubStr.length() > 0)
            m_sLocation = sSubStr;
        sSubStr = GSTD_S("");

        // decode display-name
        nCurrentPos = sInString.find(k_sDisplayNameCode, nSearchStartPos);
        nCurrentPos += k_sDisplayNameCode.length();
        if (nCurrentPos < sInString.length())
            nCurrentPos = sInString.find('\"', nCurrentPos);
        else
            nCurrentPos = cppstring::npos;

        if (nCurrentPos != cppstring::npos)
            nNextPos = nCurrentPos + 1;
        if (nNextPos != cppstring::npos)
            nNextPos = sInString.find('\"', nNextPos);
        if (nCurrentPos != cppstring::npos &&
                nNextPos != cppstring::npos &&
                nCurrentPos < nNextPos)
            sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1));
        if (sSubStr.length() > 0)
            m_sDisplayName = sSubStr;
        sSubStr = GSTD_S("");
    }
    return nResult;
}