std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter) { auto start = 0U; auto end = input.find(delimiter); std::vector<generic_string> output; const size_t delimiterLength = delimiter.length(); while (end != std::string::npos) { output.push_back(input.substr(start, end - start)); start = end + delimiterLength; end = input.find(delimiter, start); } output.push_back(input.substr(start, end)); return output; }
static void replaceStr(generic_string & str, generic_string str2BeReplaced, generic_string replacement) { size_t pos = str.find(str2BeReplaced); if (pos != generic_string::npos) str.replace(pos, str2BeReplaced.length(), replacement); }
generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace) { size_t pos = 0; while ((pos = subject.find(search, pos)) != std::string::npos) { subject.replace(pos, search.length(), replace); pos += replace.length(); } return subject; }
void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { //do nothing, go down to select the dir generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath; generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); vector<generic_string> linarPathArray = split(pathSuffix, '\\'); HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray); if (foundItem) _treeView.selectItem(foundItem); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { ::MessageBox(_hParent, TEXT("A sub-folder of the folder you want to open exists.\rPlease remove it from the panel before you add this one."), rootFolderPath.c_str(), MB_OK); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }
generic_string ProjectPanel::getRelativePath(const generic_string & filePath, const TCHAR *workSpaceFileName) { TCHAR wsfn[MAX_PATH]; lstrcpy(wsfn, workSpaceFileName); ::PathRemoveFileSpec(wsfn); size_t pos_found = filePath.find(wsfn); if (pos_found == generic_string::npos) return filePath; const TCHAR *relativeFile = filePath.c_str() + lstrlen(wsfn); if (relativeFile[0] == '\\') ++relativeFile; return relativeFile; }
void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { printStr(TEXT("do nothing, go down to select the dir.")); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { printStr(TEXT("remove old, add this one")); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }