Buffet: Move buffet over to platform2 from src/platform/buffet.
This change also open-sources buffet. The only change in this CL
is the removal of the Makefile and addition of the buffet.gyp file.
BUG=chromium:355180
TEST=USE=buffet emerge-gizmo platform2
Change-Id: Ibf8d3ac3f38313f82a9c07d79932b6f30130f9c5
diff --git a/buffet/mime_utils.h b/buffet/mime_utils.h
new file mode 100644
index 0000000..e1dc7da
--- /dev/null
+++ b/buffet/mime_utils.h
@@ -0,0 +1,102 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_MIME_UTILS_H_
+#define BUFFET_MIME_UTILS_H_
+
+#include <string>
+#include <vector>
+
+namespace chromeos {
+
+namespace mime {
+
+namespace types {
+ // Main MIME type categories
+ extern const char kApplication[]; // application
+ extern const char kAudio[]; // audio
+ extern const char kImage[]; // image
+ extern const char kMessage[]; // message
+ extern const char kMultipart[]; // multipart
+ extern const char kText[]; // test
+ extern const char kVideo[]; // video
+}
+
+namespace parameters {
+ // Common MIME parameters
+ extern const char kCharset[]; // charset=...
+}
+
+namespace image {
+ // Common image MIME types
+ extern const char kJpeg[]; // image/jpeg
+ extern const char kPng[]; // image/png
+ extern const char kBmp[]; // image/bmp
+ extern const char kTiff[]; // image/tiff
+ extern const char kGif[]; // image/gif
+}
+
+namespace text {
+ // Common text MIME types
+ extern const char kPlain[]; // text/plain
+ extern const char kHtml[]; // text/html
+ extern const char kXml[]; // text/xml
+}
+
+namespace application {
+ // Common application MIME types
+ extern const char kOctet_stream[]; // application/octet-stream
+ extern const char kJson[]; // application/json
+ extern const char kWwwFormUrlEncoded[]; // application/x-www-form-urlencoded
+}
+
+typedef std::vector<std::pair<std::string, std::string>> Parameters;
+
+// Combine a MIME type, subtype and parameters into a MIME string.
+// e.g. Combine("text", "plain", {{"charset", "utf-8"}}) will give:
+// "text/plain; charset=utf-8"
+std::string Combine(std::string const& type, std::string const& subtype,
+ Parameters const& parameters = Parameters());
+
+// Splits a MIME string into type and subtype.
+// "text/plain;charset=utf-8" => ("text", "plain")
+bool Split(std::string const& mime_string,
+ std::string* type, std::string* subtype);
+
+// Splits a MIME string into type, subtype, and parameters.
+// "text/plain;charset=utf-8" => ("text", "plain", {{"charset","utf-8"}})
+bool Split(std::string const& mime_string,
+ std::string* type, std::string* subtype, Parameters* parameters);
+
+// Returns the MIME type from MIME string.
+// "text/plain;charset=utf-8" => "text"
+std::string GetType(std::string const& mime_string);
+
+// Returns the MIME sub-type from MIME string.
+// "text/plain;charset=utf-8" => "plain"
+std::string GetSubtype(std::string const& mime_string);
+
+// Returns the MIME parameters from MIME string.
+// "text/plain;charset=utf-8" => {{"charset","utf-8"}}
+Parameters GetParameters(std::string const& mime_string);
+
+// Removes parameters from a MIME string
+// "text/plain;charset=utf-8" => "text/plain"
+std::string RemoveParameters(std::string const& mime_string);
+
+// Appends a parameter to a MIME string.
+// "text/plain" => "text/plain; charset=utf-8"
+std::string AppendParameter(std::string const& mime_string,
+ std::string const& paramName,
+ std::string const& paramValue);
+
+// Returns the value of a parameter on a MIME string (empty string if missing).
+// ("text/plain;charset=utf-8","charset") => "utf-8"
+std::string GetParameterValue(std::string const& mime_string,
+ std::string const& paramName);
+
+} // namespace mime
+} // namespace chromeos
+
+#endif // BUFFET_MIME_UTILS_H_