diff options
author | Michael Stahl <mstahl@redhat.com> | 2013-02-18 19:46:27 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2013-02-18 20:16:07 +0100 |
commit | 24eae2b75c201292990122e69954072f36b6f218 (patch) | |
tree | 75dadb6f93794056a7e063f1a5f5c74d1ba7dff5 /comphelper | |
parent | a413f18e5be4e95ceaf7cb4335ca9f62ec9693a5 (diff) |
add comphelper::string::indexOfAny()
to replace String::SearchChar()
Change-Id: If5476e94be1255247918584cf1923d408ad75064
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 11 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index cfa9ddd474f6..6e28895f7d90 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -285,6 +285,17 @@ COMPHELPER_DLLPUBLIC inline rtl::OUStringBuffer& padToLength( return detail::padToLength(rBuffer, nLength, cFill); } +/** Find any of a list of code units in the string. + @param rIn OUString to search + @param pChars 0-terminated array of sal_Unicode code units to search for + @param nPos start position + + @return position of first occurrence of any of the elements of pChars + or -1 if none of the code units occur in the string + */ +COMPHELPER_DLLPUBLIC sal_Int32 indexOfAny(rtl::OUString const& rIn, + sal_Unicode const*const pChars, sal_Int32 const nPos = 0); + /** Convert a sequence of strings to a single comma separated string. Note that no escaping of commas or anything fancy is done. diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index d5e42468a88f..8af97dc75685 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -400,6 +400,22 @@ rtl::OString reverseString(const rtl::OString &rStr) return tmpl_reverseString<rtl::OString, rtl::OStringBuffer>(rStr); } +sal_Int32 indexOfAny(rtl::OUString const& rIn, + sal_Unicode const*const pChars, sal_Int32 const nPos) +{ + for (sal_Int32 i = nPos; i < rIn.getLength(); ++i) + { + sal_Unicode const c = rIn[i]; + for (sal_Unicode const* pChar = pChars; *pChar; ++pChar) + { + if (c == *pChar) + { + return i; + } + } + } + return -1; +} } } |