DefinitionNode *DefinitionNode::findByPath(const string &path) const { if (path.empty()) { return NULL; } else if (path[0] == '/') { if (path.length() == 1) { return root; } else if (root == this) { return findByPath(path.substr(1)); } else { return root->findByPath(path); } } else { size_t seppos = path.find("/"); string child_name = (seppos == string::npos) ? path : path.substr(0, seppos); DefinitionNode *child = findChildByName(child_name); if (child) { if (seppos == string::npos) { return child; } else { return child->findByPath(path.substr(seppos + 1)); } } else { return NULL; } } }
bool K3bDirItem::mkdir( const QString& dirPath ) { // // An absolut path always starts at the root item // if( dirPath[0] == '/' ) { if( parent() ) return parent()->mkdir( dirPath ); else return mkdir( dirPath.mid( 1 ) ); } if( findByPath( dirPath ) ) return false; QString restPath; QString dirName; int pos = dirPath.find( '/' ); if( pos == -1 ) { dirName = dirPath; } else { dirName = dirPath.left( pos ); restPath = dirPath.mid( pos+1 ); } K3bDataItem* dir = find( dirName ); if( !dir ) dir = new K3bDirItem( dirName, doc(), this ); else if( !dir->isDir() ) return false; if( !restPath.isEmpty() ) return static_cast<K3bDirItem*>(dir)->mkdir( restPath ); return true; }