本文整理汇总了C++中StringVector::back方法的典型用法代码示例。如果您正苦于以下问题:C++ StringVector::back方法的具体用法?C++ StringVector::back怎么用?C++ StringVector::back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringVector
的用法示例。
在下文中一共展示了StringVector::back方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseFunctionName
/*!
* Parses lines for function/procedure names.
*
* \param line line to be processed
* \param lastline last line processed
* \param functionStack stack of functions
* \param functionName function name found
*
* \return 1 if function name is found
* \return 0 if it is still in some function
* \return 2 if the code line doesn't belong to any function
*/
int CVerilogCounter::ParseFunctionName(const string &line, string &lastline, StringVector &functionStack, string &functionName)
{
string str;
size_t idx;
/* FIND KEYWORD "task" / "function" */
static int func_flag = 0, task_flag = 0;
/* FIND KEYWORD "task" / "function" */
idx = CUtil::FindKeyword(line, "task");
if (idx != string::npos)
{
if (idx + 5 < line.length())
{
str = line.substr(idx + 5);
functionStack.push_back(str);
}
task_flag++;/* FOUND KEYWORD "task" */
}
idx = CUtil::FindKeyword(line, "function");
if (idx != string::npos)
{
if (idx + 9 < line.length())
{
str = line.substr(idx + 9);
functionStack.push_back(str);
}
func_flag++;/* FOUND KEYWORD "function" */
}
if (functionStack.empty())
{
// dealing with some code out of any subroutines, it a "main" code
return 2;
}
idx = CUtil::FindKeyword(line, "endtask");
if(idx != string::npos){
task_flag--;
}
else{
idx = CUtil::FindKeyword(line, "endfunction");
if(idx != string::npos){
func_flag--;
}
}
if (idx != string::npos)
{
str = functionStack.back();
functionStack.pop_back();
idx = str.find(";");
if (idx != string::npos)
{
functionName = CUtil::ClearRedundantSpaces(str.substr(0, idx));
lastline=line; // warning fix
return 1;
}
}
return 0;
}
示例2: getParentNameFromGroupPath
std::string getParentNameFromGroupPath(std::string groupPath)
{
std::string result = ""; // Default = root node
StringVector groupPathComponents = stringSplit(groupPath,"/", false);
if (groupPathComponents.size() > 0)
{
result = groupPathComponents.back();
}
return result;
}
示例3: captureAll
bool RegExp::captureAll(const char* str, StringVector& outResults, uint start)
{
if (_peer == NULL) return false;
SQRex* rex = (SQRex*)_peer;
bool found = sqstd_rex_search(rex, str+start, NULL, NULL);
if (!found) return false;
SQInteger n = sqstd_rex_getsubexpcount(rex);
for (SQInteger i=0; i < n; ++i)
{
SQRexMatch match;
sqstd_rex_getsubexp(rex, i, &match);
outResults.push_back(String());
outResults.back().assign(match.begin, match.begin + match.len);
}
return true;
}
示例4: parseVocationString
std::string parseVocationString(StringVector vocStringVec)
{
std::string str = "";
if(!vocStringVec.empty())
{
for(StringVector::iterator it = vocStringVec.begin(); it != vocStringVec.end(); ++it)
{
if((*it) != vocStringVec.front())
{
if((*it) != vocStringVec.back())
str += ", ";
else
str += " and ";
}
str += (*it);
str += "s";
}
}
return str;
}
示例5: luaFuncExeDirs
static int luaFuncExeDirs(lua_State* l)
{
Block* b = mbGetActiveContext()->ActiveBlock();
if (!b)
{
MB_LOGERROR("must be within a block");
mbExitError();
}
luaL_checktype(l, 1, LUA_TTABLE);
int tableLen = luaL_len(l, 1);
StringVector strings;
for (int i = 1; i <= tableLen; ++i)
{
lua_rawgeti(l, 1, i);
strings.push_back(std::string());
mbLuaToStringExpandMacros(&strings.back(), b, l, -1);
}
b->AddExeDirs(strings);
return 0;
}
示例6: ParseFunctionName
/*!
* Parses lines for function/method names.
*
* \param line line to be processed
* \param lastline last line processed
* \param functionStack stack of functions
* \param functionName function name found
*
* \return 1 if function name is found
*/
int CCJavaCsCounter::ParseFunctionName(const string &line, string &lastline, StringVector &functionStack, string &functionName)
{
string tline, str;
size_t idx, tidx, cnt, cnt2;
unsigned int cyclomatic_cnt = 0;
string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$";
tline = CUtil::TrimString(line);
idx = tline.find('{');
if (idx != string::npos)
{
// check whether it is at first index, if yes then function name is at above line
if (idx == 0)
{
functionStack.push_back(lastline);
lastline.erase();
}
else
{
str = tline.substr(0, idx);
tidx = cnt = cnt2 = 0;
if (str[0] != '(' && str[0] != ':' && (lastline.length() < 1 || lastline[lastline.length() - 1] != ':'))
{
while (tidx != string::npos)
{
tidx = str.find('(', tidx);
if (tidx != string::npos)
{
cnt++;
tidx++;
}
}
if (cnt > 0)
{
tidx = 0;
while (tidx != string::npos)
{
tidx = str.find(')', tidx);
if (tidx != string::npos)
{
cnt2++;
tidx++;
}
}
}
}
// make sure parentheses are closed and no parent class listed
if ((cnt > 0 && cnt == cnt2) || (lastline.length() > 0 && lastline[lastline.length() - 1] == ';'))
lastline = str;
else
lastline += " " + str;
functionStack.push_back(CUtil::TrimString(lastline));
lastline.erase();
}
}
else if (tline.length() > 0 && tline[tline.length() - 1] != ';' &&
lastline.length() > 0 && lastline[lastline.length() - 1] != ';')
{
// append until all parentheses are closed
tidx = lastline.find('(');
if (tidx != string::npos)
{
cnt = 1;
while (tidx != string::npos)
{
tidx = lastline.find('(', tidx + 1);
if (tidx != string::npos)
cnt++;
}
tidx = lastline.find(')');
while (tidx != string::npos)
{
cnt++;
tidx = lastline.find(')', tidx + 1);
}
if (cnt % 2 != 0)
lastline += " " + tline;
else
lastline = tline;
}
else
lastline = tline;
}
else
lastline = tline;
idx = line.find('}');
if (idx != string::npos && !functionStack.empty())
{
str = functionStack.back();
//.........这里部分代码省略.........
示例7: ParseFunctionName
/*!
* Parses lines for function/method names.
*
* \param line line to be processed
* \param needIndentation last line processed
* \param functionStack stack of functions
* \param functionName function name found
*
* \return 1 if function name is found
*/
int CPythonCounter::ParseFunctionName(const string &line, string & needIndentation, StringVector &functionStack, string &functionName, vector<int> &indenStack, int & numWS)
{
string str;
size_t idx;
int functionWS = 0;
if(indenStack.empty()){
indenStack.push_back(0);
}
functionWS = indenStack.back(); // current function's indentation
if (functionStack.empty()) {
functionStack.push_back("");
needIndentation = "";
}
string tmp;
//get white spaces
tmp = line;
tmp = CUtil::TrimString(tmp, -1);
numWS = (unsigned)(line.length() - tmp.length());
//last line is with "def", if needIndentation=="YES"
//not consider the body of function is in the same line of "def"
if(needIndentation.length() >= 3 && needIndentation == "YES"){
indenStack.push_back(numWS);
needIndentation = "";
}
string mark = needIndentation;
idx = CUtil::FindKeyword(line, "def");
if (idx != string::npos)
{
if (idx + 4 < line.length())
{
str = line.substr(idx + 4);
functionStack.push_back(str);
needIndentation = "YES"; //indicate next line need to get the indentation
}
}
if (functionStack.size() == 1 || functionStack.size() == 0)
{
// dealing with some code out of any subroutines, it is a "main" code
return 2;
}
if(mark != "YES"){
if (functionWS > numWS && functionStack.size() > 1 ) {
//the first element in functionStack is ""
//we need to get the function and pop the function from the functionStack
if(needIndentation=="YES"){
//we have already pushed the new function to the functionStack
string tempp = functionStack.back(); //pop new function
functionStack.pop_back();
str = functionStack.back();
functionStack.pop_back();
functionStack.push_back(tempp); // push new function
indenStack.pop_back(); //pop the function's indentation in the stack
}
else{
str = functionStack.back();
functionStack.pop_back();
indenStack.pop_back(); //pop the function's indentation in the stack
}
//get function's name
idx = str.find("(");
if (idx != string::npos)
{
functionName = CUtil::ClearRedundantSpaces(str.substr(0, idx));
return 1;
}
}
}
return 0;
}
示例8: processJsonFiles
void processJsonFiles(String path)
{
try {
std::cout << "[INFO] Processing " << path << " configuration file." << endl;
boost::filesystem::path jsonPath(path);
CSelectionData selectionData;
CJsonReader reader = CJsonReader(path);
String programName = reader.getStringFromProperty("program-name");
if (programName.empty()) {
std::cerr << "[ERROR] Program name is missing in configuration file:" << path << std::endl;
return;
}
StringVector reductionList = reader.getStringVectorFromProperty("reduction-method");
if (reductionList.empty()) {
std::cerr << "[ERROR] reduction-algorithm is missing from the configuration file("
<< path << ")." << std::endl;
printPluginNames(kernel.getTestSuiteReductionPluginManager().getPluginNames());
return;
} else {
int iteration = reader.getIntFromProperty("iteration");
for (StringVector::const_iterator it = reductionList.begin(); it != reductionList.end(); ++it) {
if (*it == "duplation" && !iteration) {
std::cerr << "[ERROR] Missing iteration parameter for duplation reduction method in configuration file: "
<< path << "." << std::endl;
return;
}
if (*it == "random" && !iteration && reader.getIntVectorFromProperty("reduction-sizes").empty()) {
std::cerr << "[ERROR] Missing iteration or reduction-sizes parameter for random reduction method in configuration file: "
<< path << "." << std::endl;
return;
}
try {
kernel.getTestSuiteReductionPluginManager().getPlugin(*it);
} catch (std::out_of_range &e) {
std::cerr << "[ERROR] Invalid reduction algorithm name(" << *it
<< ") in configuration file: " << path << "." << std::endl;
return;
}
}
}
String covPath = reader.getStringFromProperty("coverage-data");
if (covPath[0] == '.') {
covPath = jsonPath.parent_path().string() + "/" + covPath;
}
String resPath = reader.getStringFromProperty("results-data");
if (resPath[0] == '.') {
resPath = jsonPath.parent_path().string() + "/" + resPath;
}
if (exists(covPath)
&& exists(resPath)) {
(std::cerr << "[INFO] loading coverage from " << covPath << " ...").flush();
selectionData.loadCoverage(covPath);
(std::cerr << " done\n[INFO] loading results from " << resPath << " ...").flush();
selectionData.loadResults(resPath);
(std::cerr << " done" << std::endl).flush();
} else {
std::cerr << "[ERROR] Missing or invalid input files in config file " << path << "." << std::endl;
return;
}
if (reader.getBoolFromProperty("globalize")) {
// Globalize data.
(std::cerr << "[INFO] Globalizing ... ").flush();
selectionData.globalize();
selectionData.filterToCoverage();
(std::cerr << " done" << std::endl).flush();
}
String dirPath = reader.getStringFromProperty("output-dir");
if (dirPath[0] == '.') {
dirPath = jsonPath.parent_path().string() + "/" + dirPath;
reader.setProperty("output-dir", dirPath);
}
if (!(boost::filesystem::exists(dirPath))) {
boost::filesystem::create_directory(dirPath);
}
boost::filesystem::path p = boost::filesystem::path(covPath).filename();
while (!reductionList.empty()) {
string reductionMethod = reductionList.back();
reductionList.pop_back();
ITestSuiteReductionPlugin *plugin = NULL;
std::ofstream outStream((dirPath + "/" + reductionMethod + "-" + p.string() + ".reduced").c_str());
if (!outStream.good()) {
throw CException("Reduction output file error.", reader.getStringFromProperty("coverage-data") + ".reduced");
}
try {
plugin = kernel.getTestSuiteReductionPluginManager().getPlugin(reductionMethod);
//.........这里部分代码省略.........
示例9: LSLOC
/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param paren_cnt count of parenthesis
* \param forflag found for flag
* \param found_forifwhile found for, if, or while flag
* \param found_while found while flag
* \param prev_char previous character
* \param data_continue continuation of a data declaration line
* \param temp_lines tracks physical line count
* \param phys_exec_lines number of physical executable lines
* \param phys_data_lines number of physical data lines
* \param found_for found for loop
* \param loopLevel nested loop level
* \param always_flag found always
* \param case_flag found case
* \param repeat_flag found repeat
*/
void CVerilogCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak,
unsigned int &paren_cnt, bool &forflag, bool &found_forifwhile, bool &found_while, char &prev_char,
bool &data_continue, unsigned int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines,
bool &found_for, StringVector &loopLevel, bool &always_flag, bool &case_flag, bool &repeat_flag)
{
// paren_cnt is used with 'for' statement only
size_t start = 0, startmax = 0; // starting index of the working string
size_t i = 0, strSize;
bool trunc_flag = false;
string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:";
string dataExclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:()."; // avoid double count of casts as data and executable lines (e.g. set { m_uiValue = (uint)value; }
bool found_end = false, found_endcase = false;
unsigned int cnt = 0;
bool newline = true;
string tmp = CUtil::TrimString(strLSLOC);
size_t tmpi;
// there may be more than 1 logical SLOC in this line
while (i < line.length())
{
tmp = CUtil::TrimString(line.substr(start, i + 1 - start));
if (CUtil::FindKeyword(tmp, "end") != string::npos && loopLevel.size() > 0 && loopLevel.back().compare("begin") == 0)
{
loopLevel.pop_back(); // pop begin
loopLevel.pop_back(); // pop looping
start = i + 1;
}
if ((tmpi = CUtil::FindKeyword(line.substr(start, i + 1 - start), "generate")) != string::npos)
{
strSize = CUtil::TruncateLine(i + 1 - start, strLSLOC.length(), this->lsloc_truncate, trunc_flag);
if (strSize > 0)
{
strLSLOC += line.substr(start, strSize);
strLSLOCBak += lineBak.substr(start, strSize);
}
if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag))
result->exec_lines[LOG]++;
strLSLOCBak = strLSLOC = "";
phys_exec_lines = temp_lines;
temp_lines = 0;
start = start + 7 + tmpi;
found_forifwhile = false;
forflag = false;
found_for = false;
always_flag = false;
case_flag = false;
repeat_flag = false;
}
if ((tmpi = CUtil::FindKeyword(line.substr(start, i + 1 - start), "forever")) != string::npos)
{
if (print_cmplx)
{
tmp = CUtil::TrimString(line.substr(start, i + 1 - start));
tmp = strLSLOC + " " + tmp;
if (CUtil::FindKeyword(tmp, "begin") != string::npos && loopLevel.size() > 0 && loopLevel.back().compare("looping") == 0)
{
loopLevel.push_back("begin");
}
else if (loopLevel.size() > 0)
{
// didn't find begin, so pop off since no longer in a looping block
loopLevel.pop_back();
}
loopLevel.push_back("looping");
// forever doesn't have any conditions so just add it to sloc
unsigned int loopCnt = 0;
for (StringVector::iterator lit = loopLevel.begin(); lit < loopLevel.end(); lit++)
{
if ((*lit) != "begin")
loopCnt++;
}
//.........这里部分代码省略.........
示例10: LSLOC
/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param paren_cnt count of parenthesis
* \param forflag found for flag
* \param found_forifwhile found for, if, or while flag
* \param found_while found while flag
* \param prev_char previous character
* \param data_continue continuation of a data declaration line
* \param temp_lines tracks physical line count
* \param phys_exec_lines number of physical executable lines
* \param phys_data_lines number of physical data lines
* \param inArrayDec marks an array declaration
* \param found_for found for loop
* \param loopLevel nested loop level
*/
void CPhpCounter::LSLOC(results* result, string line, string lineBak, string &strLSLOC, string &strLSLOCBak, unsigned int &paren_cnt,
bool &forflag, bool &found_forifwhile, bool &found_while, char &prev_char, bool &data_continue,
unsigned int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines,
bool &inArrayDec, bool &found_for, StringVector &loopLevel)
{
size_t start = 0;
size_t i = 0, strSize;
bool found_do, found_try, found_else, found_declare, trunc_flag = false;
string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:";
unsigned int cnt = 0;
string tmp = CUtil::TrimString(strLSLOC);
// do, try
found_do = (CUtil::FindKeyword(tmp, "do") != string::npos);
found_try = (CUtil::FindKeyword(tmp, "try") != string::npos);
// else, declare are treated differently, else and declare are included in SLOC, do and try are not
found_else = (CUtil::FindKeyword(tmp, "else") != string::npos);
found_declare = (CUtil::FindKeyword(tmp, "declare") != string::npos);
while (i < line.length()) // there may be more than 1 logical SLOC in this line
{
switch (line[i])
{
case ';': case '{': case ':': // LSLOC terminators
// ';' for normal executable or declaration statement
// '{' or ':' for starting a function or 'do' stmt or a block (which is counted)
// get the previous logical mark until i-1 index is the new LSLOC
// except 'do' precedes '{'
// except '}' precedes ';' ??
// do nothing inside 'for' statement
if (found_for == true && paren_cnt > 0 && line[i] == ';')
break;
// record open bracket for nested loop processing
// check for excluded loop keywords for alternate control syntax
if (print_cmplx)
{
cnt = 0;
CUtil::CountTally(line, exclude_loop, cnt, 1, exclude, "", "");
if (cnt > 0)
{
if ((unsigned int)loopLevel.size() > 0)
loopLevel.pop_back();
}
else if (line[i] == '{')
loopLevel.push_back("");
else if (line[i] == ';')
{
if ((unsigned int)loopLevel.size() > 0 && loopLevel.back() != "")
{
tmp = loopLevel.back();
if (tmp[tmp.length()-1] != ':')
loopLevel.pop_back();
}
}
else if (line[i] == ':')
{
if ((unsigned int)loopLevel.size() > 0 && loopLevel.back() != "")
{
tmp = CUtil::TrimString(line.substr(0, i));
if (CUtil::FindKeyword(tmp, loopLevel.back()) != string::npos)
{
tmp = loopLevel.back() + ":";
loopLevel.pop_back();
loopLevel.push_back(tmp);
}
}
}
}
// check for excluded keywords for alternate control syntax (don't count as LSLOC)
cnt = 0;
CUtil::CountTally(line, exclude_keywords, cnt, 1, exclude, "", "");
if (cnt > 0)
//.........这里部分代码省略.........
示例11: LSLOC
//.........这里部分代码省略.........
start = end + 1;
continue;
}
}
// record nested loops
if (print_cmplx)
{
bool new_loop = false;
i = CUtil::FindKeyword(tmp, "end do", start, end, false);
if (i != string::npos)
i = string::npos;
else
i = CUtil::FindKeyword(tmp, "do", start, end, false);
if (i != string::npos)
{
// check for label after do
found = false;
if (i + 2 < end && tmp[i+2] == ' ')
{
for (j = i + 3; j <= end; j++)
{
if (tmp[j] != ' ')
{
for (k = j; k <= end; k++)
{
if (tmp[k] == ' ' || tmp[k] == ',')
break;
}
k--;
str = CUtil::TrimString(tmp.substr(j, k - j + 1));
if (CUtil::IsInteger(str))
{
loopEnd.push_back(str);
found = true;
}
break;
}
}
}
if (!found)
loopEnd.push_back("end do");
new_loop = true;
}
else
{
i = CUtil::FindKeyword(tmp, "end forall", start, end, false);
if (i != string::npos)
i = string::npos;
else
i = CUtil::FindKeyword(tmp, "forall", start, end, false);
if (i != string::npos)
{
loopEnd.push_back("end forall");
new_loop = true;
}
else if (loopEnd.size() > 0)
{
str = loopEnd.back();
if (CUtil::FindKeyword(tmp, str, start, end, false) != string::npos)
{
loopEnd.pop_back();
if (CUtil::IsInteger(str))
{
// remove additional label terminators
if (loopEnd.size() > 0)