| // Copyright 2022 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "third_party/xdg_shared_mime_info/mime_cache.h" |
| |
| #include "base/containers/fixed_flat_map.h" |
| #include "base/strings/string_piece.h" |
| #include "base/strings/string_util.h" |
| |
| // File generated by //third_party/xdg_mime_shared_info/generate.py. |
| namespace xdg_shared_mime_info { |
| |
| |
| bool GetMimeCacheTypeFromExtension(const std::string& ext, |
| std::string* result) { |
| static constexpr auto kMap = base::MakeFixedFlatMap<base::StringPiece, |
| base::StringPiece>({ |
| {% for mime_type in mime_types %} |
| {"{{mime_type.ext}}", "{{mime_type.mime}}"}, |
| {% endfor %} |
| }); |
| |
| // If first match fails, try matching lower case. |
| auto it = kMap.find(ext); |
| if (it != kMap.end()) { |
| *result = std::string(it->second); |
| return true; |
| } |
| it = kMap.find(base::ToLowerASCII(ext)); |
| if (it != kMap.end()) { |
| *result = std::string(it->second); |
| return true; |
| } |
| return false; |
| } |
| |
| } // namespace xdg_shared_mime_info |