summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rtl/ustring.hxx20
-rw-r--r--sal/qa/rtl/oustring/rtl_OUString2.cxx19
2 files changed, 39 insertions, 0 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ee3cfe170555..3a7f8bd5654f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1420,6 +1420,26 @@ public:
}
/**
+ Check whether this string starts with a given ASCII string.
+
+ @param asciiStr a sequence of at least asciiStrLength ASCII characters
+ (bytes in the range 0x00--0x7F)
+ @param asciiStrLength the length of asciiStr; must be non-negative
+ @return true if this string starts with asciiStr; otherwise, false is
+ returned
+
+ @since LibreOffice 7.2
+ */
+ bool startsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
+ const
+ {
+ return asciiStrLength <= pData->length
+ && rtl_ustr_asciil_reverseEquals_WithLength(
+ pData->buffer, asciiStr,
+ asciiStrLength);
+ }
+
+ /**
Check whether this string starts with a given string, ignoring the case of
ASCII letters.
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 516378dc14a7..d2223511f92a 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -881,6 +881,24 @@ void indexOfAscii::test() {
sal_Int32(3), OUString("foofoobar").indexOf("foo", 1));
}
+class startsWithAsciiL: public CppUnit::TestFixture {
+public:
+ void test();
+
+ CPPUNIT_TEST_SUITE(startsWithAsciiL);
+ CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void startsWithAsciiL::test() {
+ CPPUNIT_ASSERT_EQUAL(true, OUString().startsWithAsciiL("", 0));
+ CPPUNIT_ASSERT_EQUAL(false, OUString().startsWithAsciiL("x", 1));
+ CPPUNIT_ASSERT_EQUAL(true, OUString("bar").startsWithAsciiL("bar", 3));
+ CPPUNIT_ASSERT_EQUAL(false, OUString("bar").startsWithAsciiL("foobar", 6));
+ CPPUNIT_ASSERT_EQUAL(true, OUString("foobar").startsWithAsciiL("foo", 3));
+ CPPUNIT_ASSERT_EQUAL(false, OUString("FOOBAR").startsWithAsciiL("foo", 3));
+}
+
class endsWith: public CppUnit::TestFixture {
public:
void test();
@@ -1033,6 +1051,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::getToken);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::convertToString);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::construction);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::indexOfAscii);
+CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::startsWithAsciiL);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::endsWith);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::isEmpty);
CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OUString::createFromCodePoints);