Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

StringUtils: add Paramify() method to escape strings before passing t…

…hem to builtins methods
  • Loading branch information...
commit 06d0b88c2a76e4a3b205d4b1d34a1f913a513f07 1 parent 3ec269e
@Montellese Montellese authored
Showing with 22 additions and 0 deletions.
  1. +12 −0 xbmc/utils/StringUtils.cpp
  2. +10 −0 xbmc/utils/StringUtils.h
View
12 xbmc/utils/StringUtils.cpp
@@ -679,3 +679,15 @@ size_t StringUtils::utf8_strlen(const char *s)
}
return length;
}
+
+std::string StringUtils::Paramify(const std::string &param)
+{
+ std::string result = param;
+ // escape backspaces
+ StringUtils::Replace(result, "\\", "\\\\");
+ // escape double quotes
+ StringUtils::Replace(result, "\"", "\\\"");
+
+ // add double quotes around the whole string
+ return "\"" + result + "\"";
+}
View
10 xbmc/utils/StringUtils.h
@@ -114,6 +114,16 @@ class StringUtils
static bool ValidateUUID(const CStdString &uuid); // NB only validates syntax
static double CompareFuzzy(const CStdString &left, const CStdString &right);
static int FindBestMatch(const CStdString &str, const CStdStringArray &strings, double &matchscore);
+
+ /*! \brief Escapes the given string to be able to be used as a parameter.
+
+ Escapes backslashes and double-quotes with an additional backslash and
+ adds double-quotes around the whole string.
+
+ \param param String to escape/paramify
+ \return Escaped/Paramified string
+ */
+ static std::string Paramify(const std::string &param);
private:
static CStdString m_lastUUID;
};
Please sign in to comment.
Something went wrong with that request. Please try again.