18 Filename(
const std::string &filename) {
27 Filename(
const std::wstring &filename) {
46 _filename(copy._filename.c_str()),
47 _dirname_end(copy._dirname_end),
48 _basename_start(copy._basename_start),
49 _basename_end(copy._basename_end),
50 _extension_start(copy._extension_start),
51 _hash_start(copy._hash_start),
52 _hash_end(copy._hash_end),
61 Filename(std::string &&filename) noexcept : _flags(0) {
62 (*this) = std::move(filename);
70 _filename(std::move(from._filename)),
71 _dirname_end(from._dirname_end),
72 _basename_start(from._basename_start),
73 _basename_end(from._basename_end),
74 _extension_start(from._extension_start),
75 _hash_start(from._hash_start),
76 _hash_end(from._hash_end),
88 _basename_end(std::string::npos),
89 _extension_start(std::string::npos),
90 _hash_start(std::string::npos),
91 _hash_end(std::string::npos),
99 text_filename(
const Filename &filename) {
109 text_filename(
const std::string &filename) {
119 binary_filename(
const Filename &filename) {
129 binary_filename(
const std::string &filename) {
139 dso_filename(
const std::string &filename) {
141 result.set_type(T_dso);
149 executable_filename(
const std::string &filename) {
151 result.set_type(T_executable);
170 operator = (
const std::string &filename) {
171 _filename = filename;
183 operator = (
const std::wstring &filename) {
187 return operator = (encoder.
get_text());
194 operator = (
const char *filename) {
195 assert(filename !=
nullptr);
196 return (*
this) = std::string(filename);
204 _filename = copy._filename;
205 _dirname_end = copy._dirname_end;
206 _basename_start = copy._basename_start;
207 _basename_end = copy._basename_end;
208 _extension_start = copy._extension_start;
209 _hash_start = copy._hash_start;
210 _hash_end = copy._hash_end;
211 _flags = copy._flags;
219 operator = (std::string &&filename) noexcept {
220 _filename = std::move(filename);
232 operator = (
Filename &&from) noexcept {
233 _filename = std::move(from._filename);
234 _dirname_end = from._dirname_end;
235 _basename_start = from._basename_start;
236 _basename_end = from._basename_end;
237 _extension_start = from._extension_start;
238 _hash_start = from._hash_start;
239 _hash_end = from._hash_end;
240 _flags = from._flags;
248 operator
const std::string & ()
const {
255 INLINE
const char *Filename::
257 return _filename.c_str();
263 INLINE
bool Filename::
265 return _filename.empty();
271 INLINE
size_t Filename::
273 return _filename.length();
279 INLINE
char Filename::
280 operator [] (
size_t n)
const {
281 assert(n < _filename.length());
288 INLINE std::string Filename::
289 substr(
size_t begin)
const {
290 return _filename.substr(begin);
296 INLINE std::string Filename::
297 substr(
size_t begin,
size_t end)
const {
298 return _filename.substr(begin, end);
359 return _filename.substr(0, _dirname_end);
368 return _filename.substr(_basename_start);
378 return _filename.substr(0, _basename_end);
387 if (_basename_end == std::string::npos) {
388 return _filename.substr(_basename_start);
390 return _filename.substr(_basename_start, _basename_end - _basename_start);
401 if (_extension_start == std::string::npos) {
402 return std::string();
404 return _filename.substr(_extension_start);
415 _flags = (_flags & ~F_text) | F_binary;
425 _flags = (_flags & ~F_binary) | F_text;
436 return ((_flags & F_binary) != 0);
446 return ((_flags & (F_binary | F_text)) != 0);
457 return ((_flags & F_text) != 0);
469 _flags = (_flags & ~F_type) | type;
486 return (Type)(_flags & (int)F_type);
508 _flags &= ~F_pattern;
520 return (_flags & F_pattern) != 0;
532 return (_hash_start != _hash_end);
541 return _filename.substr(_hash_start);
550 return _filename.empty() || _filename[0] !=
'/';
564 (_filename.size() > 2 && _filename[0] ==
'.' && _filename[1] ==
'/') ||
565 (!_filename.empty() && _filename[0] ==
'/');
571 INLINE
bool Filename::
572 operator == (
const std::string &other)
const {
573 return (*(std::string *)
this) == other;
579 INLINE
bool Filename::
580 operator != (
const std::string &other)
const {
581 return (*(std::string *)
this) != other;
587 INLINE
bool Filename::
588 operator < (
const std::string &other)
const {
589 return (*(std::string *)
this) < other;
595 INLINE
int Filename::
596 compare_to(
const Filename &other)
const {
597 return strcmp(_filename.c_str(), other._filename.c_str());
612 return !_filename.empty();
618 INLINE
void Filename::
619 output(std::ostream &out)
const {
631 _filesystem_encoding = encoding;
640 return _filesystem_encoding;
The name of a file, such as a texture file or an Egg file.
bool __nonzero__() const
Returns true if the Filename is valid (not empty), or false if it is an empty string.
void set_type(Type type)
Sets the type of the file represented by the filename.
Filename()
Creates an empty Filename.
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
std::string get_basename() const
Returns the basename part of the filename.
bool has_hash() const
Returns true if the filename is indicated to be a filename pattern (that is, set_pattern(true) was ca...
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
Filename operator/(const Filename &other) const
Returns a new Filename that is composed of the other filename added to the end of this filename,...
bool is_text() const
Returns true if the Filename has been indicated to represent a text file via a previous call to set_t...
bool is_binary() const
Returns true if the Filename has been indicated to represent a binary file via a previous call to set...
void set_binary()
Indicates that the filename represents a binary file.
bool is_binary_or_text() const
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified a...
static TextEncoder::Encoding get_filesystem_encoding()
Specifies the default encoding to be used for all subsequent Filenames objects.
void operator+=(const std::string &other)
Appends the other filename onto the end of this one.
bool get_pattern() const
Returns the flag indicating whether this is a filename pattern.
static void set_filesystem_encoding(TextEncoder::Encoding encoding)
Specifies the default encoding to be used for all subsequent Filenames.
void set_text()
Indicates that the filename represents a text file.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
std::string get_hash_to_end() const
Returns the part of the filename beginning at the hash sequence (if any), and continuing to the end o...
std::wstring get_fullpath_w() const
Returns the entire filename as a wide-character string.
std::string get_extension() const
Returns the file extension.
bool is_local() const
Returns true if the filename is local, e.g.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
std::string get_dirname() const
Returns the directory part of the filename.
Type get_type() const
Returns the type of the file represented by the filename, as previously set by set_type().
static Filename pattern_filename(const std::string &filename)
Constructs a filename that represents a sequence of numbered files.
void set_pattern(bool pattern)
Sets the flag indicating whether this is a filename pattern.
Filename operator+(const std::string &other) const
Returns a new Filename representing the concatenation of the two filenames.
This class can be used to convert text between multiple representations, e.g.
set_text
Changes the text that is stored in the encoder.
void set_encoding(Encoding encoding)
Specifies how the string set via set_text() is to be interpreted.
get_text
Returns the current text, as encoded via the current encoding system.
const std::wstring & get_wtext() const
Returns the text associated with the TextEncoder, as a wide-character string.
void set_wtext(const std::wstring &wtext)
Changes the text that is stored in the encoder.