summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-11-22 12:29:25 +0000
committerCaolán McNamara <caolanm@redhat.com>2011-11-22 12:50:14 +0000
commit4a06a42de49215167221177d47cd2eb0e2d59232 (patch)
tree51049cdbac6d6ad5bebba8e3936424ac40d26d3b /comphelper
parent5317e0501fe356fb38c7de408cdde1d3f3e1242e (diff)
want to match here, not check for equality
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/string.hxx27
-rw-r--r--comphelper/qa/string/test_string.cxx19
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 >