/*! * Detect the character(s) that is used for marking a line as a comment line. * If such a character is found, it is added to LineCommentStart vector. * Since assembly code counter covers multiple assembly languages, there can be * mulitple markers in the same program. * GNU Assembler, for instance, supports # and ; for comment lines * * \param fmap list of file lines * */ void CAssemblyCounter::FindLineCommentMarker(filemap* fmap) { StringVector markerChecklist; // contains line comment markers that need to be checked/tested markerChecklist.push_back("#"); markerChecklist.push_back(";"); markerChecklist.push_back("|"); LineCommentStart.clear(); // remove all existing values just in case it was set unintentionally /* Algorithm: 1. Read each line a. For each comment marker, find position/index of the marker i. If position is 0, a marker is found 1. Save/add the marker: LineCommentStart.push_back() 2. Remove the marker from the check list ii. If position is > 0 && not last index && (position-1) is a space, a marker is found. 1. Save/add the marker: LineCommentStart.push_back() 2. Remove the marker from the check list */ StringVector::iterator nextMarker; string line; size_t position; for (filemap::iterator fit = fmap->begin(); fit != fmap->end(); fit++) { line = fit->line; nextMarker = markerChecklist.begin(); while (nextMarker != markerChecklist.end()) { position = line.find(*nextMarker); if (position == string::npos) { nextMarker++; continue; } else if (position == 0) { LineCommentStart.push_back(*nextMarker); nextMarker = markerChecklist.erase(nextMarker); } else if (position > 0 && position != (line.length() - 1) && line.at(position - 1) == ' ') { LineCommentStart.push_back(*nextMarker); nextMarker = markerChecklist.erase(nextMarker); } else nextMarker++; } } }
void Metadata::removeFromMetadataCollection(const string& key, const string& value, TransactionFactory& transactionFactory, TransactionContext& transactionContext) { auto_ptr<Transaction> transaction = transactionFactory.createTransaction(transactionContext); StringVector values = getMetadataCollection(key, *transaction); values.erase(remove(values.begin(), values.end(), value), values.end()); putMetadata(key, values, *transaction); transaction->commit(); }
ERMsg CUIEnvCanRadar::CleanRadarList(StringVector& radarList, CCallback& callback)const { ERMsg msg; callback.PushTask(GetString(IDS_CLEAN_LIST), radarList.size()); //callback.SetNbStep(radarList.size()); for (StringVector::iterator it = radarList.begin(); it != radarList.end() && msg;) { if (FileExists(GetOutputFilePath(as<size_t>(TYPE), *it))) it = radarList.erase(it); else it++; msg += callback.StepIt(); } callback.PopTask(); return msg; }
//remove dedup string in strs-vector void removeDuplicate(StringVector& strs) { if(1 >= strs.size()) return; StringVector sstrs = strs; //dedup by sort std::sort(sstrs.begin(),sstrs.end()); std::string rstr = ""; //result of temp bool isReplicate = false; //flag for(std::size_t i = 0;i < sstrs.size() - 1;++i) { if(sstrs[i] == sstrs[i+1]) { rstr = sstrs[i]; isReplicate = true; } else { bool isFirst = true; for(std::size_t ii = 0;ii< strs.size();++ii) { if(rstr == strs[i]) { if(isFirst) { isFirst = false; } else { strs.erase(strs.begin() + ii); ii--; } } } isReplicate = false; } } }
bool CConverToMK::ProcessPath(const char* pszVCPath, const char* pszPath, string& strRes ) { if (0 == pszPath || !*pszPath) { return false; } if (strRes.size()) { strRes = ""; } filesystem::path kVCFile(pszVCPath); filesystem::path kMKFile(m_pszMKFile); filesystem::path kInputPath(pszPath); unsigned int uiParentFolderCount = 0; string strFilename = kInputPath.filename().string(); kInputPath = kInputPath.parent_path(); kVCFile = kVCFile.parent_path(); kMKFile = kMKFile.parent_path(); StringVector kVCSets; StringVector kMKSets; StringVector kTargetSets; StringVector kTempVC; BOOST_AUTO(pkInputPathPos,kInputPath.begin()); BOOST_AUTO(pkVCPos,kVCFile.begin()); BOOST_AUTO(pkMKPos,kMKFile.begin()); while (pkInputPathPos != kInputPath.end()) { string strPath = pkInputPathPos->string().c_str(); if (strcmp(strPath.c_str(),"..") == 0) { uiParentFolderCount++; pkInputPathPos++; continue; } kTargetSets.push_back(strPath); pkInputPathPos++; } while (pkVCPos != kVCFile.end()) { filesystem::path strVC = *pkVCPos; kVCSets.push_back(strVC.string()); pkVCPos++; } kTempVC = kVCSets; while (0 < uiParentFolderCount) { kTempVC.pop_back(); kVCSets.pop_back(); uiParentFolderCount--; } while (pkMKPos != kMKFile.end()) { string strVC = pkMKPos->string(); kMKSets.push_back(strVC); pkMKPos++; } unsigned int uiMin = kMKSets.size() < kVCSets.size() ? kMKSets.size() : kVCSets.size(); unsigned int uiIndex = 0; for (uiIndex = 0;uiIndex < uiMin;uiIndex++) { if (strcmp(kMKSets[uiIndex].c_str(),kVCSets[uiIndex].c_str()) != 0) { break; } } kMKSets.erase(kMKSets.begin(),kMKSets.begin() + uiIndex); kVCSets.erase(kVCSets.begin(),kVCSets.begin() + uiIndex); strRes += "."; string strPrePath = ""; for (unsigned int uiIndex = 0;uiIndex < kTempVC.size();uiIndex++) { strPrePath += kTempVC[uiIndex]; strPrePath += "\\"; } for (unsigned int uiIndex = 0;uiIndex < kVCSets.size();uiIndex++) { strRes += "\\"; strRes += kVCSets[uiIndex]; } for (unsigned int uiIndex = 0;uiIndex < kTargetSets.size();uiIndex++) { strRes += "\\"; strPrePath += kTargetSets[uiIndex]; strPrePath += "\\"; strRes += kTargetSets[uiIndex]; } strRes += "\\"; strRes += strFilename; strPrePath += strFilename; if (!CheckFileExist(strPrePath.c_str())) { return false; } return true; }