diff options
author | Sebastien Barre <sebastien.barre@kitware.com> | 2005-06-13 22:03:53 (GMT) |
---|---|---|
committer | Sebastien Barre <sebastien.barre@kitware.com> | 2005-06-13 22:03:53 (GMT) |
commit | 7f2c1e434c0e629d0d851e047df42ce9ad71d860 (patch) | |
tree | fe1d60c677156f29632e17a943ddfda0568aeb6b /Source/kwsys/SystemTools.cxx | |
parent | 6037d1ae66f82bc650fba5ec2a53370199fac380 (diff) | |
download | CMake-7f2c1e434c0e629d0d851e047df42ce9ad71d860.zip CMake-7f2c1e434c0e629d0d851e047df42ce9ad71d860.tar.gz CMake-7f2c1e434c0e629d0d851e047df42ce9ad71d860.tar.bz2 |
ENH: add method to escape some chars in a string
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
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) { |