(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 plString
{
public:
/** Construct an empty filename. */
plFileName() { }
/** Construct a filename from the UTF-8 character data in \a cstr. */
plFileName(const char *cstr) : plString(cstr) { }
/** Construct a filename from the plString argument \a copy. */
plFileName(const plString ©) : plString(copy) { }
/** Copy constructor. */
plFileName(const plFileName ©) : plString(copy) { }
/** 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;
/** 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); }
};
#endif //plString_Defined