Adapted from code generated with Google Gemini 2.0 Flash
| 229 | |
| 230 | // Adapted from code generated with Google Gemini 2.0 Flash |
| 231 | std::string ExtractFileExtensionFromUrl(_In_ const std::string& url) { |
| 232 | // Find the last '/' before the '?' or end of string |
| 233 | size_t lastSlashPos{ url.find_last_of('/') }; |
| 234 | size_t queryPos{}; |
| 235 | if (lastSlashPos == std::string::npos) |
| 236 | queryPos = url.find('?'); // URLs without slashes |
| 237 | else |
| 238 | queryPos = url.find('?', lastSlashPos + 1); |
| 239 | std::string filename; |
| 240 | if (queryPos == std::string::npos) |
| 241 | filename = url.substr(lastSlashPos + 1); // URLs without query strings |
| 242 | else |
| 243 | filename = url.substr(lastSlashPos + 1, queryPos - lastSlashPos - 1); |
| 244 | |
| 245 | // Extract the extension using std::filesystem |
| 246 | std::filesystem::path filePath{ filename }; |
| 247 | return filePath.extension().string(); |
| 248 | } |
| 249 | |
| 250 | // Function to check for supported file extensions |
| 251 | bool IsSupportedFileExtension(_In_ const std::string& extension) { |