Beispiel #1
0
	UInt32 Path::Depth()
	{
		std::string::size_type nLength(m_sPath.length());
		UInt32 nDepth(0);
		
		for(std::string::size_type i = 0; i < nLength; i++)
		{
			if(m_sPath[i] == PATH_SEPARATOR_CHAR)
			{
				++nDepth;
			}
		}
		
		if(nDepth > 0 &&
		nLength > 0 &&
		m_sPath[nLength - 1] == PATH_SEPARATOR_CHAR)
		{
			// PATH_SEPARATOR_CHAR on the end, reduce count by 1
			--nDepth;
		}
		
		TRACE_WITH_LEVEL_MAX(("Depth of path %s is %lu", m_sPath.c_str(), nDepth));
		
		return nDepth;
	}
Beispiel #2
0
	Path Path::getParent()
	{
		if(m_sPath.length() == 0 || IsRoot())
		{
			// return empty path.
			return Path("");
		}
		
		// reverse find a / ignoring the end / if it exists.
		std::string::size_type nLength(m_sPath.length());
		std::string::size_type nOffset ((m_sPath[nLength - 1] == PATH_SEPARATOR_CHAR && nLength - 2 > 0) ? nLength - 2 : std::string::npos);
		std::string::size_type nPos (m_sPath.rfind(PATH_SEPARATOR_STR, nOffset));
		
		// create new path object given position of find / and return it.
		if(nPos != std::string::npos)
		{
	#if defined(_WINDOWS)
			return Path(m_sDrive + m_sPath.substr(0, nPos + 1), false);
	#else
			return Path(m_sPath.substr(0, nPos + 1), false);
	#endif
		}
		else
		{
			// not parent path avaliable, return an empty path.
			return Path("");
		}    
	}
Beispiel #3
0
eaio::size_type eaio::readString(IStream* pIS, char8_t* pBuffer, size_type nMaxCount, eaio::Endian endianSource)
{
    const off_type ninitialPosition(pIS->getPosition());

    char8_t   cCurrent;
    uint32_t  nLength(0);
    size_type nCount(0); // Number of chars returned to user.
    size_type nResult;

    if(!readUint32(pIS, nLength, endianSource))
        return kSizeTypeError;

    // If no buffer has been provided, just reset the stream and return the length.
    if(!pBuffer)
    {
        pIS->setPosition(ninitialPosition);
        return (size_type)nLength;
    }

    // Determine how many characters we'll actually read into the buffer.
    // 'nMaxCount - 1' because we want to leave room for terminating NUL.
    size_type nreadLength = (nLength < nMaxCount - 1) ? nLength : nMaxCount - 1;

    while(pBuffer && (nCount < nreadLength)) 
    {
        nResult = pIS->read(&cCurrent, sizeof(cCurrent));

        if(nResult != sizeof(cCurrent))
            break;

        *pBuffer++ = cCurrent;
        ++nCount;
    }

    // We may not have been able to read the entire string out of the stream
    // due to the nMaxCount limit, but we still want to advance the stream's
    // position to the end of the string.
    pIS->setPosition(ninitialPosition + (off_type)sizeof(uint32_t) + (off_type)nLength);

    if(pBuffer)
        *pBuffer = '\0';

    return nLength; // Note that we return nLength and not nCount.
}
Beispiel #4
0
	std::string Path::GetBaseFileName()
	{
		if(m_sPath.length() == 0)
		{
			// return empty name.
			return "";
		}
		
		// reverse find a / ignoring the end / if it exists.
		std::string::size_type nLength(m_sPath.length());
		std::string::size_type nOffset((m_sPath[nLength - 1] == PATH_SEPARATOR_CHAR && nLength - 2 > 0) ? nLength - 2 : std::string::npos);
		std::string::size_type nPos (m_sPath.rfind(PATH_SEPARATOR_STR, nOffset));
		
		// extract filename given position of find / and return it.
		if(nPos != std::string::npos)
		{
			return m_sPath.substr(nPos + 1, nLength - (nPos + 1) - (nOffset != std::string::npos ? 1 : 0));
		}
		else
		{
			return m_sPath;
		} 
	}