Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI)
Summary: Allow to construct CMIUtilString using std::string directly + cleanup CMIUtilString (MI) This patch cleans up lldb-mi code, and serves to simplify the following case: ``` std::string strGoodbye = "!Hello"; CMIUtilString strHello(strGoodbye.substr(1).c_str()); ``` With CMIUtilString(std::string) we can omit .c_str(): ``` std::string strGoodbye = "!Hello"; CMIUtilString strHello(strGoodbye.substr(1)); ``` Also, it removes 2 ctors because they aren't needed: # CMIUtilString::CMIUtilString(const char *const *vpData) # CMIUtilString::CMIUtilString(const char *vpData, size_t nLen) and cleans up CMIUtilString::operator=(const std::string &vrRhs). Reviewers: brucem, abidh Subscribers: lldb-commits, brucem, abidh Differential Revision: http://reviews.llvm.org/D13158 llvm-svn: 248566
This commit is contained in:
parent
f69d45efc3
commit
b2b0170c0e
|
@ -130,7 +130,7 @@ CMICmdArgContext::RemoveArg(const CMIUtilString &vArg)
|
|||
}
|
||||
|
||||
const size_t nPosEnd = nLen + nExtraSpace;
|
||||
m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace(nPos, nPosEnd, "").c_str();
|
||||
m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace(nPos, nPosEnd, "");
|
||||
m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.Trim();
|
||||
|
||||
return MIstatus::success;
|
||||
|
|
|
@ -261,7 +261,7 @@ CMICmdArgValOptionLong::IsArgLongOption(const CMIUtilString &vrTxt) const
|
|||
if (vrTxt.length() < 3)
|
||||
return false;
|
||||
|
||||
const CMIUtilString strArg = vrTxt.substr(2).c_str();
|
||||
const CMIUtilString strArg = vrTxt.substr(2);
|
||||
if (strArg.IsNumber())
|
||||
return false;
|
||||
|
||||
|
@ -293,7 +293,7 @@ CMICmdArgValOptionLong::IsArgOptionCorrect(const CMIUtilString &vrTxt) const
|
|||
bool
|
||||
CMICmdArgValOptionLong::ArgNameMatch(const CMIUtilString &vrTxt) const
|
||||
{
|
||||
const CMIUtilString strArg = vrTxt.substr(2).c_str();
|
||||
const CMIUtilString strArg = vrTxt.substr(2);
|
||||
return (strArg == GetName());
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,6 @@ CMICmdArgValOptionShort::IsArgOptionCorrect(const CMIUtilString &vrTxt) const
|
|||
bool
|
||||
CMICmdArgValOptionShort::ArgNameMatch(const CMIUtilString &vrTxt) const
|
||||
{
|
||||
const CMIUtilString strArg = vrTxt.substr(1).c_str();
|
||||
const CMIUtilString strArg = vrTxt.substr(1);
|
||||
return (strArg == GetName());
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
|
|||
if (nPos != 0)
|
||||
return false;
|
||||
|
||||
const CMIUtilString strNum = vrTxt.substr(1).c_str();
|
||||
const CMIUtilString strNum = vrTxt.substr(1);
|
||||
if (!strNum.IsNumber())
|
||||
return false;
|
||||
|
||||
|
@ -139,7 +139,7 @@ CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
|
|||
bool
|
||||
CMICmdArgValThreadGrp::ExtractNumber(const CMIUtilString &vrTxt)
|
||||
{
|
||||
const CMIUtilString strNum = vrTxt.substr(1).c_str();
|
||||
const CMIUtilString strNum = vrTxt.substr(1);
|
||||
MIint64 nNumber = 0;
|
||||
bool bOk = strNum.ExtractNumber(nNumber);
|
||||
if (bOk)
|
||||
|
|
|
@ -1613,7 +1613,7 @@ CMICmdCmdDataInfoLine::Execute()
|
|||
// Parse argument:
|
||||
// *0x12345
|
||||
// ^^^^^^^ -- address
|
||||
const CMIUtilString strAddress(strLocation.c_str() + 1);
|
||||
const CMIUtilString strAddress(strLocation.substr(1));
|
||||
strCmdOptionsLocation = CMIUtilString::Format("--address %s", strAddress.c_str());
|
||||
}
|
||||
else
|
||||
|
@ -1629,8 +1629,8 @@ CMICmdCmdDataInfoLine::Execute()
|
|||
// hello.cpp:5
|
||||
// ^^^^^^^^^ -- file
|
||||
// ^ -- line
|
||||
const CMIUtilString strFile(strLocation.substr(0, nLineStartPos).c_str());
|
||||
const CMIUtilString strLine(strLocation.substr(nLineStartPos + 1).c_str());
|
||||
const CMIUtilString strFile(strLocation.substr(0, nLineStartPos));
|
||||
const CMIUtilString strLine(strLocation.substr(nLineStartPos + 1));
|
||||
strCmdOptionsLocation = CMIUtilString::Format("--file \"%s\" --line %s", strFile.AddSlashes().c_str(), strLine.c_str());
|
||||
}
|
||||
const CMIUtilString strCmd(CMIUtilString::Format("target modules lookup -v %s", strCmdOptionsLocation.c_str()));
|
||||
|
|
|
@ -179,7 +179,7 @@ CMICmdCmdVarCreate::Execute()
|
|||
|
||||
if (rStrExpression[0] == '$')
|
||||
{
|
||||
const CMIUtilString rStrRegister(rStrExpression.substr(1).c_str());
|
||||
const CMIUtilString rStrRegister(rStrExpression.substr(1));
|
||||
value = frame.FindRegister(rStrRegister.c_str());
|
||||
}
|
||||
else
|
||||
|
|
|
@ -160,10 +160,10 @@ CMICmdInterpreter::MiHasCmdTokenEndingHyphen(const CMIUtilString &vTextLine)
|
|||
if (MiHasCmdTokenPresent(vTextLine))
|
||||
{
|
||||
const std::string strNum = vTextLine.substr(0, nPos);
|
||||
if (!CMIUtilString(strNum.c_str()).IsNumber())
|
||||
if (!CMIUtilString(strNum).IsNumber())
|
||||
return false;
|
||||
|
||||
m_miCmdData.strMiCmdToken = strNum.c_str();
|
||||
m_miCmdData.strMiCmdToken = strNum;
|
||||
}
|
||||
|
||||
m_miCmdData.bMIOldStyle = false;
|
||||
|
@ -256,20 +256,20 @@ CMICmdInterpreter::MiHasCmd(const CMIUtilString &vTextLine)
|
|||
{
|
||||
if (nPos2 == nLen)
|
||||
return false;
|
||||
const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nPos2 - nPos - 1).c_str());
|
||||
const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nPos2 - nPos - 1));
|
||||
if (cmd.empty())
|
||||
return false;
|
||||
|
||||
m_miCmdData.strMiCmd = cmd;
|
||||
|
||||
if (nPos2 < nLen)
|
||||
m_miCmdData.strMiCmdOption = CMIUtilString(vTextLine.substr(nPos2 + 1, nLen - nPos2 - 1).c_str());
|
||||
m_miCmdData.strMiCmdOption = CMIUtilString(vTextLine.substr(nPos2 + 1, nLen - nPos2 - 1));
|
||||
|
||||
bFoundCmd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nLen - nPos - 1).c_str());
|
||||
const CMIUtilString cmd = CMIUtilString(vTextLine.substr(nPos + 1, nLen - nPos - 1));
|
||||
if (cmd.empty())
|
||||
return false;
|
||||
m_miCmdData.strMiCmd = cmd;
|
||||
|
|
|
@ -585,7 +585,7 @@ CMICmnLLDBDebugger::ClientGetMaskForAllClients(const CMIUtilString &vBroadcaster
|
|||
while (it != m_mapIdToEventMask.end())
|
||||
{
|
||||
const CMIUtilString &rId((*it).first);
|
||||
if (rId.find(vBroadcasterClass.c_str()) != std::string::npos)
|
||||
if (rId.find(vBroadcasterClass) != std::string::npos)
|
||||
{
|
||||
const MIuint clientsMask = (*it).second;
|
||||
mask |= clientsMask;
|
||||
|
@ -678,9 +678,7 @@ CMICmnLLDBDebugger::ClientGetTheirMask(const CMIUtilString &vClientName, const C
|
|||
return MIstatus::failure;
|
||||
}
|
||||
|
||||
CMIUtilString strId(vBroadcasterClass.c_str());
|
||||
strId += vClientName;
|
||||
|
||||
const CMIUtilString strId(vBroadcasterClass + vClientName);
|
||||
const MapIdToEventMask_t::const_iterator it = m_mapIdToEventMask.find(strId);
|
||||
if (it != m_mapIdToEventMask.end())
|
||||
{
|
||||
|
|
|
@ -1572,7 +1572,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProcessStdout()
|
|||
if (nNewLine == std::string::npos)
|
||||
break;
|
||||
|
||||
const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
|
||||
const CMIUtilString line(text.substr(0, nNewLine + 1));
|
||||
text.erase(0, nNewLine + 1);
|
||||
const bool bEscapeQuotes(true);
|
||||
CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
|
||||
|
@ -1625,7 +1625,7 @@ CMICmnLLDBDebuggerHandleEvents::GetProcessStderr()
|
|||
if (nNewLine == std::string::npos)
|
||||
break;
|
||||
|
||||
const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
|
||||
const CMIUtilString line(text.substr(0, nNewLine + 1));
|
||||
const bool bEscapeQuotes(true);
|
||||
CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
|
||||
CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
|
||||
|
|
|
@ -505,7 +505,7 @@ CMICmnLLDBUtilSBValue::ReadCStringFromHostMemory(lldb::SBValue &vrValue, const M
|
|||
addr += sizeof(ch);
|
||||
}
|
||||
|
||||
return result.c_str();
|
||||
return result;
|
||||
}
|
||||
|
||||
//++ ------------------------------------------------------------------------------------
|
||||
|
|
|
@ -893,7 +893,7 @@ CMIDriver::WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const
|
|||
const std::string vToken(vTextLine.begin(), vTextLine.begin() + nCommandOffset);
|
||||
// 001target create "/path/to/file"
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- CLI command
|
||||
const CMIUtilString vCliCommand(std::string(vTextLine, nCommandOffset).c_str());
|
||||
const CMIUtilString vCliCommand(std::string(vTextLine, nCommandOffset));
|
||||
|
||||
// 5. Escape special characters and embed the command in a string
|
||||
// Result: it looks like -- target create \"/path/to/file\".
|
||||
|
|
|
@ -45,25 +45,12 @@ CMIUtilString::CMIUtilString(const char *vpData)
|
|||
//++ ------------------------------------------------------------------------------------
|
||||
// Details: CMIUtilString constructor.
|
||||
// Type: Method.
|
||||
// Args: vpData - Pointer to UTF8 text data.
|
||||
// Args: vpStr - Text data.
|
||||
// Return: None.
|
||||
// Throws: None.
|
||||
//--
|
||||
CMIUtilString::CMIUtilString(const char *const *vpData)
|
||||
: std::string((const char *)vpData)
|
||||
{
|
||||
}
|
||||
|
||||
//++ ------------------------------------------------------------------------------------
|
||||
// Details: CMIUtilString constructor.
|
||||
// Type: Method.
|
||||
// Args: vpData - Pointer to UTF8 text data.
|
||||
// nLen - Length of string.
|
||||
// Return: None.
|
||||
// Throws: None.
|
||||
//--
|
||||
CMIUtilString::CMIUtilString(const char *vpData, size_t nLen)
|
||||
: std::string(vpData, nLen)
|
||||
CMIUtilString::CMIUtilString(const std::string& vrStr)
|
||||
: std::string(vrStr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -96,11 +83,7 @@ CMIUtilString &CMIUtilString::operator=(const char *vpRhs)
|
|||
//--
|
||||
CMIUtilString &CMIUtilString::operator=(const std::string &vrRhs)
|
||||
{
|
||||
if (*this == vrRhs)
|
||||
return *this;
|
||||
|
||||
assign(vrRhs);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -243,7 +226,7 @@ CMIUtilString::Split(const CMIUtilString &vDelimiter, VecString_t &vwVecSplits)
|
|||
// Extract string between delimiters
|
||||
const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
|
||||
const std::string strSection(substr(nSectionPos, nSectionLen));
|
||||
vwVecSplits.push_back(strSection.c_str());
|
||||
vwVecSplits.push_back(strSection);
|
||||
|
||||
// Next
|
||||
nOffset = nNextDelimiterPos + 1;
|
||||
|
@ -299,7 +282,7 @@ CMIUtilString::SplitConsiderQuotes(const CMIUtilString &vDelimiter, VecString_t
|
|||
// Extract string between delimiters
|
||||
const size_t nSectionLen(nNextDelimiterPos - nSectionPos);
|
||||
const std::string strSection(substr(nSectionPos, nSectionLen));
|
||||
vwVecSplits.push_back(strSection.c_str());
|
||||
vwVecSplits.push_back(strSection);
|
||||
|
||||
// Next
|
||||
nOffset = nNextDelimiterPos + 1;
|
||||
|
@ -337,7 +320,7 @@ CMIUtilString::StripCREndOfLine() const
|
|||
if (nPos == std::string::npos)
|
||||
return *this;
|
||||
|
||||
const CMIUtilString strNew(substr(0, nPos).c_str());
|
||||
const CMIUtilString strNew(substr(0, nPos));
|
||||
|
||||
return strNew;
|
||||
}
|
||||
|
@ -542,12 +525,12 @@ CMIUtilString::Trim() const
|
|||
const size_t nPos = find_last_not_of(pWhiteSpace);
|
||||
if (nPos != std::string::npos)
|
||||
{
|
||||
strNew = substr(0, nPos + 1).c_str();
|
||||
strNew = substr(0, nPos + 1);
|
||||
}
|
||||
const size_t nPos2 = strNew.find_first_not_of(pWhiteSpace);
|
||||
if (nPos2 != std::string::npos)
|
||||
{
|
||||
strNew = strNew.substr(nPos2).c_str();
|
||||
strNew = strNew.substr(nPos2);
|
||||
}
|
||||
|
||||
return strNew;
|
||||
|
@ -568,7 +551,7 @@ CMIUtilString::Trim(const char vChar) const
|
|||
if (nLen > 1)
|
||||
{
|
||||
if ((strNew[0] == vChar) && (strNew[nLen - 1] == vChar))
|
||||
strNew = strNew.substr(1, nLen - 2).c_str();
|
||||
strNew = strNew.substr(1, nLen - 2);
|
||||
}
|
||||
|
||||
return strNew;
|
||||
|
|
|
@ -43,8 +43,7 @@ class CMIUtilString : public std::string
|
|||
public:
|
||||
/* ctor */ CMIUtilString();
|
||||
/* ctor */ CMIUtilString(const char *vpData);
|
||||
/* ctor */ CMIUtilString(const char *const *vpData);
|
||||
/* ctor */ CMIUtilString(const char *vpData, size_t nLen);
|
||||
/* ctor */ CMIUtilString(const std::string& vrStr);
|
||||
//
|
||||
bool ExtractNumber(MIint64 &vwrNumber) const;
|
||||
CMIUtilString FindAndReplace(const CMIUtilString &vFind, const CMIUtilString &vReplaceWith) const;
|
||||
|
|
Loading…
Reference in New Issue