From 7f2c1e434c0e629d0d851e047df42ce9ad71d860 Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Mon, 13 Jun 2005 18:03:53 -0400 Subject: ENH: add method to escape some chars in a string --- Source/kwsys/SystemTools.cxx | 35 +++++++++++++++++++++++++++++++++++ Source/kwsys/SystemTools.hxx.in | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 938a959..f5c4507 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/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/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index ba57618..8f22165 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/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 * ----------------------------------------------------------------- -- cgit v0.12