bool ModelStatement::hasBaseClassRef() const { OovString attrName = getName(); bool present = attrName.find(getBaseClassMemberRefSep()) != std::string::npos; if(!present) { present = attrName.find(getBaseClassMemberCallSep()) != std::string::npos; } return(present); }
void NameValueRecord::insertLine(OovString lineBuf) { size_t colonPos = lineBuf.find(mapDelimiter); if(colonPos != std::string::npos) { std::string key = lineBuf.substr(0, colonPos); size_t termPos = lineBuf.find('\n'); std::string value = lineBuf.substr(colonPos+1, termPos-(colonPos+1)); setNameValue(key, value); } }
size_t FilePathGetPosSegment(OovStringRef const path, OovStringRef const seg) { OovString lowerPath; // Only do case insensitive compares for Windows. #ifdef __linux__ lowerPath = path; #else lowerPath.setLowerCase(path); #endif OovString lowerSeg; #ifdef __linux__ lowerSeg = seg; #else lowerSeg.setLowerCase(seg); #endif size_t pos = lowerPath.find(lowerSeg); size_t foundPos = std::string::npos; if(pos != std::string::npos) { if(pos > 0) { size_t endPos = pos + lowerSeg.length(); if(FilePathIsPathSep(path, pos-1) && FilePathIsPathSep(path, endPos)) { foundPos = pos-1; } } } return foundPos; }
// returns std::string::npos if not found. static size_t findPathSep(OovStringRef const path, size_t startPos = 0) { const OovString str = path; size_t bpos = str.find('\\', startPos); size_t fpos = str.find('/', startPos); size_t pos = std::string::npos; if(bpos != std::string::npos && fpos != std::string::npos) { pos = (bpos > fpos) ? fpos : bpos; } else if(bpos != std::string::npos) pos = bpos; else if(fpos != std::string::npos) pos = fpos; return pos; }
static bool mapPath(ZonePathMap const &map, OovString const &origName, OovString &newName) { bool replaced = false; size_t starti = 0; newName = origName; do { size_t firstFoundi = OovString::npos; ZonePathReplaceItem const *repItem = nullptr; for(auto const &mapItem : map) { size_t foundi = newName.find(mapItem.mSearchPath, starti); if(foundi < firstFoundi) { repItem = &mapItem; firstFoundi = foundi; } } if(firstFoundi != OovString::npos) { newName.replace(firstFoundi, repItem->mSearchPath.length(), repItem->mReplacePath); starti = firstFoundi + repItem->mReplacePath.length(); replaced = true; } else starti = OovString::npos; } while(starti != OovString::npos); return replaced; }
static bool isDevelopment() { static enum eDevel { Uninit, Devel, Deploy } devel; if(devel == Uninit) { OovString path = Project::getBinDirectory(); size_t pos = path.find("bin"); if(pos != std::string::npos) { path.replace(pos, 3, "lib"); } OovStatus status(true, SC_File); if(FileIsDirOnDisk(path, status)) { devel = Deploy; } else { devel = Devel; } if(status.needReport()) { status.reported(); } } return(devel == Devel); }
/// Copy a single source file and make a comment that contains the hit count /// for each instrumented line. static void updateCovSourceCounts(OovStringRef const relSrcFn, std::vector<int> &counts) { FilePath srcFn(Project::getCoverageSourceDirectory(), FP_Dir); srcFn.appendFile(relSrcFn); FilePath dstFn(Project::getCoverageProjectDirectory(), FP_Dir); dstFn.appendFile(relSrcFn); File srcFile; OovStatus status = srcFile.open(srcFn, "r"); if(status.ok()) { status = FileEnsurePathExists(dstFn); if(status.ok()) { File dstFile; status = dstFile.open(dstFn, "w"); if(status.ok()) { char buf[1000]; size_t instrCount = 0; while(srcFile.getString(buf, sizeof(buf), status)) { if(strstr(buf, "COV_IN(")) { if(instrCount < counts.size()) { OovString countStr = " // "; countStr.appendInt(counts[instrCount]); OovString newStr = buf; size_t pos = newStr.find('\n'); newStr.insert(pos, countStr); if(newStr.length() < sizeof(buf)-1) { strcpy(buf, newStr.getStr()); } } instrCount++; } status = dstFile.putString(buf); if(!status.ok()) { break; } } } } } if(status.needReport()) { OovString err = "Unable to transfer coverage "; err += srcFn; err += " "; err += dstFn; status.report(ET_Error, err); } }
OovString Project::getSrcRootDirRelativeSrcFileName(OovStringRef const srcFileName, OovStringRef const srcRootDir) { OovString relSrcFileName = srcFileName; size_t pos = relSrcFileName.find(srcRootDir.getStr()); if(pos != std::string::npos) { relSrcFileName.erase(pos, srcRootDir.numBytes()); FilePathRemovePathSep(relSrcFileName, 0); } return relSrcFileName; }
void NameValueRecord::insertBufToMap(OovString const buf) { size_t pos = 0; mNameValues.clear(); while(pos != std::string::npos) { size_t endPos = buf.find('\n', pos); std::string line(buf, pos, endPos-pos); insertLine(line); pos = endPos; if(pos != std::string::npos) pos++; } }
/// Use the filename to make an identifier. static std::string makeOrigCovFn(OovStringRef const fn) { OovString covFn = fn; if(covFn.find("COV_") != std::string::npos) { covFn.erase(0, 4); } covFn.replaceStrs("_", "/"); size_t pos = covFn.rfind('/'); if(pos != std::string::npos) { covFn.replace(pos, 1, "."); } return covFn; }
OovString const Project::getLibDirectory() { OovString path = getBinDirectory(); #ifdef __linux__ // During development, the libs/.so are in the bin dir. if(!isDevelopment()) { size_t pos = path.find("bin"); if(pos != std::string::npos) { path.replace(pos, 3, "lib"); } } #endif return path; }
OovStringVec StringSplit(char const * const str, char const * const delimiterStr) { OovString tempStr = str; OovStringVec tokens; size_t start = 0; size_t end = 0; const size_t delimLen = strlen(delimiterStr); while(end != std::string::npos) { end = tempStr.find(delimiterStr, start); size_t len = (end == std::string::npos) ? std::string::npos : end - start; OovString splitStr = tempStr.substr(start, len); tokens.push_back(splitStr); start = (( end > (std::string::npos - delimLen)) ? std::string::npos : end + delimLen); } return tokens; }
OovStringVec Tokenizer::getDiagResults() { OovStringVec diagResults; if(mTransUnit) { int numDiags = clang_getNumDiagnostics(mTransUnit); for (int i = 0; i<numDiags && diagResults.size() < 10; i++) { CXDiagnostic diag = clang_getDiagnostic(mTransUnit, i); // CXDiagnosticSeverity sev = clang_getDiagnosticSeverity(diag); // if(sev >= CXDiagnostic_Error) OovString diagStr = getDisposedString(clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions())); if(diagStr.find(mSourceFilename) != std::string::npos) { diagResults.push_back(diagStr); } } } return diagResults; }
void CompoundValueRef::parseStringRef(OovStringRef const strIn, OovStringVec &vec, char delimiter) { OovString str = strIn; size_t startArgPos = 0; while(startArgPos != std::string::npos) { size_t endColonPos = str.find(delimiter, startArgPos); std::string tempStr = str.substr(startArgPos, endColonPos-startArgPos); // For compatibility with previous files, allow a string that is // after the last colon. Previous versions that had the extra string // did not allow null strings. if(endColonPos != std::string::npos || tempStr.length() > 0) { vec.push_back(tempStr); } startArgPos = endColonPos; if(startArgPos != std::string::npos) startArgPos++; } }
OovStringVec StringSplit(char const * const str, OovStringVec const &delimiters, bool keepZeroLengthStrings) { OovString tempStr = str; OovStringVec tokens; size_t start = 0; size_t end = 0; size_t lowestEnd = 0; while(end != std::string::npos) { lowestEnd = std::string::npos; size_t delimLen = std::string::npos; for(auto const &delim : delimiters) { end = tempStr.find(delim, start); if(end < lowestEnd) { delimLen = strlen(delim.getStr()); lowestEnd = end; } } end = lowestEnd; /// Don't add zero length strings when two delimiters are next to each other. size_t len = (end == std::string::npos) ? std::string::npos : end - start; if(keepZeroLengthStrings || len > 0) { OovString splitStr = tempStr.substr(start, len); if(splitStr.length() > 0) { tokens.push_back(splitStr); } } start = (( end > (std::string::npos - delimLen)) ? std::string::npos : end + delimLen); } return tokens; }
bool ModelType::isTypedefType(OovString const &name) { return(name.find("<<type") != std::string::npos); }
bool ModelType::isTemplateDefType(OovString const &name) { return(name.find("<<templ") != std::string::npos); }