1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/exo/mime_utils.h"
6 
7 namespace {
8 
9 constexpr char kCharset[] = ";charset=";
10 constexpr char kDefaultCharset[] = "US-ASCII";
11 constexpr char kEncodingUTF8Charset[] = "UTF-8";
12 
13 }  // namespace
14 
15 namespace exo {
16 
GetCharset(const std::string & mime_type)17 std::string GetCharset(const std::string& mime_type) {
18   // We special case UTF8_STRING to provide minimal handling of X11 apps.
19   if (mime_type == kEncodingUTF8Legacy)
20     return std::string(kEncodingUTF8Charset);
21 
22   auto pos = mime_type.find(kCharset);
23   if (pos == std::string::npos)
24     return std::string(kDefaultCharset);
25   return mime_type.substr(pos + sizeof(kCharset) - 1);
26 }
27 
28 }  // namespace exo
29