diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-11-16 22:19:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-11-17 23:04:10 +0000 |
commit | dca04e236193db7de908aad746fd4539e78eb428 (patch) | |
tree | 9808f843924944a740ca8037094d4d5c4553bbc8 /comphelper/source | |
parent | c4927a1b76b728b2208c29d09dbf54e70bb26e13 (diff) |
add a StringUtils-alike remove (can replace EraseAllChars)
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/string.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 6f59564814b9..8525e79bd4fc 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -138,6 +138,37 @@ rtl::OUString replace(const rtl::OUString &rIn, const rtl::OUString &rSearch, rReplace); } +namespace +{ + template <typename T, typename C, typename O> T tmpl_remove(const T &rIn, + const C cRemove) + { + if (rIn.isEmpty()) + return rIn; + + O aRet; + + for (sal_Int32 i = 0; i < rIn.getLength(); ++i) + { + C cChar = rIn[i]; + if (cChar != cRemove) + aRet.append(cChar); + } + + return aRet.makeStringAndClear(); + } +} + +rtl::OString remove(const rtl::OString &rIn, sal_Char c) +{ + return tmpl_remove<rtl::OString, sal_Char, rtl::OStringBuffer>(rIn, c); +} + +rtl::OUString remove(const rtl::OUString &rIn, sal_Unicode c) +{ + return tmpl_remove<rtl::OUString, sal_Unicode, rtl::OUStringBuffer>(rIn, c); +} + sal_uInt32 decimalStringToNumber( ::rtl::OUString const & str ) { |