HttpHeader: add 'GetCharset' function
authorKarlson2k <k2k@narod.ru>
Sun, 20 Oct 2013 11:27:23 +0000 (15:27 +0400)
committerKarlson2k <k2k@narod.ru>
Sun, 27 Oct 2013 00:27:59 +0000 (04:27 +0400)
xbmc/utils/HttpHeader.cpp
xbmc/utils/HttpHeader.h

index 13780d3..c9dade3 100644 (file)
@@ -146,6 +146,28 @@ std::string CHttpHeader::GetMimeType(void) const
   return strValue.substr(0, strValue.find(';'));
 }
 
+std::string CHttpHeader::GetCharset(void) const
+{
+  std::string strValue(GetValueRaw("content-type"));
+  if (strValue.empty())
+    return strValue;
+
+  const size_t semicolonPos = strValue.find(';');
+  if (semicolonPos == std::string::npos)
+    return "";
+
+  StringUtils::ToUpper(strValue);
+  size_t posCharset;
+  if ((posCharset = strValue.find("; CHARSET=", semicolonPos)) != std::string::npos)
+    posCharset += 10;
+  else if ((posCharset = strValue.find(";CHARSET=", semicolonPos)) != std::string::npos)
+    posCharset += 9;
+  else
+    return "";
+
+  return strValue.substr(posCharset, strValue.find(';', posCharset) - posCharset);
+}
+
 void CHttpHeader::Clear()
 {
   m_params.clear();
index 75d5c30..078eef2 100644 (file)
@@ -43,6 +43,7 @@ public:
   std::string GetHeader(void) const;
 
   std::string GetMimeType(void) const;
+  std::string GetCharset(void) const;
   std::string GetProtoLine() { return m_protoLine; }
 
   inline bool IsHeaderDone(void) const