add a route to compare a O[U]String to one code unit
Seems very awkward to create an entire temporary O[U]String just to compare it to another when we want to know if that other contains just one char of a given value Change-Id: Iacd4e0d87dc5c5211fa06c61c55e1ed85b1e91f3
This commit is contained in:
@@ -91,6 +91,26 @@ COMPHELPER_DLLPUBLIC rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen);
|
|||||||
*/
|
*/
|
||||||
COMPHELPER_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen);
|
COMPHELPER_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen);
|
||||||
|
|
||||||
|
/** Compare an OString to a single char
|
||||||
|
|
||||||
|
@param rIn The input OString
|
||||||
|
@param c The character to compare againsg
|
||||||
|
|
||||||
|
@return true if rIn has one char and its equal to c
|
||||||
|
*/
|
||||||
|
inline bool equals(const rtl::OString& rIn, sal_Char c)
|
||||||
|
{ return rIn.getLength() == 1 && rIn[0] == c; }
|
||||||
|
|
||||||
|
/** Compare an OUString to a single char
|
||||||
|
|
||||||
|
@param rIn The input OUString
|
||||||
|
@param c The character to compare againsg
|
||||||
|
|
||||||
|
@return true if rIn has one char and its equal to c
|
||||||
|
*/
|
||||||
|
inline bool equals(const rtl::OUString& rIn, sal_Unicode c)
|
||||||
|
{ return rIn.getLength() == 1 && rIn[0] == c; }
|
||||||
|
|
||||||
/** Removes all occurrences of a character from within the source string
|
/** Removes all occurrences of a character from within the source string
|
||||||
|
|
||||||
@deprecated Use rtl::OString::replaceAll(rtl::OString(c), rtl::OString())
|
@deprecated Use rtl::OString::replaceAll(rtl::OString(c), rtl::OString())
|
||||||
|
@@ -54,6 +54,7 @@ public:
|
|||||||
void testDecimalStringToNumber();
|
void testDecimalStringToNumber();
|
||||||
void testIsdigitAsciiString();
|
void testIsdigitAsciiString();
|
||||||
void testReverseString();
|
void testReverseString();
|
||||||
|
void testEqualsString();
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(TestString);
|
CPPUNIT_TEST_SUITE(TestString);
|
||||||
CPPUNIT_TEST(testNatural);
|
CPPUNIT_TEST(testNatural);
|
||||||
@@ -66,6 +67,7 @@ public:
|
|||||||
CPPUNIT_TEST(testDecimalStringToNumber);
|
CPPUNIT_TEST(testDecimalStringToNumber);
|
||||||
CPPUNIT_TEST(testIsdigitAsciiString);
|
CPPUNIT_TEST(testIsdigitAsciiString);
|
||||||
CPPUNIT_TEST(testReverseString);
|
CPPUNIT_TEST(testReverseString);
|
||||||
|
CPPUNIT_TEST(testEqualsString);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -405,6 +407,17 @@ void TestString::testReverseString()
|
|||||||
CPPUNIT_ASSERT(aOut == "CBA");
|
CPPUNIT_ASSERT(aOut == "CBA");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestString::testEqualsString()
|
||||||
|
{
|
||||||
|
::rtl::OString aIn("A");
|
||||||
|
CPPUNIT_ASSERT(::comphelper::string::equals(aIn, 'A'));
|
||||||
|
CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'B'));
|
||||||
|
aIn = ::rtl::OString("AA");
|
||||||
|
CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
|
||||||
|
aIn = ::rtl::OString();
|
||||||
|
CPPUNIT_ASSERT(!::comphelper::string::equals(aIn, 'A'));
|
||||||
|
}
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
|
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user