parse_performance_data(pd) | Parses a performance data string and returns an array describing the values.
dirname(path) | Returns the directory portion of the specified path.
basename(path) | Returns the filename portion of the specified path.
+escape\_create\_process\_arg(text)| (Windows only) Escapes a string for use as an argument for CreateProcess().
exit(integer) | Terminates the application.
## <a id="object-accessor-functions"></a> Object Accessor Functions
if (args != "")
args += " ";
- args += Utility::EscapeShellArg(argument);
+ args += Utility::EscapeCreateProcessArg(argument);
#else /* _WIN32 */
args.push_back(argument);
#endif /* _WIN32 */
REGISTER_SCRIPTFUNCTION(basename, &Utility::BaseName);
REGISTER_SCRIPTFUNCTION(dirname, &Utility::DirName);
REGISTER_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim);
+REGISTER_SCRIPTFUNCTION(escape_create_process_arg, &Utility::EscapeCreateProcessArg);
String ScriptUtils::CastString(const Value& value)
{
void Trim(void);
+ inline void Append(int count, char ch)
+ {
+ m_Data.append(count, ch);
+ }
+
inline bool Contains(const String& str) const
{
return (m_Data.find(str) != std::string::npos);
return result;
}
+#ifdef _WIN32
+String Utility::EscapeCreateProcessArg(const String& arg)
+{
+ if (arg.FindFirstOf(" \t\n\v\"") == String::NPos)
+ return arg;
+
+ String result = "\"";
+
+ for (String::ConstIterator it = arg.Begin(); ; it++) {
+ int numBackslashes = 0;
+
+ while (it != arg.End() && *it == '\\') {
+ it++;
+ numBackslashes++;
+ }
+
+ if (it == arg.End()) {
+ result.Append(numBackslashes * 2, '\\');
+ break;
+ } else if (*it == '"') {
+ result.Append(numBackslashes * 2, '\\');
+ result.Append(1, *it);
+ } else {
+ result.Append(numBackslashes, '\\');
+ result.Append(1, *it);
+ }
+ }
+
+ result += "\"";
+
+ return result;
+}
+#endif /* _WIN32 */
+
#ifdef _WIN32
static void WindowsSetThreadName(const char *name)
{
static String EscapeShellCmd(const String& s);
static String EscapeShellArg(const String& s);
+ static String EscapeCreateProcessArg(const String& arg);
static String EscapeString(const String& s, const String& chars);
static String UnescapeString(const String& s);