Changeset b87f2f8e1875…
Parent 0d28542b5ed2…
by
Changes to one file · Browse files at b87f2f8e1875 Showing diff from parent 0d28542b5ed2 Diff from another changeset...
@@ -64,39 +64,49 @@ }
-int Directory::add(const std::string& n, Direntry& e)
+int Directory::add(const std::string& n_in, Direntry& e)
{
std::string base;
std::string rest;
+
+ std::string n = n_in;
+ Directory* cur = this;
+
+ for (;;)
+ {
- if (!splitbase(n, base, rest)) {
- TDEBUG_TRACE("Directory(" << path() << ")::add(" << n << "): splitbase returned 0");
- return 0;
+ if (!splitbase(n, base, rest)) {
+ TDEBUG_TRACE("Directory(" << path() << ")::add(" << n_in
+ << "): splitbase returned 0");
+ return 0;
+ }
+
+ if (base.empty())
+ {
+ e.name = n;
+ cur->files_.push_back(e);
+ return 1;
+ }
+
+ Directory* d = 0;
+ for (DirsT::iterator i = cur->subdirs_.begin();
+ i != cur->subdirs_.end(); ++i)
+ {
+ if ((*i)->name_ == base) {
+ d = *i;
+ break;
+ }
+ }
+
+ if (!d)
+ {
+ d = new Directory(cur, base, cur->path());
+ cur->subdirs_.push_back(d);
+ }
+
+ n = rest;
+ cur = d;
}
-
- if (base.empty())
- {
- e.name = n;
- files_.push_back(e);
- return 1;
- }
-
- Directory* d = 0;
- for (DirsT::iterator i = subdirs_.begin(); i != subdirs_.end(); ++i)
- {
- if ((*i)->name_ == base) {
- d = *i;
- break;
- }
- }
-
- if (!d)
- {
- d = new Directory(this, base, path());
- subdirs_.push_back(d);
- }
-
- return d->add(rest, e);
}
|
Loading...