18Filename(
const std::string &filename) {
27Filename(
const std::wstring &filename) {
36Filename(
const char *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),
61Filename(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),
99text_filename(
const Filename &filename) {
109text_filename(
const std::string &filename) {
119binary_filename(
const Filename &filename) {
129binary_filename(
const std::string &filename) {
139dso_filename(
const std::string &filename) {
141 result.set_type(T_dso);
149executable_filename(
const std::string &filename) {
151 result.set_type(T_executable);
160pattern_filename(
const std::string &filename) {
170operator = (
const std::string &filename) {
171 _filename = filename;
183operator = (
const std::wstring &filename) {
187 return operator = (encoder.
get_text());
194operator = (
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;
219operator = (std::string &&filename)
noexcept {
220 _filename = std::move(filename);
232operator = (
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;
248operator
const std::string & ()
const {
255INLINE
const char *Filename::
257 return _filename.c_str();
263INLINE
bool Filename::
265 return _filename.empty();
271INLINE
size_t Filename::
273 return _filename.length();
279INLINE
char Filename::
280operator [] (
size_t n)
const {
281 assert(n < _filename.length());
288INLINE std::string Filename::
289substr(
size_t begin)
const {
290 return _filename.substr(begin);
296INLINE std::string Filename::
297substr(
size_t begin,
size_t end)
const {
298 return _filename.substr(begin, end);
306INLINE
void Filename::
307operator += (
const std::string &other) {
318operator + (
const std::string &other)
const {
329operator / (
const Filename &other)
const {
337INLINE std::string Filename::
338get_fullpath()
const {
345INLINE std::wstring Filename::
346get_fullpath_w()
const {
357INLINE std::string Filename::
359 return _filename.substr(0, _dirname_end);
366INLINE std::string Filename::
367get_basename()
const {
368 return _filename.substr(_basename_start);
376INLINE std::string Filename::
377get_fullpath_wo_extension()
const {
378 return _filename.substr(0, _basename_end);
385INLINE std::string Filename::
386get_basename_wo_extension()
const {
387 if (_basename_end == std::string::npos) {
388 return _filename.substr(_basename_start);
390 return _filename.substr(_basename_start, _basename_end - _basename_start);
399INLINE std::string Filename::
400get_extension()
const {
401 if (_extension_start == std::string::npos) {
402 return std::string();
404 return _filename.substr(_extension_start);
413INLINE
void Filename::
415 _flags = (_flags & ~F_text) | F_binary;
423INLINE
void Filename::
425 _flags = (_flags & ~F_binary) | F_text;
434INLINE
bool Filename::
436 return ((_flags & F_binary) != 0);
444INLINE
bool Filename::
445is_binary_or_text()
const {
446 return ((_flags & (F_binary | F_text)) != 0);
455INLINE
bool Filename::
457 return ((_flags & F_text) != 0);
467INLINE
void Filename::
468set_type(Filename::Type type) {
469 _flags = (_flags & ~F_type) | type;
484INLINE Filename::Type Filename::
486 return (Type)(_flags & (int)F_type);
502INLINE
void Filename::
503set_pattern(
bool pattern) {
508 _flags &= ~F_pattern;
518INLINE
bool Filename::
520 return (_flags & F_pattern) != 0;
530INLINE
bool Filename::
532 return (_hash_start != _hash_end);
539INLINE std::string Filename::
540get_hash_to_end()
const {
541 return _filename.substr(_hash_start);
548INLINE
bool Filename::
550 return _filename.empty() || _filename[0] !=
'/';
561INLINE
bool Filename::
562is_fully_qualified()
const {
564 (_filename.size() > 2 && _filename[0] ==
'.' && _filename[1] ==
'/') ||
565 (!_filename.empty() && _filename[0] ==
'/');
571INLINE
bool Filename::
572operator == (
const std::string &other)
const {
573 return (*(std::string *)
this) == other;
579INLINE
bool Filename::
580operator != (
const std::string &other)
const {
581 return (*(std::string *)
this) != other;
587INLINE
bool Filename::
588operator < (
const std::string &other)
const {
589 return (*(std::string *)
this) < other;
596compare_to(
const Filename &other)
const {
597 return strcmp(_filename.c_str(), other._filename.c_str());
610INLINE
bool Filename::
612 return !_filename.empty();
618INLINE
void Filename::
619output(std::ostream &out)
const {
629INLINE
void Filename::
630set_filesystem_encoding(TextEncoder::Encoding encoding) {
631 _filesystem_encoding = encoding;
638INLINE TextEncoder::Encoding Filename::
639get_filesystem_encoding() {
640 return _filesystem_encoding;
The name of a file, such as a texture file or an Egg file.
Filename()
Creates an empty Filename.
void set_binary()
Indicates that the filename represents a binary file.
static TextEncoder::Encoding get_filesystem_encoding()
Specifies the default encoding to be used for all subsequent Filenames objects.
bool get_pattern() const
Returns the flag indicating whether this is a filename pattern.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
void set_pattern(bool pattern)
Sets the flag indicating whether this is a filename pattern.
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.