MCPcopy Create free account
hub / github.com/DentonW/DevIL / CheckExtension

Function CheckExtension

DevIL/examples/windows_example/BatchConv.cpp:134–161  ·  view source on GitHub ↗

Simple function to test if a filename has a given extension, disregarding case

Source from the content-addressed store, hash-verified

132
133// Simple function to test if a filename has a given extension, disregarding case
134bool CheckExtension(TCHAR *Arg, TCHAR *Ext)
135{
136 bool PeriodFound = false;
137 TCHAR *Argu = Arg; // pointer to arg so we don't destroy arg
138 unsigned int i;
139
140 if (Arg == NULL || Ext == NULL || !wcslen(Arg) || !wcslen(Ext)) // if not a good filename/extension, exit early
141 return false;
142
143 Argu += wcslen(Arg); // start at the end
144
145
146 for (i = (int)wcslen(Arg); i >= 0; i--) {
147 if (*Argu == '.') { // try to find a period
148 PeriodFound = true;
149 break;
150 }
151 Argu--;
152 }
153
154 if (!PeriodFound) // if no period, no extension
155 return false;
156
157 if (!_wcsicmp(Argu+1, Ext)) // extension and ext match?
158 return true;
159
160 return false; // if all else fails, return IL_FALSE
161}
162

Callers 4

GetPrevImageFunction · 0.85
GetNextImageFunction · 0.85
GetPrevImageFunction · 0.85
GetNextImageFunction · 0.85

Calls

no outgoing calls

Tested by 2

GetPrevImageFunction · 0.68
GetNextImageFunction · 0.68