X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FWebCore%2Fplatform%2FContentType.cpp;h=f0d2c10b88f2087ebdabf157bc81b65c58081389;hp=88a714b5f392ce1979edbef44e259cdba22c1fb9;hb=e52289da0b9a4b2b4ad35d388bf495d5420b7407;hpb=97bf5ae3a256e0d248e3ddf898080ccd549faf76 diff --git a/Source/WebCore/platform/ContentType.cpp b/Source/WebCore/platform/ContentType.cpp index 88a714b..f0d2c10 100644 --- a/Source/WebCore/platform/ContentType.cpp +++ b/Source/WebCore/platform/ContentType.cpp @@ -27,14 +27,34 @@ #include "config.h" #include "ContentType.h" +#include "HTMLParserIdioms.h" +#include +#include namespace WebCore { +ContentType::ContentType(String&& contentType) + : m_type(WTFMove(contentType)) +{ +} + ContentType::ContentType(const String& contentType) : m_type(contentType) { } +const String& ContentType::codecsParameter() +{ + static NeverDestroyed codecs { "codecs"_s }; + return codecs; +} + +const String& ContentType::profilesParameter() +{ + static NeverDestroyed profiles { "profiles"_s }; + return profiles; +} + String ContentType::parameter(const String& parameterName) const { String parameterValue; @@ -43,7 +63,7 @@ String ContentType::parameter(const String& parameterName) const // a MIME type can have one or more "param=value" after a semi-colon, and separated from each other by semi-colons size_t semi = strippedType.find(';'); if (semi != notFound) { - size_t start = strippedType.find(parameterName, semi + 1, false); + size_t start = strippedType.findIgnoringASCIICase(parameterName, semi + 1); if (start != notFound) { start = strippedType.find('=', start + parameterName.length()); if (start != notFound) { @@ -64,7 +84,7 @@ String ContentType::parameter(const String& parameterName) const return parameterValue; } -String ContentType::type() const +String ContentType::containerType() const { String strippedType = m_type.stripWhiteSpace(); @@ -76,19 +96,39 @@ String ContentType::type() const return strippedType; } +static inline Vector splitParameters(StringView parametersView) +{ + Vector result; + for (auto view : parametersView.split(',')) + result.append(view.stripLeadingAndTrailingMatchedCharacters(isHTMLSpace).toString()); + return result; +} + Vector ContentType::codecs() const { - String codecsParameter = parameter(ASCIILiteral("codecs")); + return splitParameters(parameter(codecsParameter())); +} + +Vector ContentType::profiles() const +{ + return splitParameters(parameter(profilesParameter())); +} - if (codecsParameter.isEmpty()) - return Vector(); +String ContentType::toJSONString() const +{ + auto object = JSON::Object::create(); - Vector codecs; - codecsParameter.split(',', codecs); - for (size_t i = 0; i < codecs.size(); ++i) - codecs[i] = codecs[i].simplifyWhiteSpace(); + object->setString("containerType"_s, containerType()); - return codecs; + auto codecs = codecsParameter(); + if (!codecs.isEmpty()) + object->setString("codecs"_s, codecs); + + auto profiles = profilesParameter(); + if (!profiles.isEmpty()) + object->setString("profiles"_s, profiles); + + return object->toJSONString(); } } // namespace WebCore