Skip to content

Commit

Permalink
StringUtils: add Paramify() method to escape strings before passing t…
Browse files Browse the repository at this point in the history
…hem to builtins methods
  • Loading branch information
Montellese committed Feb 27, 2013
1 parent 3ec269e commit 06d0b88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions xbmc/utils/StringUtils.cpp
Expand Up @@ -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 + "\"";
}
10 changes: 10 additions & 0 deletions xbmc/utils/StringUtils.h
Expand Up @@ -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;
};

0 comments on commit 06d0b88

Please sign in to comment.