コード例 #1
0
//++ ------------------------------------------------------------------------------------
// Details: Get string with backslashes in front of double quote '"' and backslash '\\'
//          characters.
// Type:    Method.
// Args:    None.
// Return:  CMIUtilString - The wrapped version of the initial string.
// Throws:  None.
//--
CMIUtilString
CMIUtilString::AddSlashes(void) const
{
    const char cBckSlash('\\');
    const size_t nLen(length());
    CMIUtilString strNew;
    strNew.reserve(nLen);

    size_t nOffset(0);
    while (nOffset < nLen)
    {
        const size_t nUnescapedCharPos(find_first_of("\"\\", nOffset));
        const bool bUnescapedCharNotFound(nUnescapedCharPos == std::string::npos);
        if (bUnescapedCharNotFound)
        {
            const size_t nAppendAll(std::string::npos);
            strNew.append(*this, nOffset, nAppendAll);
            break;
        }
        const size_t nAppendLen(nUnescapedCharPos - nOffset);
        strNew.append(*this, nOffset, nAppendLen);
        strNew.push_back(cBckSlash);
        const char cUnescapedChar((*this)[nUnescapedCharPos]);
        strNew.push_back(cUnescapedChar);
        nOffset = nUnescapedCharPos + 1;
    }

    return strNew;
}
コード例 #2
0
//++ ------------------------------------------------------------------------------------
// Details: Splits string into array of strings using delimiter. If multiple delimiter
//          are found in sequence then they are not added to the list of splits.
// Type:    Method.
// Args:    vData       - (R) String data to be split up.
//          vDelimiter  - (R) Delimiter char or text.
//          vwVecSplits - (W) Container of splits found in string data.
// Return:  size_t - Number of splits found in the string data.
// Throws:  None.
//--
size_t
CMIUtilString::Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits) const
{
    vwVecSplits.clear();

    if (this->empty() || vDelimiter.empty())
        return 0;

    const size_t nLen(length());
    size_t nOffset(0);
    do
    {
        // Find first occurrence which doesn't match to the delimiter
        const size_t nSectionPos(FindFirstNot(vDelimiter, nOffset));
        if (nSectionPos == std::string::npos)
            break;

        // Find next occurrence of the delimiter after section
        size_t nNextDelimiterPos(FindFirst(vDelimiter, nSectionPos));
        if (nNextDelimiterPos == std::string::npos)
            nNextDelimiterPos = nLen;

        // Extract string between delimiters
        const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
        const std::string strSection(substr(nSectionPos, nSectionLen));
        vwVecSplits.push_back(strSection.c_str());

        // Next
        nOffset = nNextDelimiterPos + 1;
    }
    while (nOffset < nLen);

    return vwVecSplits.size();
}
コード例 #3
0
ファイル: MIUtilString.cpp プロジェクト: llvm-project/lldb
//++
// Details: Remove backslashes added by CMIUtilString::AddSlashes.
// Type:    Method.
// Args:    None.
// Return:  CMIUtilString - The initial version of wrapped string.
// Throws:  None.
//--
CMIUtilString CMIUtilString::StripSlashes() const {
  const char cBckSlash('\\');
  const size_t nLen(length());
  CMIUtilString strNew;
  strNew.reserve(nLen);

  size_t nOffset(0);
  while (nOffset < nLen) {
    const size_t nBckSlashPos(find(cBckSlash, nOffset));
    const bool bBckSlashNotFound(nBckSlashPos == std::string::npos);
    if (bBckSlashNotFound) {
      const size_t nAppendAll(std::string::npos);
      strNew.append(*this, nOffset, nAppendAll);
      break;
    }
    const size_t nAppendLen(nBckSlashPos - nOffset);
    strNew.append(*this, nOffset, nAppendLen);
    const bool bBckSlashIsLast(nBckSlashPos == nLen);
    if (bBckSlashIsLast) {
      strNew.push_back(cBckSlash);
      break;
    }
    const char cEscapedChar((*this)[nBckSlashPos + 1]);
    const size_t nEscapedCharPos(std::string("\"\\").find(cEscapedChar));
    const bool bEscapedCharNotFound(nEscapedCharPos == std::string::npos);
    if (bEscapedCharNotFound)
      strNew.push_back(cBckSlash);
    strNew.push_back(cEscapedChar);
    nOffset = nBckSlashPos + 2;
  }

  return strNew;
}
コード例 #4
0
ファイル: Path.cpp プロジェクト: dkoerner/base
	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("");
		}    
	}
コード例 #5
0
ファイル: Path.cpp プロジェクト: dkoerner/base
	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;
		} 
	}