mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 11:19:10 +00:00
Add plFileName string specialization for filename manipulation
This commit is contained in:
@ -84,7 +84,7 @@ public:
|
||||
virtual ~hsStream() { }
|
||||
|
||||
// Pre-filename-stringification shortcut:
|
||||
bool Open_TEMP(const plString & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
|
||||
bool Open_TEMP(const plFileName & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
|
||||
|
||||
virtual bool Open(const char *, const char * = "rb")=0;
|
||||
virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0;
|
||||
|
@ -878,3 +878,71 @@ size_t ustrlen(const UniChar *ustr, size_t max)
|
||||
;
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/* plFileName */
|
||||
plString plFileName::GetFileName() const
|
||||
{
|
||||
int end = FindLast('/');
|
||||
if (end < 0)
|
||||
end = FindLast('\\');
|
||||
if (end < 0)
|
||||
return *this;
|
||||
|
||||
return Substr(end + 1);
|
||||
}
|
||||
|
||||
plString plFileName::GetFileExt() const
|
||||
{
|
||||
int dot = FindLast('.');
|
||||
|
||||
// Be sure not to get a dot in the directory!
|
||||
int end = FindLast('/');
|
||||
if (end < 0)
|
||||
end = FindLast('\\');
|
||||
|
||||
if (dot > end)
|
||||
return Substr(dot + 1);
|
||||
|
||||
return plString::Null;
|
||||
}
|
||||
|
||||
plString plFileName::GetFileNameNoExt() const
|
||||
{
|
||||
int dot = FindLast('.');
|
||||
|
||||
int end = FindLast('/');
|
||||
if (end < 0)
|
||||
end = FindLast('\\');
|
||||
|
||||
// Be sure not to get a dot in the directory!
|
||||
if (dot > end)
|
||||
return Substr(end + 1, dot - end - 1);
|
||||
return Substr(end + 1);
|
||||
}
|
||||
|
||||
plFileName plFileName::StripFileName() const
|
||||
{
|
||||
int end = FindLast('/');
|
||||
if (end < 0)
|
||||
end = FindLast('\\');
|
||||
if (end < 0)
|
||||
return *this;
|
||||
|
||||
return Left(end + 1);
|
||||
}
|
||||
|
||||
plFileName plFileName::StripFileExt() const
|
||||
{
|
||||
int dot = FindLast('.');
|
||||
|
||||
// Be sure not to get a dot in the directory!
|
||||
int end = FindLast('/');
|
||||
if (end < 0)
|
||||
end = FindLast('\\');
|
||||
|
||||
if (dot > end)
|
||||
return Left(dot);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -656,4 +656,22 @@ private:
|
||||
/** \p strlen implementation for UniChar based C-style string buffers. */
|
||||
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
|
||||
|
||||
|
||||
/* plFileName - custom extension of plString for manipulating filenames */
|
||||
class plFileName : public plString
|
||||
{
|
||||
public:
|
||||
plFileName() { }
|
||||
plFileName(const char *cstr) : plString(cstr) { }
|
||||
plFileName(const plString ©) : plString(copy) { }
|
||||
plFileName(const plFileName ©) : plString(copy) { }
|
||||
|
||||
plString GetFileName() const;
|
||||
plString GetFileExt() const;
|
||||
plString GetFileNameNoExt() const;
|
||||
|
||||
plFileName StripFileName() const;
|
||||
plFileName StripFileExt() const;
|
||||
};
|
||||
|
||||
#endif //plString_Defined
|
||||
|
Reference in New Issue
Block a user