Skip to content

Commit

Permalink
HttpHeader: add 'GetCharset' function
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlson2k committed Oct 27, 2013
1 parent 389ce4d commit 4d63ef9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions xbmc/utils/HttpHeader.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions xbmc/utils/HttpHeader.h
Expand Up @@ -43,6 +43,7 @@ class CHttpHeader
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
Expand Down

0 comments on commit 4d63ef9

Please sign in to comment.