Simple function to test if a filename has a given extension, disregarding case
| 106 | |
| 107 | // Simple function to test if a filename has a given extension, disregarding case |
| 108 | ILboolean iCheckExtension(ILconst_string Arg, ILconst_string Ext) |
| 109 | { |
| 110 | ILboolean PeriodFound = IL_FALSE; |
| 111 | ILint i, Len; |
| 112 | ILstring Argu = (ILstring)Arg; |
| 113 | |
| 114 | if (Arg == NULL || Ext == NULL || !ilStrLen(Arg) || !ilStrLen(Ext)) // if not a good filename/extension, exit early |
| 115 | return IL_FALSE; |
| 116 | |
| 117 | Len = ilStrLen(Arg); |
| 118 | Argu += Len; // start at the end |
| 119 | |
| 120 | for (i = Len; i >= 0; i--) { |
| 121 | if (*Argu == '.') { // try to find a period |
| 122 | PeriodFound = IL_TRUE; |
| 123 | break; |
| 124 | } |
| 125 | Argu--; |
| 126 | } |
| 127 | |
| 128 | if (!PeriodFound) // if no period, no extension |
| 129 | return IL_FALSE; |
| 130 | |
| 131 | if (!iStrCmp(Argu+1, Ext)) // extension and ext match? |
| 132 | return IL_TRUE; |
| 133 | |
| 134 | return IL_FALSE; // if all else fails, return IL_FALSE |
| 135 | } |
| 136 | |
| 137 | |
| 138 | ILstring iGetExtension(ILconst_string FileName) |
no test coverage detected