diff options
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 27 | ||||
-rw-r--r-- | comphelper/qa/string/test_string.cxx | 19 |
2 files changed, 46 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 31414e5519ff..00a1664016cf 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -272,6 +272,33 @@ COMPHELPER_DLLPUBLIC inline sal_Bool matchL(const rtl::OString& rStr, const char } /** + Match against a substring appearing in this string, ignoring the case of + ASCII letters. + + The result is true if and only if the second string appears as a substring + of this string, at the given position. + Character values between 65 and 90 (ASCII A-Z) are interpreted as + values between 97 and 122 (ASCII a-z). + This function can't be used for language specific comparison. + + @param rStr The string that pMatch will be compared to. + @param pMatch The substring rStr is to be compared against + @param nMatchLen The length of pMatch + @param fromIndex the index to start the comparion from. + The index must be greater or equal than 0 + and less or equal as the string length. + @return sal_True if str match with the characters in the string + at the given position; + sal_False, otherwise. +*/ +COMPHELPER_DLLPUBLIC inline sal_Bool matchIgnoreAsciiCaseL(const rtl::OString& rStr, const char *pMatch, sal_Int32 nMatchLen, sal_Int32 fromIndex = 0) SAL_THROW(()) +{ + return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( rStr.pData->buffer+fromIndex, rStr.pData->length-fromIndex, + pMatch, nMatchLen, + nMatchLen ) == 0; +} + +/** Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index 110638164506..2ce6f2cff1bb 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -55,6 +55,7 @@ public: void testIsalnumAsciiString(); void testIsupperAsciiString(); void testIndexOfL(); + void testMatchIgnoreAsciiCaseL(); CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(testSearchAndReplaceAsciiL); @@ -67,6 +68,7 @@ public: CPPUNIT_TEST(testIsalnumAsciiString); CPPUNIT_TEST(testIsupperAsciiString); CPPUNIT_TEST(testIndexOfL); + CPPUNIT_TEST(testMatchIgnoreAsciiCaseL); CPPUNIT_TEST_SUITE_END(); }; @@ -168,6 +170,23 @@ void TestString::testIndexOfL() RTL_CONSTASCII_STRINGPARAM("two"), 5), static_cast<sal_Int32>(-1)); } +void TestString::testMatchIgnoreAsciiCaseL() +{ + rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("one two three")); + + CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, + RTL_CONSTASCII_STRINGPARAM("one")), sal_True); + + CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, + RTL_CONSTASCII_STRINGPARAM("ONE")), sal_True); + + CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, + RTL_CONSTASCII_STRINGPARAM("two")), sal_False); + + CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, + RTL_CONSTASCII_STRINGPARAM("two"), 4), sal_True); +} + using namespace ::com::sun::star; class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > |