diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-08-28 23:08:39 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-08-29 09:56:08 +0100 |
commit | 313332e76bd17c0a5a6bd67c0abc467877948a3a (patch) | |
tree | 217b63800be13ef2ebbae21c0f919467d782a287 /comphelper | |
parent | tweaks to analyze .a archives (diff) | |
download | core-313332e76bd17c0a5a6bd67c0abc467877948a3a.tar.gz core-313332e76bd17c0a5a6bd67c0abc467877948a3a.zip |
various centralized isFOOAsciiStrings
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 46 | ||||
-rw-r--r-- | comphelper/qa/string/test_string.cxx | 14 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 45 |
3 files changed, 86 insertions, 19 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 4daa01b00b6f..627c04c984bf 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -288,7 +288,7 @@ COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const rtl::OString &rString); */ COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const rtl::OUString &rString); -/** Determine if an OString contains solely ASCII alphanumeric digits +/** Determine if an OString contains solely ASCII alphanumeric chars/digits @param rString An OString @@ -298,7 +298,7 @@ COMPHELPER_DLLPUBLIC bool isdigitAsciiString(const rtl::OUString &rString); */ COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OString &rString); -/** Determine if an OUString contains solely ASCII alphanumeric digits +/** Determine if an OUString contains solely ASCII alphanumeric chars/digits @param rString An OUString @@ -306,7 +306,47 @@ COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OString &rString); the ASCII 'a'-'z', 'A'-'Z' and '0'-'9' ranges true otherwise, including for empty string */ -COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OString &rString); +COMPHELPER_DLLPUBLIC bool isalnumAsciiString(const rtl::OUString &rString); + +/** Determine if an OString contains solely ASCII lower-case chars + + @param rString An OString + + @return false if string contains any characters outside + the ASCII 'a'-'z' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool islowerAsciiString(const rtl::OString &rString); + +/** Determine if an OUString contains solely ASCII lower-case chars + + @param rString An OUString + + @return false if string contains any characters outside + the ASCII 'a'-'z' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool islowerAsciiString(const rtl::OUString &rString); + +/** Determine if an OString contains solely ASCII upper-case chars + + @param rString An OString + + @return false if string contains any characters outside + the ASCII 'A'-'Z' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isupperAsciiString(const rtl::OString &rString); + +/** Determine if an OUString contains solely ASCII upper-case chars + + @param rString An OUString + + @return false if string contains any characters outside + the ASCII 'A'-'Z' ranges + true otherwise, including for empty string + */ +COMPHELPER_DLLPUBLIC bool isupperAsciiString(const rtl::OUString &rString); COMPHELPER_DLLPUBLIC inline bool isdigitAscii(sal_Unicode c) { diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index d7187e04fd75..21d84c9142fe 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -48,6 +48,7 @@ public: void testDecimalStringToNumber(); void testIsdigitAsciiString(); void testIsalnumAsciiString(); + void testIsupperAsciiString(); CPPUNIT_TEST_SUITE(TestString); CPPUNIT_TEST(testSearchAndReplaceAsciiL); @@ -57,6 +58,7 @@ public: CPPUNIT_TEST(testDecimalStringToNumber); CPPUNIT_TEST(testIsdigitAsciiString); CPPUNIT_TEST(testIsalnumAsciiString); + CPPUNIT_TEST(testIsupperAsciiString); CPPUNIT_TEST_SUITE_END(); }; @@ -129,6 +131,18 @@ void TestString::testIsalnumAsciiString() CPPUNIT_ASSERT_EQUAL(comphelper::string::isalnumAsciiString(s4), false); } +void TestString::testIsupperAsciiString() +{ + rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("1234")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isupperAsciiString(s1), false); + + rtl::OString s2(RTL_CONSTASCII_STRINGPARAM("aAbB")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isupperAsciiString(s2), false); + + rtl::OString s3(RTL_CONSTASCII_STRINGPARAM("AABB")); + CPPUNIT_ASSERT_EQUAL(comphelper::string::isupperAsciiString(s3), true); +} + using namespace ::com::sun::star; class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 0138cc672ed8..873a1ffe34e9 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -354,21 +354,14 @@ NaturalStringSorter::NaturalStringSorter( namespace { - template <typename T> bool tmpl_isalnumAsciiString(const T &rString) + //do OPER on each element of the string, return false + //if any OPER is false, true otherwise + template <bool (*OPER)(sal_Unicode), typename T> + bool tmpl_is_OPER_AsciiString(const T &rString) { for (sal_Int32 i = 0; i < rString.getLength(); ++i) { - if (!isalnumAscii(rString[i])) - return false; - } - return true; - } - - template <typename T> bool tmpl_isdigitAsciiString(const T &rString) - { - for (sal_Int32 i = 0; i < rString.getLength(); ++i) - { - if (!isdigitAscii(rString[i])) + if (!OPER(rString[i])) return false; } return true; @@ -377,22 +370,42 @@ namespace bool isalnumAsciiString(const rtl::OString &rString) { - return tmpl_isalnumAsciiString(rString); + return tmpl_is_OPER_AsciiString<isalnumAscii>(rString); } bool isalnumAsciiString(const rtl::OUString &rString) { - return tmpl_isalnumAsciiString(rString); + return tmpl_is_OPER_AsciiString<isalnumAscii>(rString); } bool isdigitAsciiString(const rtl::OString &rString) { - return tmpl_isdigitAsciiString(rString); + return tmpl_is_OPER_AsciiString<isdigitAscii>(rString); } bool isdigitAsciiString(const rtl::OUString &rString) { - return tmpl_isdigitAsciiString(rString); + return tmpl_is_OPER_AsciiString<isdigitAscii>(rString); +} + +bool islowerAsciiString(const rtl::OString &rString) +{ + return tmpl_is_OPER_AsciiString<islowerAscii>(rString); +} + +bool islowerAsciiString(const rtl::OUString &rString) +{ + return tmpl_is_OPER_AsciiString<islowerAscii>(rString); +} + +bool isupperAsciiString(const rtl::OString &rString) +{ + return tmpl_is_OPER_AsciiString<isupperAscii>(rString); +} + +bool isupperAsciiString(const rtl::OUString &rString) +{ + return tmpl_is_OPER_AsciiString<isupperAscii>(rString); } } } |