(num)); }
/** Append a base-10 formatted double to the stream. */
plStringStream &operator<<(double num);
/** Append a single Latin-1 character to the stream. */
plStringStream &operator<<(char ch) { return append(&ch, 1); }
/** Append the contents of \a text to the stream. */
plStringStream &operator<<(const plString &text)
{
return append(text.c_str(), text.GetSize());
}
/** Returns a pointer to the beginning of the stream buffer.
* \warning This pointer is not null-terminated.
*/
const char *GetRawBuffer() const
{
return ICanHasHeap() ? fBuffer : fShort;
}
/** Return the size (in bytes) of the stream's data. */
size_t GetLength() const { return fLength; }
/** Convert the stream's data to a UTF-8 string. */
plString GetString() const { return plString::FromUtf8(GetRawBuffer(), fLength); }
/** Reset the stream's append pointer back to the beginning.
* This does not incur a reallocation of the buffer -- it is left
* with as much space as it had before, making this method more
* useful for re-using string streams in loops.
*/
void Truncate() { fLength = 0; }
private:
union {
char *fBuffer;
char fShort[STRING_STACK_SIZE];
};
size_t fBufSize, fLength;
bool ICanHasHeap() const { return fBufSize > STRING_STACK_SIZE; }
};
/** \p strlen implementation for UniChar based C-style string buffers. */
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
#if HS_BUILD_FOR_WIN32
# define PATH_SEPARATOR '\\'
# define PATH_SEPARATOR_STR "\\"
#else
# define PATH_SEPARATOR '/'
# define PATH_SEPARATOR_STR "/"
#endif
/** Subclass of plString with specific methods to help deal with common
* filename manipulation tasks.
*/
class plFileName
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : fName(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString ©) : fName(copy) { }
/** Copy constructor. */
plFileName(const plFileName ©) : fName(copy.fName) { }
/** Assignment operator. Same as plFileName(const char *). */
plFileName &operator=(const char *cstr)
{
fName.operator=(cstr);
return *this;
}
/** Assignment operator. Same as plFileName(const plString &). */
plFileName &operator=(const plString ©)
{
fName.operator=(copy);
return *this;
}
/** Assignment operator. Same as plFileName(const plFileName &). */
plFileName &operator=(const plFileName ©)
{
fName.operator=(copy.fName);
return *this;
}
/** Return whether this filename is valid (not empty). */
bool IsValid() const { return !fName.IsEmpty(); }
/** Return the length of the filename string (UTF-8). */
size_t GetSize() const { return fName.GetSize(); }
/** Convert the filename to a string. This does not resolve relative
* paths or normalize slashes, it just returns the stored name string.
*/
const plString &AsString() const { return fName; }
/** Return the name portion of the path (including extension).
* For example:
* plFileName("C:\\Path\\Filename.ext") => "Filename.ext"
*/
plString GetFileName() const;
/** Return the file extension from the filename.
* For example:
* plFileName("C:\\Path\\Filename.ext") => "ext"
*/
plString GetFileExt() const;
/** Return the name portion of the path, excluding its extension.
* For example:
* plFileName("C:\\Path\\Filename.ext") => "Filename"
*/
plString GetFileNameNoExt() const;
/** Return the path with the filename portion stripped off.
* For example:
* plFileName("C:\\Path\\Filename.ext") => "C:\\Path"
*/
plFileName StripFileName() const;
/** Return the filename with the extension stripped off.
* For example:
* plFileName("C:\\Path\\Filename.ext") => "C:\\Path\\Filename"
*/
plFileName StripFileExt() const;
/** Normalize slashes to a particular format. By default, we use the
* OS's native slash format.
* For example:
* plFileName("C:\\Path/Filename.ext").Normalize("\\") => "C:\\Path\\Filename.ext"
*/
plFileName Normalize(char slash = PATH_SEPARATOR) const;
/** Join two path components together with the correct path separator.
* For example:
* plFileName::Join("C:\\Path", "Filename.ext") => "C:\\Path\\Filename.ext"
*/
static plFileName Join(const plFileName &base, const plFileName &path);
/** Join three path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2)
{ return Join(Join(base, path), path2); }
/** Join four path components together with the correct path separator.
* \todo Make this more efficient.
*/
static plFileName Join(const plFileName &base, const plFileName &path,
const plFileName& path2, const plFileName &path3)
{ return Join(Join(Join(base, path), path2), path3); }
private:
plString fName;
};
#endif //plString_Defined