aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmarshallnz <jcmarsha@gmail.com>2011-05-30 16:00:48 -0700
committerjmarshallnz <jcmarsha@gmail.com>2011-05-30 16:00:48 -0700
commit6fa3af9455a5ee9dd1e71ce98f6166f73c8874f5 (patch)
tree3687cfd616f661dacdf8164f31ff3fa51a99e5d5
parent8c076b3b0310b1421bf4602135ed698636cff62c (diff)
parent7d77070d7e14aa7d1a225e705c9c28f8755a48f7 (diff)
Merge pull request #124 from jmarshallnz/escaped_info
Escaped info support to builtin parameter parsing
-rw-r--r--xbmc/Util.cpp11
-rw-r--r--xbmc/guilib/GUIInfoTypes.cpp47
-rw-r--r--xbmc/guilib/GUIInfoTypes.h5
3 files changed, 46 insertions, 17 deletions
diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp
index f486aae142..f94faed3d4 100644
--- a/xbmc/Util.cpp
+++ b/xbmc/Util.cpp
@@ -1304,6 +1304,9 @@ bool CUtil::TestSplitExec()
CUtil::SplitExecFunction("SetProperty(Foo,\"\")", function, params);
if (function != "SetProperty" || params.size() != 2 || params[0] != "Foo" || params[1] != "")
return false;
+ CUtil::SplitExecFunction("SetProperty(foo,ba(\"ba black )\",sheep))", function, params);
+ if (function != "SetProperty" || params.size() != 2 || params[0] != "foo" || params[1] != "ba(\"ba black )\",sheep)")
+ return false;
return true;
}
#endif
@@ -1344,7 +1347,6 @@ void CUtil::SplitExecFunction(const CStdString &execString, CStdString &function
if (ch == '\"' && !escaped)
{ // finished a quote - no need to add the end quote to our string
inQuotes = false;
- continue;
}
}
else
@@ -1352,7 +1354,6 @@ void CUtil::SplitExecFunction(const CStdString &execString, CStdString &function
if (ch == '\"' && !escaped)
{ // start of quote - no need to add the quote to our string
inQuotes = true;
- continue;
}
if (inFunction && ch == ')')
{ // end of a function
@@ -1366,6 +1367,9 @@ void CUtil::SplitExecFunction(const CStdString &execString, CStdString &function
{ // not in a function, so a comma signfies the end of this parameter
if (whiteSpacePos)
parameter = parameter.Left(whiteSpacePos);
+ // trim off start and end quotes
+ if (parameter.GetLength() > 1 && parameter[0] == '\"' && parameter[parameter.GetLength() - 1] == '\"')
+ parameter = parameter.Mid(1,parameter.GetLength() - 2);
parameters.push_back(parameter);
parameter.Empty();
whiteSpacePos = 0;
@@ -1393,6 +1397,9 @@ void CUtil::SplitExecFunction(const CStdString &execString, CStdString &function
CLog::Log(LOGWARNING, "%s(%s) - end of string while searching for ) or \"", __FUNCTION__, execString.c_str());
if (whiteSpacePos)
parameter = parameter.Left(whiteSpacePos);
+ // trim off start and end quotes
+ if (parameter.GetLength() > 1 && parameter[0] == '\"' && parameter[parameter.GetLength() - 1] == '\"')
+ parameter = parameter.Mid(1,parameter.GetLength() - 2);
if (!parameter.IsEmpty() || parameters.size())
parameters.push_back(parameter);
}
diff --git a/xbmc/guilib/GUIInfoTypes.cpp b/xbmc/guilib/GUIInfoTypes.cpp
index 6642db0037..2a4f07f887 100644
--- a/xbmc/guilib/GUIInfoTypes.cpp
+++ b/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, "");
diff --git a/xbmc/guilib/GUIInfoTypes.h b/xbmc/guilib/GUIInfoTypes.h
index a2eae659c5..ec36c1159c 100644
--- a/xbmc/guilib/GUIInfoTypes.h
+++ b/xbmc/guilib/GUIInfoTypes.h
@@ -102,10 +102,13 @@ private:
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;