Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

introduce $ESCINFO[] - identical to $INFO[] except the result is cons…

…tructed by escaping any quotes and then wrapping the result in quotes, allowing it to be fed through as a parameter to a builtin function
  • Loading branch information...
commit 7d77070d7e14aa7d1a225e705c9c28f8755a48f7 1 parent baa24bb
Jonathan Marshall authored
Showing with 37 additions and 15 deletions.
  1. +33 −14 xbmc/guilib/GUIInfoTypes.cpp
  2. +4 −1 xbmc/guilib/GUIInfoTypes.h
View
47 xbmc/guilib/GUIInfoTypes.cpp
@@ -139,11 +139,7 @@ CStdString CGUIInfoLabel::GetLabel(int contextWindow, bool preferImage) const
if (infoLabel.IsEmpty())
infoLabel = g_infoManager.GetLabel(portion.m_info, contextWindow);
if (!infoLabel.IsEmpty())
- {
- label += portion.m_prefix;
- label += infoLabel;
- label += portion.m_postfix;
- }
+ label += portion.GetLabel(infoLabel);
}
else
{ // no info, so just append the prefix
@@ -170,11 +166,7 @@ CStdString CGUIInfoLabel::GetItemLabel(const CGUIListItem *item, bool preferImag
else
infoLabel = g_infoManager.GetItemLabel((const CFileItem *)item, portion.m_info);
if (!infoLabel.IsEmpty())
- {
- label += portion.m_prefix;
- label += infoLabel;
- label += portion.m_postfix;
- }
+ label += portion.GetLabel(infoLabel);
}
else
{ // no info, so just append the prefix
@@ -261,6 +253,13 @@ void CGUIInfoLabel::Parse(const CStdString &label)
work = ReplaceAddonStrings(work);
// Step 3: Find all $INFO[info,prefix,postfix] blocks
int pos1 = work.Find("$INFO[");
+ int pos2 = work.Find("$ESCINFO[");
+ bool escaped = false;
+ if (pos2 >= 0 && (pos1 < 0 || pos2 < pos1))
+ {
+ escaped = true;
+ pos1 = pos2;
+ }
while (pos1 >= 0)
{
// output the first block (contents before first $INFO)
@@ -268,11 +267,12 @@ void CGUIInfoLabel::Parse(const CStdString &label)
m_info.push_back(CInfoPortion(0, work.Left(pos1), ""));
// ok, now decipher the $INFO block
- int pos2 = StringUtils::FindEndBracket(work, '[', ']', pos1 + 6);
+ int len = escaped ? 9 : 6;
+ pos2 = StringUtils::FindEndBracket(work, '[', ']', pos1 + len);
if (pos2 > pos1)
{
// decipher the block
- CStdString block = work.Mid(pos1 + 6, pos2 - pos1 - 6);
+ CStdString block = work.Mid(pos1 + len, pos2 - pos1 - len);
CStdStringArray params;
StringUtils::SplitString(block, ",", params);
int info = g_infoManager.TranslateString(params[0]);
@@ -281,7 +281,7 @@ void CGUIInfoLabel::Parse(const CStdString &label)
prefix = params[1];
if (params.size() > 2)
postfix = params[2];
- m_info.push_back(CInfoPortion(info, prefix, postfix));
+ m_info.push_back(CInfoPortion(info, prefix, postfix, escaped));
// and delete it from our work string
work = work.Mid(pos2 + 1);
}
@@ -291,17 +291,25 @@ void CGUIInfoLabel::Parse(const CStdString &label)
return;
}
pos1 = work.Find("$INFO[");
+ pos2 = work.Find("$ESCINFO[");
+ escaped = false;
+ if (pos2 >= 0 && (pos1 < 0 || pos2 < pos1))
+ {
+ escaped = true;
+ pos1 = pos2;
+ }
}
// add any last block
if (!work.IsEmpty())
m_info.push_back(CInfoPortion(0, work, ""));
}
-CGUIInfoLabel::CInfoPortion::CInfoPortion(int info, const CStdString &prefix, const CStdString &postfix)
+CGUIInfoLabel::CInfoPortion::CInfoPortion(int info, const CStdString &prefix, const CStdString &postfix, bool escaped)
{
m_info = info;
m_prefix = prefix;
m_postfix = postfix;
+ m_escaped = escaped;
// filter our prefix and postfix for comma's
m_prefix.Replace("$COMMA", ",");
m_postfix.Replace("$COMMA", ",");
@@ -309,6 +317,17 @@ CGUIInfoLabel::CInfoPortion::CInfoPortion(int info, const CStdString &prefix, co
m_postfix.Replace("$LBRACKET", "["); m_postfix.Replace("$RBRACKET", "]");
}
+CStdString CGUIInfoLabel::CInfoPortion::GetLabel(const CStdString &info) const
+{
+ CStdString label = m_prefix + info + m_postfix;
+ if (m_escaped) // escape all quotes, then quote
+ {
+ label.Replace("\"", "\\\"");
+ return "\"" + label + "\"";
+ }
+ return label;
+}
+
CStdString CGUIInfoLabel::GetLabel(const CStdString &label, int contextWindow, bool preferImage)
{ // translate the label
CGUIInfoLabel info(label, "");
View
5 xbmc/guilib/GUIInfoTypes.h
@@ -102,10 +102,13 @@ class CGUIInfoLabel
class CInfoPortion
{
public:
- CInfoPortion(int info, const CStdString &prefix, const CStdString &postfix);
+ CInfoPortion(int info, const CStdString &prefix, const CStdString &postfix, bool escaped = false);
+ CStdString GetLabel(const CStdString &info) const;
int m_info;
CStdString m_prefix;
CStdString m_postfix;
+ private:
+ bool m_escaped;
};
CStdString m_fallback;
Please sign in to comment.
Something went wrong with that request. Please try again.