diff --git a/SystemTools.cxx b/SystemTools.cxx
index 11bbf2da1b362103deebee39ffd7797adafb6ad9..2de0ba21dc58fe8643dcecb82d8030538c64c88c 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -1205,6 +1205,41 @@ int SystemTools::EstimateFormatLength(const char *format, va_list ap)
   return length;
 }
 
+kwsys_stl::string SystemTools::EscapeChars(
+  const char *str, 
+  const char *chars_to_escape, 
+  char escape_char)
+{
+  kwsys_stl::string n;
+  if (str)
+    {
+    if (!chars_to_escape | !*chars_to_escape)
+      {
+      n.append(str);
+      }
+    else
+      {
+      n.reserve(strlen(str));
+      while (*str)
+        {
+        const char *ptr = chars_to_escape;
+        while (*ptr)
+          {
+          if (*str == *ptr)
+            {
+            n += escape_char;
+            break;
+            }
+          ++ptr;
+          }
+        n += *str;
+        ++str;
+        }
+      }
+    }
+  return n;
+}
+
 // convert windows slashes to unix slashes 
 void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
 {
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index e6af70222fb6486fbec50d5a9943b22f109a5aac..d7d9322afb212ddea0358c2dcf937597ec5efed7 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -220,6 +220,12 @@ public:
    */
   static int EstimateFormatLength(const char *format, va_list ap);
 
+  /**
+   * Escape specific characters in 'str'.
+   */
+  static kwsys_stl::string EscapeChars(
+    const char *str, const char *chars_to_escape, char escape_char = '\\');
+  
   /** -----------------------------------------------------------------
    *               Filename Manipulation Routines
    *  -----------------------------------------------------------------