REVIEWED: GetFileExtension() to include the dot #1523

This commit is contained in:
Ray 2021-03-02 01:07:08 +01:00
parent 2ff5fa73e9
commit bcc4418ff0
5 changed files with 19 additions and 19 deletions

View file

@ -2351,14 +2351,14 @@ bool DirectoryExists(const char *dirPath)
return result; return result;
} }
// Get pointer to extension for a filename string // Get pointer to extension for a filename string (includes the dot: .png)
const char *GetFileExtension(const char *fileName) const char *GetFileExtension(const char *fileName)
{ {
const char *dot = strrchr(fileName, '.'); const char *dot = strrchr(fileName, '.');
if (!dot || dot == fileName) return NULL; if (!dot || dot == fileName) return NULL;
return (dot + 1); return dot;
} }
// String pointer reverse break: returns right-most occurrence of charset in s // String pointer reverse break: returns right-most occurrence of charset in s

View file

@ -732,16 +732,16 @@ Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int
if (false) { } if (false) { }
#if defined(SUPPORT_FILEFORMAT_WAV) #if defined(SUPPORT_FILEFORMAT_WAV)
else if (TextIsEqual(fileExtLower, "wav")) wave = LoadWAV(fileData, dataSize); else if (TextIsEqual(fileExtLower, ".wav")) wave = LoadWAV(fileData, dataSize);
#endif #endif
#if defined(SUPPORT_FILEFORMAT_OGG) #if defined(SUPPORT_FILEFORMAT_OGG)
else if (TextIsEqual(fileExtLower, "ogg")) wave = LoadOGG(fileData, dataSize); else if (TextIsEqual(fileExtLower, ".ogg")) wave = LoadOGG(fileData, dataSize);
#endif #endif
#if defined(SUPPORT_FILEFORMAT_FLAC) #if defined(SUPPORT_FILEFORMAT_FLAC)
else if (TextIsEqual(fileExtLower, "flac")) wave = LoadFLAC(fileData, dataSize); else if (TextIsEqual(fileExtLower, ".flac")) wave = LoadFLAC(fileData, dataSize);
#endif #endif
#if defined(SUPPORT_FILEFORMAT_MP3) #if defined(SUPPORT_FILEFORMAT_MP3)
else if (TextIsEqual(fileExtLower, "mp3")) wave = LoadMP3(fileData, dataSize); else if (TextIsEqual(fileExtLower, ".mp3")) wave = LoadMP3(fileData, dataSize);
#endif #endif
else TRACELOG(LOG_WARNING, "WAVE: File format not supported"); else TRACELOG(LOG_WARNING, "WAVE: File format not supported");

View file

@ -998,7 +998,7 @@ RLAPI bool SaveFileText(const char *fileName, char *text); // Save text d
RLAPI bool FileExists(const char *fileName); // Check if file exists RLAPI bool FileExists(const char *fileName); // Check if file exists
RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists
RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension (including point: .png, .wav) RLAPI bool IsFileExtension(const char *fileName, const char *ext);// Check file extension (including point: .png, .wav)
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (including point: ".png") RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: ".png")
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string) RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string) RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string)

View file

@ -479,7 +479,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
return font; return font;
} }
// Load font from memory buffer, fileType refers to extension: i.e. "ttf" // Load font from memory buffer, fileType refers to extension: i.e. ".ttf"
Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount) Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount)
{ {
Font font = { 0 }; Font font = { 0 };
@ -488,8 +488,8 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
strcpy(fileExtLower, TextToLower(fileType)); strcpy(fileExtLower, TextToLower(fileType));
#if defined(SUPPORT_FILEFORMAT_TTF) #if defined(SUPPORT_FILEFORMAT_TTF)
if (TextIsEqual(fileExtLower, "ttf") || if (TextIsEqual(fileExtLower, ".ttf") ||
TextIsEqual(fileExtLower, "otf")) TextIsEqual(fileExtLower, ".otf"))
{ {
font.baseSize = fontSize; font.baseSize = fontSize;
font.charsCount = (charsCount > 0)? charsCount : 95; font.charsCount = (charsCount > 0)? charsCount : 95;

View file

@ -294,7 +294,7 @@ Image LoadImageAnim(const char *fileName, int *frames)
return image; return image;
} }
// Load image from memory buffer, fileType refers to extension: i.e. "png" // Load image from memory buffer, fileType refers to extension: i.e. ".png"
Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize) Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize)
{ {
Image image = { 0 }; Image image = { 0 };
@ -303,28 +303,28 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
strcpy(fileExtLower, TextToLower(fileType)); strcpy(fileExtLower, TextToLower(fileType));
#if defined(SUPPORT_FILEFORMAT_PNG) #if defined(SUPPORT_FILEFORMAT_PNG)
if ((TextIsEqual(fileExtLower, "png")) if ((TextIsEqual(fileExtLower, ".png"))
#else #else
if ((false) if ((false)
#endif #endif
#if defined(SUPPORT_FILEFORMAT_BMP) #if defined(SUPPORT_FILEFORMAT_BMP)
|| (TextIsEqual(fileExtLower, "bmp")) || (TextIsEqual(fileExtLower, ".bmp"))
#endif #endif
#if defined(SUPPORT_FILEFORMAT_TGA) #if defined(SUPPORT_FILEFORMAT_TGA)
|| (TextIsEqual(fileExtLower, "tga")) || (TextIsEqual(fileExtLower, ".tga"))
#endif #endif
#if defined(SUPPORT_FILEFORMAT_JPG) #if defined(SUPPORT_FILEFORMAT_JPG)
|| (TextIsEqual(fileExtLower, "jpg") || || (TextIsEqual(fileExtLower, ".jpg") ||
TextIsEqual(fileExtLower, "jpeg")) TextIsEqual(fileExtLower, ".jpeg"))
#endif #endif
#if defined(SUPPORT_FILEFORMAT_GIF) #if defined(SUPPORT_FILEFORMAT_GIF)
|| (TextIsEqual(fileExtLower, "gif")) || (TextIsEqual(fileExtLower, ".gif"))
#endif #endif
#if defined(SUPPORT_FILEFORMAT_PIC) #if defined(SUPPORT_FILEFORMAT_PIC)
|| (TextIsEqual(fileExtLower, "pic")) || (TextIsEqual(fileExtLower, ".pic"))
#endif #endif
#if defined(SUPPORT_FILEFORMAT_PSD) #if defined(SUPPORT_FILEFORMAT_PSD)
|| (TextIsEqual(fileExtLower, "psd")) || (TextIsEqual(fileExtLower, ".psd"))
#endif #endif
) )
{ {