31 using namespace ystdex;
46 n = n == StringType::npos ? 0
47 : ptr->find_first_not_of(Slash, ptr->find(Slash, n));
52 Path::iterator::operator--()
54 n = n == 0 ? StringType::npos
55 : ptr->rfind(Slash, ptr->find_last_not_of(Slash, n)) + 1;
59 Path::iterator::value_type
62 if(n == StringType::npos)
65 StringType::size_type p(ptr->find(Slash, n));
67 return ptr->substr(n, p == StringType::npos ? StringType::npos : p - n);
72 Path::operator/=(
const Path& path)
79 erase((--
end()).GetPosition());
81 *
this = GetRootPath();
103 Path::GetRootName()
const
109 Path::GetRootDirectory()
const
114 Path::GetRootPath()
const
116 return GetRootName() / GetRootDirectory();
119 Path::GetRelativePath()
const
124 Path::GetParentPath()
const
126 return substr(0, (--
end()).GetPosition());
129 Path::GetFilename()
const
131 return empty() ?
Path() : *--
end();
134 Path::GetStem()
const
139 Path::GetExtension()
const
145 Path::MakeAbsolute(
const Path&)
152 Path::NormalizeTrailingSlash()
157 const bool has_trailing_slash(back() == Slash);
159 if(has_trailing_slash && size() == 1)
163 if(has_trailing_slash)
169 if(!has_trailing_slash)
177 Path::RemoveFilename()
184 Path::ReplaceExtension(
const Path& new_extension)
187 *
this += new_extension;
200 return p ? (*++p ? p :
nullptr) : path;
207 return p == string::npos ?
string(path) : path.substr(p + 1);
215 return p == string::npos ?
string() : path.substr(0, p + 1);
219 SplitPath(
const string& path,
string& directory,
string& file)
223 if(p == string::npos)
224 yunseq((directory =
"", file = path));
226 yunseq((directory = path.substr(0, p + 1),
227 file = path.substr(p + 1)));
234 const string::size_type p(name.rfind(
'.'));
236 return p == string::npos ?
string(name) : name.substr(0, p);
246 return !strncmp(str, name,
strlen_n(str));
251 if(str.length() > name.length())
253 return !name.compare(0, str.length(), str);
261 if(pea - a != peb - b)
283 const char* p(strrchr(name,
'.'));
285 return p && *++p ? p :
nullptr;
290 const string::size_type p(name.rfind(
'.'));
292 return p == string::npos ?
string() : name.substr(p + 1);
303 return !strcmp(str, p);
308 if(str.length() > name.length())
324 return std::strcmp(pa, pb) != 0;
332 return std::strcmp(ea.c_str(), eb.c_str()) != 0;
365 ? String(buf) : String();
371 return bool(HFileNode(pathstr.c_str()));
376 : Directory((path && *path) ? path :
FS_Root), hList(new ListType())
378 FileList::FileList(
const string& path)
379 : Directory(path.empty() ?
FS_Root : path.c_str()), hList(new ListType())
382 : Directory(path.empty() ?
FS_Root : path.GetMBCS(
CP_Path).c_str()),
383 hList(new ListType())
387 FileList::operator=(
const Path& d)
391 (Directory = d).NormalizeTrailingSlash();
398 FileList::operator/=(
const Path& d)
400 return *
this = (Directory / d);
404 FileList::ListType::size_type
405 FileList::ListItems()
407 HFileNode dir(Directory.GetNativeString().c_str());
412 YAssert(
bool(hList),
"Null handle found.");
415 while((++dir).LastError == 0)
420 while((++dir).LastError == 0)
422 hList->push_back(std::strcmp(dir.GetName(),
FS_Parent)
423 && dir.IsDirectory() ? String(
425 : String(dir.GetName(),
CP_Path));