diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-01-02 10:55:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-01-05 09:18:19 +0000 |
commit | bacfd2dc4cea1a5d87658ed8592116acd931e000 (patch) | |
tree | d22172a33fdd13a440b6882a28c23ea2d639bbad /comphelper/source | |
parent | 6281eb0e0792da0194c07da18296e94dd944b8e5 (diff) |
add a comphelper::string::getTokenCount
suitable for conversion from [Byte]String::GetTokenCount
converted low-hanging variants to rtl::O[UString]::getToken loops
added unit test
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/string.cxx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index bc3f89048aaf..13a1236ea55e 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -240,6 +240,35 @@ rtl::OUString strip(const rtl::OUString &rIn, sal_Unicode c) return stripEnd(stripStart(rIn, c), c); } +namespace +{ + template <typename T, typename C> sal_Int32 tmpl_getTokenCount(const T &rIn, + C cTok) + { + // Empty String: TokenCount by Definition is 0 + if (rIn.isEmpty()) + return 0; + + sal_Int32 nTokCount = 1; + for (sal_Int32 i = 0; i < rIn.getLength(); ++i) + { + if (rIn[i] == cTok) + ++nTokCount; + } + return nTokCount; + } +} + +sal_Int32 getTokenCount(const rtl::OString &rIn, sal_Char cTok) +{ + return tmpl_getTokenCount<rtl::OString, sal_Char>(rIn, cTok); +} + +sal_Int32 getTokenCount(const rtl::OUString &rIn, sal_Unicode cTok) +{ + return tmpl_getTokenCount<rtl::OUString, sal_Unicode>(rIn, cTok); +} + sal_uInt32 decimalStringToNumber( ::rtl::OUString const & str ) { |