ENH: add string replaceAny() method
- takes a search string and a replacement character.
The replacement character can also be a nul char ('\0'), which
simply removes the characters.
Possible uses:
* Replace reserved characters
str.replaceAny("<>:", '_');
* Remove shell meta-characters or reserved filesystem characters
str.replaceAny("*?<>{}[]:", '\0');
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -234,7 +234,7 @@ public:
|
||||
|
||||
//- Replace all occurrences of sub-string s1 with s2,
|
||||
//- beginning at pos in the string.
|
||||
// This is a no-op if s1 is empty.
|
||||
// A no-op if s1 is empty.
|
||||
string& replaceAll
|
||||
(
|
||||
const std::string& s1,
|
||||
@ -242,6 +242,16 @@ public:
|
||||
size_type pos = 0
|
||||
);
|
||||
|
||||
//- Replace any occurrence of s1 characters with c2,
|
||||
//- beginning at pos in the string.
|
||||
// A no-op if s1 is empty.
|
||||
string& replaceAny
|
||||
(
|
||||
const std::string& s1,
|
||||
const char c2,
|
||||
size_type pos = 0
|
||||
);
|
||||
|
||||
//- Inplace expand initial tags, tildes, and all occurrences of
|
||||
//- environment variables as per stringOps::expand
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user