Rewrite filename_ext.cxx for the driver model.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11556 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-08 16:00:26 +00:00
parent 90682dbd48
commit 1ba6928313
4 changed files with 20 additions and 14 deletions

View File

@ -110,6 +110,8 @@ public:
virtual int filename_isdir(const char* n);
// the default implementation of filename_isdir_quick() is in src/filename_isdir.cxx and may be enough
virtual int filename_isdir_quick(const char* n);
// the default implementation of filename_iext() is in src/filename_ext.cxx and may be enough
virtual const char *filename_ext(const char *buf);
};
#endif // FL_SYSTEM_DRIVER_H

View File

@ -74,6 +74,7 @@ public:
virtual int filename_absolute(char *to, int tolen, const char *from);
virtual int filename_isdir(const char* n);
virtual int filename_isdir_quick(const char* n);
virtual const char *filename_ext(const char *buf);
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H

View File

@ -648,6 +648,16 @@ int Fl_WinAPI_System_Driver::filename_isdir_quick(const char* n)
return filename_isdir(n);
}
const char *Fl_WinAPI_System_Driver::filename_ext(const char *buf) {
const char *q = 0;
const char *p = buf;
for (p = buf; *p; p++) {
if (isdirsep(*p) ) q = 0;
else if (*p == '.') q = p;
}
return q ? q : p;
}
//
// End of "$Id$".
//

View File

@ -16,18 +16,10 @@
// http://www.fltk.org/str.php
//
// returns pointer to the last '.' or to the null if none:
#include <FL/Fl_System_Driver.H>
#include <FL/Fl.H>
#include <FL/filename.H>
#ifdef WIN32
#elif defined(__APPLE__) // PORTME: Fl_System_Driver - filename stuff
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: implement directory and filename handling for your platform if needed"
#else // X11
#endif
/** Gets the extensions of a filename.
/** Gets the extension of a filename.
\code
#include <FL/filename.H>
[..]
@ -39,13 +31,14 @@
\return a pointer to the extension (including '.') if any or NULL otherwise
*/
const char *fl_filename_ext(const char *buf) {
return Fl::system_driver()->filename_ext(buf);
}
const char *Fl_System_Driver::filename_ext(const char *buf) {
const char *q = 0;
const char *p = buf;
for (p=buf; *p; p++) {
if (*p == '/') q = 0;
#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
else if (*p == '\\') q = 0;
#endif
else if (*p == '.') q = p;
}
return q ? q : p;