Skip to content

Commit

Permalink
XMLUtils: re-add the possibility to use a string seperator instead of…
Browse files Browse the repository at this point in the history
… multiple tags to GetStringArray
  • Loading branch information
Montellese committed Apr 20, 2012
1 parent f57f8ec commit 2e616ab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
10 changes: 5 additions & 5 deletions xbmc/music/Album.cpp
Expand Up @@ -41,11 +41,11 @@ bool CAlbum::Load(const TiXmlElement *album, bool append, bool prioritise)

XMLUtils::GetString(album,"title",strAlbum);

XMLUtils::GetStringArray(album, "artist", artist, prioritise);
XMLUtils::GetStringArray(album, "genre", genre, prioritise);
XMLUtils::GetStringArray(album, "style", styles, prioritise);
XMLUtils::GetStringArray(album, "mood", moods, prioritise);
XMLUtils::GetStringArray(album, "theme", themes, prioritise);
XMLUtils::GetStringArray(album, "artist", artist, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(album, "genre", genre, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(album, "style", styles, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(album, "mood", moods, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(album, "theme", themes, prioritise, g_advancedSettings.m_musicItemSeparator);

XMLUtils::GetString(album,"review",strReview);
XMLUtils::GetString(album,"releasedate",m_strDateOfRelease);
Expand Down
10 changes: 5 additions & 5 deletions xbmc/music/Artist.cpp
Expand Up @@ -32,11 +32,11 @@ bool CArtist::Load(const TiXmlElement *artist, bool append, bool prioritise)
Reset();

XMLUtils::GetString(artist,"name",strArtist);
XMLUtils::GetStringArray(artist, "genre", genre, prioritise);
XMLUtils::GetStringArray(artist, "style", styles, prioritise);
XMLUtils::GetStringArray(artist, "mood", moods, prioritise);
XMLUtils::GetStringArray(artist, "yearsactive", yearsActive, prioritise);
XMLUtils::GetStringArray(artist, "instruments", instruments, prioritise);
XMLUtils::GetStringArray(artist, "genre", genre, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(artist, "style", styles, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(artist, "mood", moods, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(artist, "yearsactive", yearsActive, prioritise, g_advancedSettings.m_musicItemSeparator);
XMLUtils::GetStringArray(artist, "instruments", instruments, prioritise, g_advancedSettings.m_musicItemSeparator);

XMLUtils::GetString(artist, "born", strBorn);
XMLUtils::GetString(artist, "formed", strFormed);
Expand Down
21 changes: 18 additions & 3 deletions xbmc/utils/XMLUtils.cpp
Expand Up @@ -162,9 +162,9 @@ bool XMLUtils::GetAdditiveString(const TiXmlNode* pRootNode, const char* strTag,
Parses the XML for multiple tags of the given name.
Does not clear the array to support chaining.
*/
bool XMLUtils::GetStringArray(const TiXmlNode* pRootNode, const char* strTag, std::vector<std::string>& arrayValue, bool clear /* = false */)
bool XMLUtils::GetStringArray(const TiXmlNode* pRootNode, const char* strTag, std::vector<std::string>& arrayValue, bool clear /* = false */, const std::string separator /* = "" */)
{
CStdString strTemp;
std::string strTemp;
const TiXmlElement* node = pRootNode->FirstChildElement(strTag);
bool bResult=false;
if (node && node->FirstChild() && clear)
Expand All @@ -174,7 +174,22 @@ bool XMLUtils::GetStringArray(const TiXmlNode* pRootNode, const char* strTag, st
if (node->FirstChild())
{
bResult = true;
arrayValue.push_back(node->FirstChild()->Value());
strTemp = node->FirstChild()->ValueStr();

const char* clearAttr = node->Attribute("clear");
if (clearAttr && strcasecmp(clearAttr, "true") == 0)
arrayValue.clear();

if (strTemp.empty())
continue;

if (separator.empty())
arrayValue.push_back(strTemp);
else
{
std::vector<std::string> tempArray = StringUtils::Split(strTemp, separator);
arrayValue.insert(arrayValue.end(), tempArray.begin(), tempArray.end());
}
}
node = node->NextSiblingElement(strTag);
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/utils/XMLUtils.h
Expand Up @@ -55,7 +55,7 @@ class XMLUtils
\param clear if true, clears the string prior to adding tags, if tags are available. Defaults to false.
*/
static bool GetAdditiveString(const TiXmlNode* rootNode, const char* tag, const CStdString& separator, CStdString& value, bool clear = false);
static bool GetStringArray(const TiXmlNode* rootNode, const char* tag, std::vector<std::string>& arrayValue, bool clear = false);
static bool GetStringArray(const TiXmlNode* rootNode, const char* tag, std::vector<std::string>& arrayValue, bool clear = false, const std::string separator = "");
static bool GetEncoding(const TiXmlDocument* pDoc, CStdString& strEncoding);
static bool GetPath(const TiXmlNode* pRootNode, const char* strTag, CStdString& strStringValue);
static bool GetFloat(const TiXmlNode* pRootNode, const char* strTag, float& value, const float min, const float max);
Expand Down
14 changes: 7 additions & 7 deletions xbmc/video/VideoInfoTag.cpp
Expand Up @@ -559,11 +559,11 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prioritise)
m_strPictureURL.m_xml = xmlAdd;
}

XMLUtils::GetStringArray(movie, "genre", m_genre, prioritise);
XMLUtils::GetStringArray(movie, "country", m_country, prioritise);
XMLUtils::GetStringArray(movie, "credits", m_writingCredits, prioritise);
XMLUtils::GetStringArray(movie, "director", m_director, prioritise);
XMLUtils::GetStringArray(movie, "showlink", m_showLink, prioritise);
XMLUtils::GetStringArray(movie, "genre", m_genre, prioritise, g_advancedSettings.m_videoItemSeparator);
XMLUtils::GetStringArray(movie, "country", m_country, prioritise, g_advancedSettings.m_videoItemSeparator);
XMLUtils::GetStringArray(movie, "credits", m_writingCredits, prioritise, g_advancedSettings.m_videoItemSeparator);
XMLUtils::GetStringArray(movie, "director", m_director, prioritise, g_advancedSettings.m_videoItemSeparator);
XMLUtils::GetStringArray(movie, "showlink", m_showLink, prioritise, g_advancedSettings.m_videoItemSeparator);

// cast
const TiXmlElement* node = movie->FirstChildElement("actor");
Expand Down Expand Up @@ -593,8 +593,8 @@ void CVideoInfoTag::ParseNative(const TiXmlElement* movie, bool prioritise)
node = node->NextSiblingElement("actor");
}

XMLUtils::GetStringArray(movie, "set", m_set, prioritise);
XMLUtils::GetStringArray(movie, "studio", m_studio, prioritise);
XMLUtils::GetStringArray(movie, "set", m_set, prioritise, g_advancedSettings.m_videoItemSeparator);
XMLUtils::GetStringArray(movie, "studio", m_studio, prioritise, g_advancedSettings.m_videoItemSeparator);
// artists
node = movie->FirstChildElement("artist");
if (node && node->FirstChild() && prioritise)
Expand Down

0 comments on commit 2e616ab

Please sign in to comment.